Commit Graph

99 Commits

Author SHA1 Message Date
Wolfgang Bumiller
c31eaf0018 router, rest-server, api-macro: rename Streaming api to Serializing
This does not "stream", but rather skips the intermediate step to
serialize the entire output into a local json string.

We now reserve the "Stream*" prefix for actual *streaming*, that is,
producing an API response which gets streamed continuously as it is
asynchronously produced.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-09-05 14:15:11 +02:00
Wolfgang Bumiller
c3713cffe5 api-macro: fix warnings in tests
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-08-06 14:23:38 +02:00
Wolfgang Bumiller
839f508f55 api-macro: type-key support for derived enums
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-08-06 14:14:42 +02:00
Wolfgang Bumiller
4d96aa52d2 section-config, api-macro: add SectionConfig enum support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-08-06 14:14:42 +02:00
Wolfgang Bumiller
51d78fdd2b api-macro: handle renames in updater derive
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-08-06 14:14:42 +02:00
Wolfgang Bumiller
38a60d3acb api: support #[default] attribute
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-12-12 11:34:18 +01:00
Wolfgang Bumiller
7fe84f8e15 api-macro: allow overriding field attributes in the updater
This allows fixing up things such as `skip_serialize_if`
calls like so:

    #[derive(Updater)]
    struct Foo {
        #[serde(skip_serializing_if = "MyType::is_special")]
        #[updater(serde(skip_serializing_if = "Option::is_none"))]
        field: MyType,
    }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-05-11 16:00:42 +02:00
Dominik Csapak
ca3b25869c proxmox-api-macro: add 'streaming' option
to generate the `Streaming` variants of the ApiHandler

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-04-12 14:23:05 +02:00
Stefan Sterz
0b90f8d802 api-macro: fix "Forgerty" typo
Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
2022-02-07 15:38:39 +01:00
Wolfgang Bumiller
d871d6849b api-macro: formatting
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-07 11:51:09 +01:00
Wolfgang Bumiller
41f3fdfeb9 add proxmox-schema and proxmox-router crates
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-10-11 11:39:59 +02:00
Wolfgang Bumiller
744d69c2ab more updater cleanups
* Updatable is now named UpdaterType
* UPDATER_IS_OPTION is now assumed to always be true
    While an updater can be a non-optional struct, being an
    updater, all its fields are also Updaters, so after
    expanding all levels of nesting, the resulting list of
    fields can only contain optional values.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-13 11:11:27 +02:00
Wolfgang Bumiller
cb9d57b453 put API_SCHEMA variable into ApiType trait
This way we can assign `API_SCHEMA` constants to `Option`
types.

Here's why:

The api-macro generated code usese `T::API_SCHEMA` when
building ObjectSchemas.

For Updaters we replace `T` with
  `<T as Updatable>::Updater`

This means for "simple" wrappers like our `Authid` or
`Userid`, the ObjectSchema will try to refer to
  `<Authid as Updatable>::Updater::API_SCHEMA`
which resolves to:
  `Option<Authid>::API_SCHEMA`
which does not exist, for which we cannot add a normal
`impl` block to add the schema variable, since `Option` is
not "ours".

But we now have a blanket implementation of `ApiType` for
`Option<T> where T: ApiType` which just points to the
original `T::API_SCHEMA`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-12 10:15:13 +02:00
Wolfgang Bumiller
783cbcb499 fixup schema entry for updaters with explicit types
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-10 14:17:20 +02:00
Wolfgang Bumiller
34020ea3d6 change updater derivation
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-10 12:03:29 +02:00
Wolfgang Bumiller
cde2863a68 api-macro: fix Updatable path in generated derive attribute
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-04-14 11:58:32 +02:00
Wolfgang Bumiller
857b8ab2b9 Updater: take serde renames into account
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-24 09:21:52 +01:00
Wolfgang Bumiller
223d7ed55c api-macro: let tests depend on api-macro
the updater tests require both the trait and the proc macros
to be visible, running tests with `--all-features` prevents
them from being imported from two separate locations as
their names are the same, so let's always include the macro
versions in test cases by depending on the `api-macro`
feature in tests in the api-macro crate

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-03 10:54:18 +01:00
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