Replies: 1 comment
-
My bad... I finally found that a vector of enum does the job: use serde::{Serialize, Deserialize};
use utoipa::{OpenApi, ToSchema};
#[derive(OpenApi)]
#[openapi(
info(description = "My Api description"),
components(
schemas(
MyEnum, Fields, MyEnumVec
),
),
)]
struct ApiDoc;
#[derive(Serialize, Deserialize, ToSchema)]
enum MyEnum {
Value1,
Value2,
Value3,
}
#[derive(Serialize, Deserialize, ToSchema)]
struct MyEnumVec(#[schema(inline)] Vec<MyEnum>);
#[derive(Serialize, Deserialize, ToSchema)]
struct Fields {
first_field: Vec<MyEnum>,
}
fn main() {
let mut doc = ApiDoc::openapi();
doc.info.title = String::from("My Api");
println!("{}", ApiDoc::openapi().to_pretty_json().unwrap());
} {
"openapi": "3.0.3",
"info": {
"title": "utoipa-test",
"description": "My Api description",
"license": {
"name": ""
},
"version": "0.1.0"
},
"paths": {},
"components": {
"schemas": {
"Fields": {
"type": "object",
"required": [
"first_field"
],
"properties": {
"first_field": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyEnum"
}
}
}
},
"MyEnum": {
"type": "string",
"enum": [
"Value1",
"Value2",
"Value3"
]
},
"MyEnumVec": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyEnum"
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I need my OpenAPI definition to feature a
schema
typed as anarray
with a list of (multi)selectableenum
values:Here is a corresponding example definition:
I expected a Rust
enum
to do the job, but I cannot find a way to get the expected result.Any suggestion?
Beta Was this translation helpful? Give feedback.
All reactions