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>
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>
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>
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>
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>