Commit Graph

187 Commits

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