Wolfgang Bumiller
7c48247c58
formatting fixup
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-05 11:32:48 +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
7609cf2bd4
api-macro: move doc-comment reading to util
...
The function attribute reader doesn't read any other
attributes anymore, so make it reusable!
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 11:47:27 +01:00
Wolfgang Bumiller
8a6e741d6c
api: let ConstRegexPattern deref to Regex
...
This way we can just use `SOME_REGEX.is_match()` again
without having to explicitly call `(SOME_REGEX.regex_obj)()`
first.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-04 11:06:03 +01:00
Wolfgang Bumiller
197b1bccb3
api-macro: rename SimpleIdent to FieldName
...
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>
2019-12-04 09:06:31 +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
f3f15c2893
api-macro: drop ToTokens for SimpleIdent
...
The user must be explicit about whether the ident or string
is required.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:58:40 +01:00
Wolfgang Bumiller
b7ecf3a597
api-macro: drop Deref of SimpleIdent
...
The user must always be explicit about whether the Ident or
the String is required, since they may differ.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:57:07 +01:00
Wolfgang Bumiller
7533252072
api-macro: fixup idents in SimpleIdent
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:56:27 +01:00
Wolfgang Bumiller
02acd7269f
api-macro: remove Into<Ident> for SimpleIdent
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-03 11:55:14 +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
Dietmar Maurer
55f90b4eac
proxmox_api/src/format.rs - get_property_description: fix paragraph indention
2019-12-03 07:55:53 +01:00
Dietmar Maurer
4bca463944
proxmox-api/src/format.rs: improve docs
2019-12-02 20:06:14 +01:00
Dietmar Maurer
00f3a6575c
proxmox-api/src/format.rs: add missing docs
2019-12-02 19:50:04 +01:00
Dietmar Maurer
8f7127a9aa
proxmox-api/src/cli/shellword.rs: re-export Quote from rustyline
2019-12-02 19:29:47 +01:00
Dietmar Maurer
a9275caa61
proxmox-api/src/cli/completion.rs: add more tests
2019-12-02 17:34:11 +01:00
Dietmar Maurer
f9d4dcc540
proxmox-api/src/cli/completion.rs: add help completion tests
2019-12-02 16:42:59 +01:00
Dietmar Maurer
1819b194a4
proxmox_api: add cli submodule (copied from proxmox-backup)
2019-12-02 11:49:58 +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
21fab51bda
api-macro: allow 'bool' and rust int types
...
in place of Boolean and Integer
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-02 10:55:01 +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
Dietmar Maurer
354cfabd37
proxmox-api: fix text_wrap() - use join instead of concat (separate by newlines)
2019-12-01 12:30:50 +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
Wolfgang Bumiller
2fc2df9a78
api-macro: tests: remove #![allow(dead_code)]
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:29:45 +01:00
Wolfgang Bumiller
74ed56957d
api-macro: match the item type early
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:16:34 +01:00
Wolfgang Bumiller
1ae127b63a
api-macro: move method handling to api/method.rs
...
We may want to add the ability to declare a Schema for
structs, so factorize function handling into its own file.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-28 09:13:33 +01:00
Wolfgang Bumiller
993eb7d168
api-macro: update tests, cleanup some macro generated paths
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:46:20 +01:00
Wolfgang Bumiller
0bf354e437
api-macro: convert function output to a json value
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:44:16 +01:00
Wolfgang Bumiller
6e98ae0dd3
api-macro: minor improvements
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:41:51 +01:00
Wolfgang Bumiller
03012deb3f
api-macro: reduce code output a little
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:04:14 +01:00
Wolfgang Bumiller
881df81976
api-macro: start actually extracting parameters
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 14:00:41 +01:00
Wolfgang Bumiller
d02a8f4e42
api-macro: begin and explain the parameter mapping strategy
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 12:29:50 +01:00
Wolfgang Bumiller
79f77253be
api-macro: start looking at function parameter types
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:31:40 +01:00
Wolfgang Bumiller
09d1363fa0
api-macro: start checking some function signature parts
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:04:36 +01:00
Wolfgang Bumiller
ebda5a3c5c
api-macro: parse properties as attributes to #[api]
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:01:40 +01:00
Wolfgang Bumiller
676ef1796d
api-amcro: expose JSONObject::parse_inner as Parser
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 11:01:12 +01:00
Wolfgang Bumiller
d4721d77b7
api-macro: JSONValue to bool shortcut
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:59:37 +01:00
Wolfgang Bumiller
c21a44b16d
api-macro: factor out inner parser of JSONObject
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:48:00 +01:00
Wolfgang Bumiller
044af76286
api-macro: test: add 'protected' attribute
...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-27 10:06:15 +01:00