Commit Graph

300 Commits

Author SHA1 Message Date
Wolfgang Bumiller
d18292192d bump proxmox-api-macro to 1.0.1-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-10-12 14:51:35 +02:00
Wolfgang Bumiller
5988a1adf1 drop automatically_derived attribute for now
new rustc seems to *sometimes* complain about it

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-10-12 14:49:11 +02: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
cb96de1c4d bump proxmox-api-macro to 0.5.1-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-30 10:46:05 +02:00
Wolfgang Bumiller
76641b0a72 api-macro: allow external schemas in 'returns' specification
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-26 13:34:23 +02:00
Wolfgang Bumiller
0f2caafc4e bump proxmox to 0.13.0-1 and proxmox-api-macro to 0.5.0
and proxmox-http to 0.4.0... urgh

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-25 09:41:17 +02:00
Wolfgang Bumiller
917ce00dd6 rustfmt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-13 13:31:57 +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
017b81712e api macro: assume that field types are api types by default
#[api]
    struct Foo {
        field: Bar,
    }

does not require the use of
    #[api(
        properties: {
            field: {
                type: Bar,
            },
        },
    )]

anymore

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-10 11:42:24 +02:00
Wolfgang Bumiller
8ebcd68a2c refactor serde parsing for later reuse
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-08-10 11:42:24 +02:00
Thomas Lamprecht
c75e706006 proxmox-api-macro: bump version to 0.4.0
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-07-20 17:45:29 +02:00
Dietmar Maurer
5cbddad172 update versions in generated control files 2021-07-20 15:45:45 +02:00
Dietmar Maurer
82d7a1cdbf bump proxmox version to 0.12.0-1 2021-07-20 15:45:45 +02:00
Wolfgang Bumiller
6729d41188 bump api-macro to 0.3.4-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-04-14 12:00:01 +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
248335df36 api-macro: fix dev-dep versions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-03-24 11:20:23 +01:00
Wolfgang Bumiller
1f6a2a66c9 bump api-macro to 0.3.3-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-24 09:37:30 +01: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
4e375ba95c bump api-macro to 0.3.2-1
This got lost in a rebase...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-11 09:00:44 +01:00
Wolfgang Bumiller
50e9148853 api-macro: pull in 'extra-traits' feature from syn
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-04 13:11:34 +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
dd767723d8 formatting fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-02-03 10:54:18 +01:00
Wolfgang Bumiller
034dd3fe5e updaters: docs and exports
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
dc5b2bebf1 debcargo: fix maintainer directive
and remove accidentally committed files

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-02-01 11:26:33 +01:00
Fabian Grünbichler
586d94947b bump proxmox-api-macro to 0.3.1-1
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-01-14 15:42:54 +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
9a290275c3 macro: refactoring
purely non-functional changes

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-01-05 13:50:55 +01:00
Dietmar Maurer
04417d1df5 update control files, fix changelogs 2020-12-22 13:29:09 +01:00
Dietmar Maurer
f6e7463ec1 bump versions to 0.9.0-1/0.3.0-1 2020-12-22 07:54:32 +01:00
Wolfgang Bumiller
bc0355e582 macro: temporary d/changelog update
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:24:09 +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
4802e0321b api-macro: factor parameter extraction into a function
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:21:25 +01:00
Wolfgang Bumiller
301918529d api-macro: more tuple refactoring
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:21:13 +01:00
Wolfgang Bumiller
75530cb68c api-macro: object schema entry tuple -> struct
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:20:48 +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
357b3016d5 api-macro: add more standard Maybe methods
Note that any methods added there should be oriented around
`Option`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:19:16 +01:00
Wolfgang Bumiller
6b5bf36989 api-macro: forbid flattened fields
They don't appear in the json data structure and therefore
should not be named separately in the schema. Structs with
flattened fields will become an `AllOf` schema instead.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:18:46 +01:00
Wolfgang Bumiller
fbc9be471b api-macro: add 'flatten' to SerdeAttrib
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:18:08 +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
4dec479d2c update d/control
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:44:58 +01:00
Wolfgang Bumiller
8cc4c167ac bump proxmox-api-macro to 0.2.4-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:43:49 +01:00
Wolfgang Bumiller
0ad74b431e api-macro: lower a whole bunch of errors
to be non fatal for better error messages, this way the user
will see the compile error, but we still generate all the
code & schema variables so that one error isn't accompanied
by all the ones resulting from not having the generated code
there at all.

Eg.

    error: description not allowed on external type
       --> src/api2/access/user.rs:472:22
        |
    472 |         description: "Get API token metadata (with config digest).",
        |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Was previously also accompanied by

    error[E0425]: cannot find value `API_METHOD_READ_TOKEN` in this scope
       --> src/api2/access/user.rs:774:11
        |
    699 | pub fn delete_token(
        | ------ similarly named constant `API_METHOD_DELETE_TOKEN` defined here
    ...
    774 |     .get(&API_METHOD_READ_TOKEN)
        |           ^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `API_METHOD_DELETE_TOKEN`

The second error was "wrong" and came much later, needlessly
filling the screen if this happened on multiple functions.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-07 15:34:02 +01:00
Wolfgang Bumiller
273ce60242 api-macro: forbid description on incompatible schemas
References to external schemas (or types) already include
the description in the external schema and therefore are
illegal.

The implementation consists of multiple parts:

* Introduce a `Maybe` type which can be `Explicit`,
  `Derived` or `None`.
* Forbid `Explicit` descriptions on references.
* Instead of bailing out on such errors which causes all of
  the generated code to vanish and create heaps of
  additional nonsensical errors, add a way to *add* errors
  without bailing out immediately via the `error!()` macro.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-07 15:09:45 +01:00
Fabian Grünbichler
cce052e97f build: track d/control in git
and check build-dependencies before building..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-30 15:13:01 +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