-
Given a struct #[derive(Debug, Deserialize, utoipa::ToSchema)]
#[schema(as = config)]
pub struct Config {
/// test url
#[schema(example = "https://localhost/api")]
pub(crate) url: String,
/// test api key
#[serde(serialize_with = "expose_secret_string")]
pub(crate) access_token: SecretString,
/// input
#[schema(example = "eee")]
pub(crate) input_field: SpecialString,
/// input1
#[schema(example = "ooah")]
pub(crate) input_field1: String,
/// input2
#[schema(example = "bla")]
pub(crate) input_field2: InputField,
/// input3
#[schema(example = "blub")]
pub(crate) input_field3: OtherInputField,
}
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct InputField {
/// input
#[schema(example = "blub")]
pub(crate) reference: String,
}
#[derive(Debug, Deserialize)]
pub struct OtherInputField;
impl<'__s> utoipa::ToSchema<'__s> for OtherInputField {
fn schema() -> (
&'__s str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
let ref_schema = utoipa::openapi::Ref::new(
"https://localhost:12345/schema#/definitions/InputField",
);
("OtherInputField", ref_schema.into())
}
} the resulting properties are "properties": {
"url": {
"type": "string",
"description": "test url",
"example": "https://localhost/api"
},
"access_token": {
"$ref": "#/components/schemas/SecretString"
},
"input_field": {
"$ref": "#/components/schemas/SpecialString"
},
"input_field1": {
"type": "string",
"description": "input1",
"example": "ooah"
},
"input_field2": {
"$ref": "#/components/schemas/InputField"
},
"input_field3": {
"$ref": "#/components/schemas/OtherInputField"
}
} while the doc comments and the example don't appear at all for all custom structs. I'm wondering what obvious thing I'm missing. Afaik I was hoping to get results like "properties": {
"url": {
"type": "string",
"description": "test url",
"example": "https://localhost/api"
},
"access_token": {
"$ref": "#/components/schemas/SecretString",
"description": "test api key"
},
"input_field": {
"$ref": "#/components/schemas/SpecialString"
"description": "input",
"example": "eee"
},
"input_field1": {
"type": "string",
"description": "input1",
"example": "ooah"
},
"input_field2": {
"$ref": "#/components/schemas/InputField",
"description": "input2",
"example": "bla"
},
"input_field3": {
"$ref": "#/components/schemas/OtherInputField",
"description": "input3",
"example": "blub"
}
} What I'm a missing? Thanks in advance |
Beta Was this translation helpful? Give feedback.
Answered by
smndtrl
Aug 10, 2024
Replies: 1 comment
-
My bad. I confused OAS 3.1 vs 3.0.3. This works with the 3.1 branch. Amazing |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
smndtrl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My bad. I confused OAS 3.1 vs 3.0.3. This works with the 3.1 branch. Amazing