Wolfgang Bumiller
055793c481
api-macro: support raw method parameters
...
Support raw parameter name identifiers (eg. `r#type`)
#[api(
input: {
properties: {
type: {
type: String,
description: "Foo",
},
},
},
)]
fn foo(r#type: String) { code... }
The "r#type" parameter in the fn decl will match the "type"
parameter name in the input property list.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-10 13:53:06 +01:00
Thomas Lamprecht
0c816fe383
bump proxmox-api-macro version to 0.2.3
...
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-05 12:13:05 +01:00
Wolfgang Bumiller
05749ab419
test fixups
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 14:51:22 +01:00
Thomas Lamprecht
7d34e6f3a4
api macro: reuse generated default const for "unwrap_or"
...
Instead of setting a default value to a const and inside an
.unwrap_or_else closure, lets set it only to the const and reuse that
later in .unwrap_or
To achieve that we move the "unrwap_or" code for param plumbing code generation
a bit later so that we have easy access to the generated const name.
As all this code is related to optional/default-value stuff it does read still
relatively OK with that change, IMO.
This has the advantage of not getting a warning like:
> warning: constant is never used: `API_METHOD_EXAMPLE_FOO_PARAM_DEFAULT_FORCE`
> --> src/api2/node/foo.rs
> |
> XY | force: {
> | ^^^^^
> = note: `#[warn(dead_code)]` on by default
When one has a API endpoint like:
> #[api(
> input: {
> properties: {
> force: {
> type: bool,
> optional: true,
> default: false,
> },
> },
> },
> ...
> )]
> /// Example
> fn example_foo(force: bool) -> Result<(), Error> {
> if force {
> // do something
> }
> Ok(())
> }
It effectively changes the output for optional parameters with a default set
and no Option<T> from
> let p = p.unwrap_or_else(|| #default_value);
to
> let p = p.unwrap_or(#const_name_for_default);
where the "#const_name_for_default" is a pub const with value
"#default_value"
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-27 09:17:12 +01:00
Wolfgang Bumiller
e5456f873d
clippy fixups
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-14 11:13:20 +02:00
Wolfgang Bumiller
ef5c719150
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-02 09:59:52 +02:00
Dietmar Maurer
2702a2a7b5
bump versions to proxmox 0.4.0 and proxmox-api-macro 0.2.2
2020-09-19 06:32:06 +02:00
Dominik Csapak
3458d3fa69
api-macro: replace ident hashmap with simple find
...
after benchmarking (again), i found that doing a simple find instead
of saving the inidices for the ident strings in a hashmap has
no real performance impact (the max list size for the properties
are max ~25 at the moment, so this should not be impacting compile
times much) but it is much simpler
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-19 06:28:36 +02:00
Dietmar Maurer
2fb7f4a312
bump proxmox-api-macro version to 0.2.1-1
2020-09-17 08:26:25 +02:00
Dominik Csapak
958e72aa69
api-macro: relax Fieldname rules
...
by replacing more characters ('.','+') by '_' and prefix them when
it starts with a number
we sometimes need to parse such fields, e.g in serde attributes like
#[serde(rename = "802.3ad")]
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-17 08:21:17 +02:00
Dominik Csapak
29763449f0
api-macro: fix broken binary ident search
...
the 'properties_' list is sorted by the the literal string of a
fieldname, but we binary-search for the 'ident_str' (which may be
different, since we map '-' to '_' for example)
by creating a hashmap to map from ident to index, we can do a simple
lookup in that case that will work
benchmarks showed no measurable performance difference
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-17 08:20:44 +02:00
Wolfgang Bumiller
f165dee496
switch to using mod.rs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-28 15:11:38 +02:00
Wolfgang Bumiller
a4abaa8b17
api-macro: formatting fixups
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-16 14:13:14 +02:00
Wolfgang Bumiller
def1d54aa6
various clippy lint fixes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-16 13:44:42 +02:00
Wolfgang Bumiller
2904b622be
bump api macro to 0.2.0-1
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-10 11:04:20 +02:00
Wolfgang Bumiller
e3800fb853
api-macro: test using return schemas within return objects
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-10 11:04:00 +02:00
Wolfgang Bumiller
0ce4c9eeb8
api-macro: reference consistency
...
API_RETURN_* and API_PARAMETER_* schemas are no references
anymore to allow using them as external schemas via the
`"schema"` key inside object schemas inside the `#[api]`
macro.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-07-10 10:56:29 +02:00
Dietmar Maurer
bd4b4bdc15
proxmox/src/api/rpc_environment.rs: use Value to store metadata
...
And impl. Index and IndexMut to make it easy to access/set the metadata.
2020-05-18 09:38:00 +02:00
Wolfgang Bumiller
fa25b17cd0
api-macro: bump version to 0.1.9-1
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-05-18 09:17:35 +02:00
Wolfgang Bumiller
7d6ecaa306
api-macro: remove more unnecessary parentheses
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-05-15 09:15:10 +02:00
Wolfgang Bumiller
b671b2fce2
api-macro: remove some unnecessary parentheses in output
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-05-14 15:39:40 +02:00
Wolfgang Bumiller
c329cedb02
bump api macro to 0.1.8
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-29 10:48:19 +02:00
Wolfgang Bumiller
83d9d3e165
implement descriptions for enum variants
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-29 10:48:19 +02:00
Wolfgang Bumiller
95403224c5
bump proxmox-api-macro to 0.1.7-1
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-17 18:37:55 +02:00
Wolfgang Bumiller
5dd21ee89b
switch from failure to anyhow
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-17 18:34:21 +02:00
Dietmar Maurer
5affb691b5
proxmox-api-macro/src/api/method.rs: fix error message
2020-04-17 15:28:49 +02:00
Wolfgang Bumiller
5ae320f577
api-macro: add test for access w/o a description
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-16 09:26:24 +02:00
Wolfgang Bumiller
62f3c7d2d9
api-macro: avoid duplicate output code
...
While this is a tiny piece of code, having only one output
code consisting of prepared parts is nicer to keep up to
date.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-16 09:26:24 +02:00
Wolfgang Bumiller
6d831e36dd
api-macro: cleanup & test fixup
...
remove unnecessary types, they were already in the struct
update test to use Option for access description
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-16 09:26:24 +02:00
Dietmar Maurer
b07d592597
bump rust-proxmox-api-macro version to 0.1.6-1
2020-04-16 08:44:17 +02:00
Dietmar Maurer
076501e17e
proxmox-api-macro/tests/api1.rs: fix test case
2020-04-16 08:42:05 +02:00
Dietmar Maurer
e78e31ab4c
make access description optional
2020-04-16 07:20:29 +02:00
Dietmar Maurer
25dbb0ebab
api macro: support reload_timezone
2020-04-15 17:26:43 +02:00
Wolfgang Bumiller
da01ff1a72
style cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-15 09:21:04 +02:00
Wolfgang Bumiller
973e7ccef0
rename some permission/access items
...
router.permissions(...) -> router.access(...)
to be more consistent with the other builder methods and
struct member names
ApiAccessPermissions -> ApiAccess
shorter, not necessarily with defined permissions, and
gets rid of a singular/plural confusion
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-15 09:19:25 +02:00
Wolfgang Bumiller
510d410b7a
api-macro: support 'access' specification for methods
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-14 14:28:12 +02:00
Wolfgang Bumiller
19ad65ac84
api-macro: error on unexpected keys
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-14 13:48:09 +02:00
Wolfgang Bumiller
2c83d55cb0
api-macro: util: add join and join_debug helper
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-14 13:27:36 +02:00
Wolfgang Bumiller
0b2c9b95b4
api-macro: minor cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-14 11:45:50 +02:00
Wolfgang Bumiller
ab8a6120ca
api-macro: started with some more documentation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-23 15:55:18 +01:00
Wolfgang Bumiller
176e208caf
api-macro: add consts for defaults
...
Not sure how we want to actually handle default values yet.
For now we need to figure out what "feels best".
This adds default values as publicly available consts so
they can be accessed from anywhere as
`API_METHOD_<METHOD_NAME>_PARAM_DEFAULT_<PARAM_NAME>`.
This is quite a handful to type, but I'm not sure how to
make this better.
Within the function body we also have the
`api_get_default!(param_name)` macro which is more
convenient, but not available outside the `#[api]` tagged
function.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-23 09:15:54 +01:00
Fabian Grünbichler
6a21867d87
api-macro: explicitly enable syn's visit-mut feature
...
otherwise the build fails because the module is not visible
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-03-23 08:04:26 +01:00
Wolfgang Bumiller
f5d15872f4
api-macro: add api_get_default!() macro
...
When writing an #[api] function, one can now access default
values by parameter name (see test_default_option in
tests/options.rs):
#[api(...)]
pub fn func(value: Option<isize>) {
println!(
"value: {}",
value.unwrap_or(api_get_default!("value")),
);
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-19 15:49:34 +01:00
Wolfgang Bumiller
8beec0d6e6
api-macro: tests for optional non-Option parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-19 12:08:38 +01:00
Wolfgang Bumiller
83b6d082db
api-macro: allow optional types without Option<T>
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-19 12:08:10 +01:00
Wolfgang Bumiller
2065bcb136
bump api-macro to 0.1.5
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-19 09:58:02 +01:00
Wolfgang Bumiller
c5c82abc7d
api-macro: cleanup: warnings
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 13:50:39 +01:00
Wolfgang Bumiller
8e1ace59b1
api-macro: cleanup: don't use try_fold for a Vec
...
`collect()` uses `FromIterator` which is also implemented
for `Result<Vec, Err>` from `Result<Item, Err>` doing the
same thing.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 13:37:59 +01:00
Wolfgang Bumiller
2edd8da965
api-macro: add integer limit test cases
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 12:02:32 +01:00
Wolfgang Bumiller
723500dbfc
api-macro: include default minimum/maximum for integer types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 11:59:08 +01:00
Wolfgang Bumiller
f4e88aab6c
api-macro: replace unreachable with a panic
...
(we're not running into this, but ran into an unreachable in
`syn` during development, and I needed to make sure it's not
one of ours...)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 11:56:48 +01:00
Wolfgang Bumiller
dc4ec65723
api-macro: correctly infer newtype types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 11:10:22 +01:00
Wolfgang Bumiller
67949bf8f0
api-macro: factor handle_struct differently
...
Don't assume an empty object schema for all cases as
newtypes shouldn't use an object schema at all actually!
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-03-06 10:53:59 +01:00
Wolfgang Bumiller
d7be7df86c
bump proxmox-api-macro to 0.1.4
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-02-27 13:10:40 +01:00
Wolfgang Bumiller
dd8ccd80d9
api-macro: make API_{RETURN,PARAMETER}_SCHEMA_... public
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-02-27 13:08:59 +01:00
Wolfgang Bumiller
39566afb15
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-30 12:37:26 +01:00
Wolfgang Bumiller
db741bfb81
bump api-macro to 0.1.3
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-30 12:35:28 +01:00
Wolfgang Bumiller
eadffcfc16
expose parameter schema as API_PARAMETER_SCHEMA_<methodname>
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-30 12:32:22 +01:00
Wolfgang Bumiller
2c7b786cef
expose return schema as API_RETURN_SCHEMA_<methodname>
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-30 12:28:19 +01:00
Wolfgang Bumiller
a5373a9679
bump api-macro
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-23 13:16:50 +01:00
Wolfgang Bumiller
edebbf920a
fix property sorting
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-23 13:15:59 +01:00
Wolfgang Bumiller
436bf05e0b
merge api, sys and tools into proxmox directly
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-21 12:15:42 +01:00
Wolfgang Bumiller
f22b693800
macro: silence some warnings in tests
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-15 14:10:58 +01:00
Fabian Grünbichler
a94de245f0
build: switch to debcargo
...
to autogenerate crate (build)-dependencies, and correct Provides
statements.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-01-15 12:02:47 +01:00
Wolfgang Bumiller
66d9d43cd4
bump api-macro to 0.1.1
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 11:29:15 +01:00
Wolfgang Bumiller
1992abf96e
api-macro: even more documentation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 11:28:00 +01:00
Wolfgang Bumiller
0f630a4cb8
api-macro: more documentation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 11:23:48 +01:00
Wolfgang Bumiller
5b652dbad8
api-macro: schema tests for async fns
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 11:01:55 +01:00
Wolfgang Bumiller
943bc4de52
api-macro: more tests
...
Note that this one tests the fact that we do not do output
schema validation!
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 10:58:27 +01:00
Wolfgang Bumiller
58158b495e
api-macro: more invocation tests for api methods
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 10:56:45 +01:00
Wolfgang Bumiller
679ad01c03
api-macro: add expanded data to tests for verification
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 10:51:00 +01:00
Wolfgang Bumiller
08e1cf3c2f
api-macro: support empty api macro on structs
...
The description comes from the doc comment, the field types
and description from field doc comments and types.
Previously we needed to add at least the hint that the
schema is an object schema. Now we support an empty #[api]
attribute as well.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 10:09:42 +01:00
Wolfgang Bumiller
7c6ebbdbf3
api-macro: support renamed struct fields
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-08 10:06:48 +01:00
Wolfgang Bumiller
2e63bf8422
api-macro: support rename_all in enums
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 15:29:56 +01:00
Wolfgang Bumiller
dd5cd3f311
api-macro: start using serde attribute helpers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 15:23:52 +01:00
Wolfgang Bumiller
799c993d63
api-macro: prepare to support serde::rename_all
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 15:17:20 +01:00
Wolfgang Bumiller
3626f57d2c
api-macro: more option type handling
...
infer_type now also returns whether it was encapsualted in
an Option<>. So `type: String, optional: true` is now
inferred propertly from `Option<String>`.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:37:34 +01:00
Wolfgang Bumiller
45af06f090
api-macro: derive optional values correctly
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:19:13 +01:00
Wolfgang Bumiller
46fe5832fb
api-macro: reorganize field iteration
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:18:21 +01:00
Wolfgang Bumiller
9207e8aa9a
api-macro: error on extraneous fields
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:16:12 +01:00
Wolfgang Bumiller
860a4fd0ad
api-macro: add basic struct handling
...
- handle doc comments for descriptions
- infer fields from structs when possible
- perform some basic error checking
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:09:20 +01:00
Wolfgang Bumiller
e960a68b60
api-macro: factor out type inference for reuse with structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 13:09:08 +01:00
Wolfgang Bumiller
b9769de6b6
api-macro: split struct handling into newtype, regular, unit, ...
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 12:11:04 +01:00
Wolfgang Bumiller
4c77a7fece
api-macro: derive descriptions for structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-07 12:00:17 +01:00
Wolfgang Bumiller
f214bcb652
api-macro: drop unused dev-dependencies
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-02 14:25:09 +01:00
Wolfgang Bumiller
c52794b8ad
api-macro: bump bytes to 0.5
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-02 12:45:07 +01:00
Fabian Grünbichler
8840877c80
proxmox-api-macro: initial packaging
...
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2019-12-20 09:39:45 +01:00
Wolfgang Bumiller
5e1468bff8
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-18 13:20:58 +01:00
Thomas Lamprecht
13007df318
api/macro: add NumberSchema
...
Adapted from the integer schema, uses f64 type.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-18 11:30:55 +01:00
Wolfgang Bumiller
1d65ff88dd
drop derive-builder dependency
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-18 10:00:30 +01:00
Wolfgang Bumiller
778983c1b0
remove old router macro documentation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-18 09:40:40 +01:00
Wolfgang Bumiller
79c9d6ab08
api-macro: remove now-unnecessary PropertySchema type
...
Schemas can now generally refer to an externally defined
schema.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-16 13:06:58 +01:00
Wolfgang Bumiller
3e5927a1b4
api-macro: generalized '{ schema: PATH }' schemas
...
allow 'schema: PATH' outside object property context
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-16 12:11:52 +01:00
Wolfgang Bumiller
808035f524
api-macro: support 'async fn' with new async api method
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-16 11:13:26 +01:00
Wolfgang Bumiller
6d152f8930
updates for hyper 0.13 release
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-12 13:13:53 +01:00
Wolfgang Bumiller
65a284784b
clippy fixups
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-05 11:42:34 +01:00
Wolfgang Bumiller
7c48247c58
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-05 11:32:48 +01:00
Wolfgang Bumiller
b81beb4dfb
api-macro: allow methods without return types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 14:27:57 +01:00
Wolfgang Bumiller
c282c8ce23
api-macro: don't return Null without return schema
...
serde_json turns () into Null anyway, so there's no need to
check this!
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 14:25:12 +01:00
Wolfgang Bumiller
f9d775924d
api-macro: get enum description from doc comments
...
instead of:
#[api(description: "Some description.")]
pub enum { ... }
support:
#[api]
/// Some description.
pub enum { ... }
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 11:52:03 +01:00
Wolfgang Bumiller
7609cf2bd4
api-macro: move doc-comment reading to util
...
The function attribute reader doesn't read any other
attributes anymore, so make it reusable!
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 11:47:27 +01:00
Wolfgang Bumiller
197b1bccb3
api-macro: rename SimpleIdent to FieldName
...
Initially it was a wrapper around Ident to avoid some
copies, but now it's what we use to allow hyphenated names
for fields in objects (as `syn::Ident` doesn't allow that at
all), so give it a more fitting name.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 09:06:31 +01:00
Wolfgang Bumiller
4de409c526
api-macro: support hyphenated parameter names
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 13:34:37 +01:00
Wolfgang Bumiller
f3f15c2893
api-macro: drop ToTokens for SimpleIdent
...
The user must be explicit about whether the ident or string
is required.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:58:40 +01:00
Wolfgang Bumiller
b7ecf3a597
api-macro: drop Deref of SimpleIdent
...
The user must always be explicit about whether the Ident or
the String is required, since they may differ.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:57:07 +01:00
Wolfgang Bumiller
7533252072
api-macro: fixup idents in SimpleIdent
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:56:27 +01:00
Wolfgang Bumiller
02acd7269f
api-macro: remove Into<Ident> for SimpleIdent
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:55:14 +01:00
Wolfgang Bumiller
d3ec63f26d
api-macro: allow referencing external schemas in properties
...
Reference a predefined BACKUP_ARCHIVE_NAME StringSchema like
this:
#[api(
input: {
properties: {
archive: {
optional: true,
schema: BACKUP_ARCHIVE_NAME,
},
}
}
)]
fn get_archive(archive: String) -> Result<(), Error> {
...
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:11:46 +01:00
Wolfgang Bumiller
d78659a2c0
api-macro: allow inferring some types automatically
...
non-optional boolean, string and integer types can be
inferred from the function
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 11:46:15 +01:00
Wolfgang Bumiller
7fd69f8b12
api-macro: test optional value invocation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 11:12:36 +01:00
Wolfgang Bumiller
263b943287
api-macro: allow skipping input
schema
...
when there are no parameters
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 11:00:04 +01:00
Wolfgang Bumiller
bead1e6b13
api-macro: add test with no parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 10:55:28 +01:00
Wolfgang Bumiller
21fab51bda
api-macro: allow 'bool' and rust int types
...
in place of Boolean and Integer
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 10:55:01 +01:00
Wolfgang Bumiller
a997502ab1
api-macro: make return schema optional
...
and support returning () from methods
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 10:43:10 +01:00
Wolfgang Bumiller
6afad53466
api-macro: some more test code
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 13:49:14 +01:00
Wolfgang Bumiller
22581b382c
api-macro: fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 13:47:42 +01:00
Wolfgang Bumiller
5690e5e6a2
api-macro: cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 13:43:25 +01:00
Wolfgang Bumiller
7d6fac0fa5
api-macro: parse serde(rename) on enums
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 13:42:46 +01:00
Wolfgang Bumiller
30a1c0b9ae
api-macro: experimental enum support
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 12:21:46 +01:00
Wolfgang Bumiller
6818cf76c9
api-macro: support defining schemas for structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 11:15:37 +01:00
Wolfgang Bumiller
4f042f8133
api-macro: support external types
...
See the test example:
assuming a `pub struct Foo` which implements `Serialize` and
`Deserialize`, we also expect it to provide a
`pub const Foo::API_SCHEMA: &Schema` like so:
#[derive(Deserialize, Serialize)]
pub struct StrongString(String);
impl StrongString {
pub const API_SCHEMA: &'static Schema =
&StringSchema::new("Some generic string")
.format(&ApiStringFormat::Enum(&["a", "b"]))
.schema();
}
Then we can use:
#[api(
input: {
properties: {
arg: { type: StrongString },
}
},
...
)]
fn my_api_func(arg: StrongString) -> Result<...> {
...
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 10:42:35 +01:00
Wolfgang Bumiller
2fc2df9a78
api-macro: tests: remove #![allow(dead_code)]
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:29:45 +01:00
Wolfgang Bumiller
74ed56957d
api-macro: match the item type early
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:16:34 +01:00
Wolfgang Bumiller
1ae127b63a
api-macro: move method handling to api/method.rs
...
We may want to add the ability to declare a Schema for
structs, so factorize function handling into its own file.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:13:33 +01:00
Wolfgang Bumiller
993eb7d168
api-macro: update tests, cleanup some macro generated paths
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:46:20 +01:00
Wolfgang Bumiller
0bf354e437
api-macro: convert function output to a json value
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:44:16 +01:00
Wolfgang Bumiller
6e98ae0dd3
api-macro: minor improvements
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:41:51 +01:00
Wolfgang Bumiller
03012deb3f
api-macro: reduce code output a little
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:04:14 +01:00
Wolfgang Bumiller
881df81976
api-macro: start actually extracting parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:00:41 +01:00
Wolfgang Bumiller
d02a8f4e42
api-macro: begin and explain the parameter mapping strategy
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 12:29:50 +01:00
Wolfgang Bumiller
79f77253be
api-macro: start looking at function parameter types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:31:40 +01:00
Wolfgang Bumiller
09d1363fa0
api-macro: start checking some function signature parts
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:04:36 +01:00
Wolfgang Bumiller
ebda5a3c5c
api-macro: parse properties as attributes to #[api]
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:01:40 +01:00
Wolfgang Bumiller
676ef1796d
api-amcro: expose JSONObject::parse_inner as Parser
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:01:12 +01:00
Wolfgang Bumiller
d4721d77b7
api-macro: JSONValue to bool shortcut
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:59:37 +01:00
Wolfgang Bumiller
c21a44b16d
api-macro: factor out inner parser of JSONObject
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:48:00 +01:00
Wolfgang Bumiller
044af76286
api-macro: test: add 'protected' attribute
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:06:15 +01:00
Wolfgang Bumiller
7799deb095
api-macro: refactoring: split api macro function
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 14:18:27 +01:00
Wolfgang Bumiller
97c29f0db5
api-macro: move json part to util module
...
The json value type is more of an intermediate step between
the TokenStream and the Schema type and should stay somewhat
independent of it. We may want to reuse it for the router?
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 14:07:49 +01:00
Wolfgang Bumiller
c5f9227c23
api-macro: remove old unused files
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 14:04:44 +01:00
Wolfgang Bumiller
0a7cc08f3a
api-macro: fix section iteration
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 13:39:56 +01:00
Wolfgang Bumiller
366b50dee7
api-macro: understand a 'Returns:' section in function doc comments
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 13:39:20 +01:00
Wolfgang Bumiller
b899c3e9ee
api-macro: correctly concatenate doc macros
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 13:34:41 +01:00
Wolfgang Bumiller
7f7a9fe92f
api-macro: make type optional in some cases
...
Objects and arrays are now optionally identified by their
'properties' or 'items' property if their 'type' is left
out.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 13:27:54 +01:00
Wolfgang Bumiller
5b41f68891
api-macro: trim doc-comment when used as description
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 12:17:40 +01:00
Wolfgang Bumiller
5a2fe67cd8
api-macro: rename elements to properties
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 12:16:05 +01:00
Wolfgang Bumiller
a646146f75
replace builder-pattern api macro parser with json
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-26 12:12:49 +01:00
Wolfgang Bumiller
5721d21a5e
import a first draft of api macros
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-22 15:23:24 +01:00
Wolfgang Bumiller
068d56ed3d
delete the old api macro stuff
...
to be replaced by a new set of macros for the current api
schema in proxmox-backup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:13:18 +01:00
Wolfgang Bumiller
589cb7e296
macro: enforce Send
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-10-04 14:11:33 +02:00