Commit Graph

18 Commits

Author SHA1 Message Date
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
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
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
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
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
Wolfgang Bumiller
30a1c0b9ae api-macro: experimental enum support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 12:21:46 +01:00
Wolfgang Bumiller
6818cf76c9 api-macro: support defining schemas for structs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 11:15:37 +01:00
Wolfgang Bumiller
4f042f8133 api-macro: support external types
See the test example:

assuming a `pub struct Foo` which implements `Serialize` and
`Deserialize`, we also expect it to provide a
`pub const Foo::API_SCHEMA: &Schema` like so:

    #[derive(Deserialize, Serialize)]
    pub struct StrongString(String);
    impl StrongString {
        pub const API_SCHEMA: &'static Schema =
            &StringSchema::new("Some generic string")
                .format(&ApiStringFormat::Enum(&["a", "b"]))
                .schema();
    }

Then we can use:

    #[api(
        input: {
            properties: {
                arg: { type: StrongString },
            }
        },
        ...
    )]
    fn my_api_func(arg: StrongString) -> Result<...> {
        ...
    }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 10:42:35 +01:00