1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 08:00:41 +00:00

enum representations

[skip ci]
This commit is contained in:
Dominic 2021-03-09 00:17:13 +01:00
parent 5f60599c41
commit a57f1c097d
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
5 changed files with 246 additions and 19 deletions

View file

@ -19,4 +19,5 @@ serde_json = "1.0"
[dev-dependencies]
paste = "1.0"
serde = "1.0"
trybuild = "1.0"

View file

@ -43,6 +43,15 @@ test_type!(SimpleStruct = {
"required": ["foo", "bar"]
});
#[derive(OpenapiType)]
#[openapi(rename = "FooBar")]
struct StructRename;
test_type!(StructRename = {
"type": "object",
"title": "FooBar",
"additionalProperties": false
});
#[derive(OpenapiType)]
enum EnumWithoutFields {
Success,
@ -119,6 +128,7 @@ test_type!(EnumWithFields = {
#[derive(OpenapiType)]
enum EnumExternallyTagged {
Success { value: isize },
Empty,
Error
}
test_type!(EnumExternallyTagged = {
@ -139,6 +149,101 @@ test_type!(EnumExternallyTagged = {
"required": ["Success"]
}, {
"type": "string",
"enum": ["Error"]
"enum": ["Empty", "Error"]
}]
});
#[derive(OpenapiType)]
#[openapi(tag = "ty")]
enum EnumInternallyTagged {
Success { value: isize },
Empty,
Error
}
test_type!(EnumInternallyTagged = {
"title": "EnumInternallyTagged",
"oneOf": [{
"type": "object",
"properties": {
"value": {
"type": "integer"
},
"ty": {
"type": "string",
"enum": ["Success"]
}
},
"required": ["value", "ty"]
}, {
"type": "object",
"properties": {
"ty": {
"type": "string",
"enum": ["Empty", "Error"]
}
},
"required": ["ty"]
}]
});
#[derive(OpenapiType)]
#[openapi(tag = "ty", content = "ct")]
enum EnumAdjacentlyTagged {
Success { value: isize },
Empty,
Error
}
test_type!(EnumAdjacentlyTagged = {
"title": "EnumAdjacentlyTagged",
"oneOf": [{
"type": "object",
"properties": {
"ty": {
"type": "string",
"enum": ["Success"]
},
"ct": {
"type": "object",
"properties": {
"value": {
"type": "integer"
}
},
"required": ["value"]
}
},
"required": ["ty", "ct"]
}, {
"type": "object",
"properties": {
"ty": {
"type": "string",
"enum": ["Empty", "Error"]
}
},
"required": ["ty"]
}]
});
#[derive(OpenapiType)]
#[openapi(untagged)]
enum EnumUntagged {
Success { value: isize },
Empty,
Error
}
test_type!(EnumUntagged = {
"title": "EnumUntagged",
"oneOf": [{
"type": "object",
"properties": {
"value": {
"type": "integer"
}
},
"required": ["value"]
}, {
"type": "object",
"additionalProperties": false
}]
});