Commit Graph

117 Commits

Author SHA1 Message Date
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