81 Commits

Author SHA1 Message Date
Wolfgang Bumiller
cc065c175d api-macro: introduce updaters
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-03 10:54:18 +01:00
Fabian Grünbichler
43e9cf10af move ParameterSchema from router to schema
it's the place where it belongs, and unbreaks the --no-default-features
build

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-01-13 13:40:04 +01:00
Wolfgang Bumiller
34651099d1 api-macro: support flattened parameters
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:21:43 +01:00
Wolfgang Bumiller
9d9231313d api-macro: suport AllOf on structs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:19:40 +01:00
Wolfgang Bumiller
4916d5b10d api-macro: support optional return values
The return specification can now include an `optional`
field.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:02:47 +01:00
Wolfgang Bumiller
46c71f7da3 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-16 14:21:45 +01:00
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
Wolfgang Bumiller
05749ab419 test fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 14:51:22 +01: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
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
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
5dd21ee89b switch from failure to anyhow
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-04-17 18:34:21 +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
Dietmar Maurer
076501e17e proxmox-api-macro/tests/api1.rs: fix test case 2020-04-16 08:42:05 +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
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
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
edebbf920a fix property sorting
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-23 13:15:59 +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
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
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
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
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
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
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
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
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
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
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