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
Wolfgang Bumiller
df55ab2dda
api-macro: update to 1.0 of syn/quote/proc_macro2
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-10-04 13:42:03 +02:00
Wolfgang Bumiller
e0b50d07bf
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-28 10:36:43 +02:00
Wolfgang Bumiller
617e25abba
api: make ApiMethodInfo already require Send + Sync
...
ApiMethodInfo provides static information about a type
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-28 10:30:33 +02:00
Wolfgang Bumiller
eb4e28d7bf
remove async_await feature gate
...
then we can build with beta as well
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-28 10:10:06 +02:00
Wolfgang Bumiller
7864cef16d
update hyper & tokio to alpha releases
...
tokio: alpha.2 to alpha.4
hyper: git alpha.0 to crates.io alpha.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-06 10:13:32 +02:00
Wolfgang Bumiller
05b432c422
[clippy] macro: remaining clippy lints
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:24:37 +02:00
Wolfgang Bumiller
c241be9e6a
[clippy] macro: ident implements comparsion with strings
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:20:49 +02:00
Wolfgang Bumiller
7f2ae4f272
[clippy] api-test: remove unnecessary lifetimes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:15:03 +02:00
Wolfgang Bumiller
025eaf5519
api-macro: fix non-async test case after adding verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-16 12:21:32 +02:00
Wolfgang Bumiller
bb937395f7
macro: functions: call verify() on all parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-16 10:18:33 +02:00
Wolfgang Bumiller
a7b9c8d89e
fixup tests for router change
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@errno.eu>
2019-08-15 20:26:18 +02:00
Wolfgang Bumiller
bb2639bf40
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:34:23 +02:00
Wolfgang Bumiller
8e24ada75a
macro: support deriving Display for newtypes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:01:21 +02:00
Wolfgang Bumiller
50f5115718
macro: fix enum verify method
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 14:00:59 +02:00
Wolfgang Bumiller
37cf2e6208
macro: fixup previous commit: remove hardcoded error
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 13:30:35 +02:00
Wolfgang Bumiller
0046e5e33a
macro: experimental support for enums with values
...
enum Foo {
Variant1(Type), // allowed
Variant2(Type, Type), // not allowed
Variant3 { name: Type }, // not allowed
}
In the simple case of a single type we simply drop the
automatically derived `FromStr`/`Display` impls and expect
the user to implement them manually, while in the `verify()`
method we simply match on self and forward to the inner
verifier.
So to get "tagged unions" in the API, implement a proper
API type for each variant, then add an enum with 1-tuple
variants.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 12:00:12 +02:00
Wolfgang Bumiller
fb5670c5b5
macro: remove exact futures-preview version
...
Otherwise we have .16 and .17 in the same project. And we
can't go to .18 currently until hyper/tokio git-master are
in sync again.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-12 10:42:19 +02:00
Wolfgang Bumiller
169bf79c72
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
ed503f689d
macro: split enum handler into separate module
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
59d0c72642
macro: split struct handlers into separate submodules
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
841c2a218d
macro: split function handler into separate file
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-09 12:42:06 +02:00
Wolfgang Bumiller
080f62916e
macro: errors shouldn't discard the code
...
Otherwise we'll get even more errors.
Consider this example:
#[api(...)]
struct Foo { ... }
impl MyTrait for Foo { ... }
If the #[api] macro fails and does not at least produce the
`struct Foo{}` along with its `compile_error!()` output,
then in addition to our macro errors, we'll see errors about
trying to implement `MyTrait` for an unknown thing called
`Foo`.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 14:04:28 +02:00
Wolfgang Bumiller
cad8f2f1c3
macro: implement #[derive(FromStr)] for newtypes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:54:17 +02:00
Wolfgang Bumiller
e3273d6172
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:13:35 +02:00
Wolfgang Bumiller
cfa6f0f67f
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 13:13:19 +02:00
Wolfgang Bumiller
bb3e2859e4
macro: derive ser/de for newtypes just like structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:29:12 +02:00
Wolfgang Bumiller
a53e8c5e82
macro: make sure errors are separated
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:17:37 +02:00
Wolfgang Bumiller
818dc25478
macro: factor out newtype handler
...
Reuse verifier code of structs fields. Add handling of
'validate' methods for fields.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:14:47 +02:00
Wolfgang Bumiller
dfdf354b0d
macro: more quote -> quote_spanned changes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:09:58 +02:00
Wolfgang Bumiller
af04fc5764
macro: remove unused add_verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-08 11:09:29 +02:00
Wolfgang Bumiller
d78142302c
formatting fixup
...
add #[rustfmt::skip] to our macros...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 09:45:14 +02:00
Wolfgang Bumiller
ef13b38632
macro: improve error output
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 15:42:07 +02:00
Wolfgang Bumiller
3a36ff78df
macro: clear a warning
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:39:18 +02:00
Wolfgang Bumiller
14acfcd5cd
macro: recurse into struct field verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:35:00 +02:00
Wolfgang Bumiller
3c31381fb2
macro: support 'pattern' verifier in structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-31 14:32:35 +02:00
Wolfgang Bumiller
2a4af329a7
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 15:20:55 +02:00
Wolfgang Bumiller
d5ee03da9f
macro: support serialize_with and deserialize_with
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 15:19:51 +02:00
Wolfgang Bumiller
a6fcaf27e5
macro: don't enforce the AsOptionStr type on formats
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 10:33:07 +02:00
Wolfgang Bumiller
fab0210287
api, macro: implement 'format' verifier for structs
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 10:06:32 +02:00
Wolfgang Bumiller
b77733c8ef
api: macro: implement minimum/maximum_length checks
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:40:04 +02:00
Wolfgang Bumiller
f1f4c14819
api: verify: rename Verify to TestMinMax
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:30:32 +02:00
Wolfgang Bumiller
20b8c709c6
api: add helper module for verifiers
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:16:05 +02:00
Wolfgang Bumiller
30105c5743
refactor struct handling
...
less spaghetti code accumulation, more purpose oriented
functions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 12:01:20 +02:00
Wolfgang Bumiller
bb62206e27
macro: disable derive_default for now
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:24:39 +02:00
Wolfgang Bumiller
5d9fe0d24d
macro: fixup: don't create unwanted default impl snippets
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:20:45 +02:00
Wolfgang Bumiller
8523e03486
macro: partial support for automatic Default derivation
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 15:17:25 +02:00
Wolfgang Bumiller
50eadf23fb
macro: support Option in deserialization
...
When deserializing we currently expect all fields to be
available, but we actually want Option types to be truly
optional...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:50:23 +02:00
Wolfgang Bumiller
ce5fa31721
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:30:48 +02:00
Wolfgang Bumiller
061cc5b525
implement accessors for types with defaults
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:09:15 +02:00
Wolfgang Bumiller
cb2c260f87
default to not serializing None options
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 13:22:18 +02:00
Wolfgang Bumiller
d9f57ed107
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:08:38 +02:00
Wolfgang Bumiller
ec1ad87193
macro: replace named struct handler
...
We now derive Serialize and Deserialize automatically.
This way we'll be able to add verifiers right into the
structs, support our 'rename' functionality, and our
'default' handling etc. which needs to be compatible with
what we have in perl.
Ideally this will also give us the option to mark structs as
being perl-compatible "property strings"
(PVE::JSONSchema::parse_property_string()) and automatically
derive FromStr for structs on demand.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:04:55 +02:00
Wolfgang Bumiller
0a8a9cdb5b
macro: error handling
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:04:38 +02:00
Wolfgang Bumiller
bb62dde9b0
macro: common defs: add default, and sort
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:01:59 +02:00
Wolfgang Bumiller
bb673ec0db
macro: improved error output
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 09:58:07 +02:00
Wolfgang Bumiller
183125b1cd
macro: named struct: allow short form for fields
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 15:05:26 +02:00
Wolfgang Bumiller
c54afe1be4
macro: add spans to more errors
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:59:09 +02:00
Wolfgang Bumiller
f340968773
macro: ability to rename enum variants via an attribute
...
In PVE we have multiple different enum types: hyphenated,
all-caps, underscores.
By default our api-macro enums will convert CamelCase to
underscores, so we need a way to represent the rest:
enum AnEnum {
CaseOne, // becomes "case_one",
#[api(rename = "case-two")]
CaseTwo, // "case-two",
#[api(rename = "CASE_THREE")]
CaseThree,
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:52:25 +02:00
Wolfgang Bumiller
4b3333aa5c
macro: cleanup error handling, remove error module
...
syn::Error already covers this
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:41:27 +02:00
Wolfgang Bumiller
09eaef022f
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:58:26 +02:00
Wolfgang Bumiller
43d69cb1aa
macro: more error handling improvements
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:57:51 +02:00
Wolfgang Bumiller
9c9413ae56
macro: add types.rs, preserve Span for Expressions
...
Move the Name type into types.rs and make it hashable.
Expression::Object not contains an Object where the
hashmap's key is a Name and therefore preserves the Span of
all the keys for better error messages.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:54:52 +02:00
Wolfgang Bumiller
4803bfcb59
macro: add TypeInfo for enum types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:26:57 +02:00
Wolfgang Bumiller
7510f3179c
macro: more absolute paths
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:26:49 +02:00
Wolfgang Bumiller
a034fe3335
cleanup/remove old code
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:15:21 +02:00
Wolfgang Bumiller
7f704d12df
macro: started basic enum support
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:14:58 +02:00
Wolfgang Bumiller
624afe28a4
prepare to parse enums
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:51:16 +02:00
Wolfgang Bumiller
da40267188
api-server, tools: formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:47:56 +02:00
Wolfgang Bumiller
9654d1feeb
macro: add spanned format_err equivalent
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:47:41 +02:00
Wolfgang Bumiller
145abf62a5
macro: helpers for error handling
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:30:40 +02:00
Wolfgang Bumiller
a1c8b00f17
example for better error messages
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 16:49:19 +02:00
Wolfgang Bumiller
bfbba4e605
tests: use an async block instead of an async closure
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 16:13:36 +02:00
Wolfgang Bumiller
205a9fc2aa
api: split ApiHandler out of ApiMethodInfo
...
The method info part is not generic after all.
(Makes it easier to test different representations of
ApiHandler without having to adapt all the other methods as
well.)
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-07-01 09:48:33 +02:00
Wolfgang Bumiller
8a2d7a43e0
macro: cleanup: rename parse_object2 to parse_object
...
The old parse_object function is gone now.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-26 15:08:20 +02:00
Wolfgang Bumiller
c8e11115d2
api: replace handler() with call()
...
An `fn` type can be more annoying to produce in some generic
cases, and we haven't really needed it yet.
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-23 11:19:49 +02:00
Wolfgang Bumiller
b4378755f0
api-macro: remove old comment
...
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-23 11:10:32 +02:00
Wolfgang Bumiller
bd79dd8f02
api: make method body an associated type
...
This way we do not need to carry the body type into the CLI
router and can instead just require the body to be
Into<Bytes>.
This also makes more sense, because previously a method
could in theory implement multiple ApiMethodInfo types with
different bodies which seems pointless.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-19 15:16:40 +02:00
Wolfgang Bumiller
a5af6eedf7
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:32:42 +02:00
Wolfgang Bumiller
c48e17fe26
macro: add cli
property and remove specialization
...
Drop #!feature(specialization) in favor of having a `cli`
property for types to decide whether they are CLI
compatible.
The unconstrained_type! macro now has both ParseCli and
ParseCliFromStr in view, and requires one of the two to be
implemented for a type. This means that if a type implements
FromStr, it should "just work".
For types created without the help of the #[api] macro,
there's a shortcut to exclude a type from the CLI via
the no_cli_type!{typename} macro.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
691af5cade
add the ParseCli trait
...
In order to get parameters from the command line into the
API we need to get them into a json value, so that we can
pass it down the handler which deserializes them into their
real type and runs verifications.
For this we need to define how the type is going to be
converted into a json Value. We cannot simply use
Deserialize as that would for instance require quotes
around strings. So instead, we have a ParseCli trait, which
is a nop (direct serde_json::Value::String()) for string
types, and uses .parse() (the std::str::FromStr trait) for
everything else.
Currently this uses a `default fn` as an example of the
specialization feature, but I'll probably remove this and
use yet another mass-impl macro since there isn't much
activity on that feature's issue tracker. (The issue itself
seems to be outdated ...
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
b243d9664d
macro: implement minimum and maximum verification
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-13 14:29:09 +02:00
Wolfgang Bumiller
23d8e1d4e0
api: Parameter::type_info must be an fn
...
while filling the Parameter fields as &'static we cannot
really make use of the get_type_info() yet because it would
need to be a `const fn` (possible via #!feature(const_fn)),
so for now we store the method pointer until `const_fn` is
stable
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 16:43:24 +02:00
Wolfgang Bumiller
1a279f54a9
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 16:33:27 +02:00
Wolfgang Bumiller
41884a622e
macro: check function parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 16:33:12 +02:00
Wolfgang Bumiller
11b09e578c
router: parse an optional visibility
...
The 'pub' in `pub static ROUTER: ...`
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 15:31:19 +02:00
Wolfgang Bumiller
841799d882
fixup add missing question mark
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
1c1c8530c5
formatting cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
7db28deaff
macro: body type support for router and api macros
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
10451f65eb
rewrite parse_object
...
This should support arbitrary expresion, so gobble up
elements up to the next comma and then run it through
syn::parse2.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
1791c089b6
macro: need to allow specifying the body type now
...
TODO:
- change parse_object to use Punctuated for the fields to
support longer value types (so we can use actual types
as fields)
- allow adding a body type to methods
- allow adding a body type to routers explicitly
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
ff2767129f
rename reload_timezone -> reload-timezone
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
b82b14d947
macro: add wildcard matching to router macro
...
router!{
/path/{parameter}*: {
methods...
}
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
dcfa3ca9a2
allow async api methods to return Response<Bytes>
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
3f7e4c0eda
router: add remaining missing ::proxmox::api:: prefixes
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
2b577c9c17
cleanup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
1993460d4a
allow integer literals as subdirectories
...
eg: /api/2/ should be legal
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
f3e2e672be
use 'quote' in router macro
...
get rid of a lot of unreadable TokenTree entries
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
7155689724
fix missing proxmox_api -> proxmox::api replacement
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
cd23e0956a
macro: switch to using proxmox::api
...
and fixup a `bail!` -> `::failure::bail!`
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
3dd6cd3fe0
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-07 12:03:17 +02:00
Wolfgang Bumiller
b5c05fc85c
import proxmox-api-macro crate
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 15:25:47 +02:00