-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
When I have a schema like:
export const CircuitTypeSchema = z
.enum([
'RACE',
'ROAD',
'STREET'
])
.openapi('CircuitType', { description: 'Represents a circuit type.' });
export const CircuitSchema = z
.object({
id: z.string().openapi({ description: 'The unique identifier.', example: 'melbourne' }),
name: z.string().openapi({ description: 'The name.', example: 'Melbourne' }),
type: CircuitTypeSchema, // .openapi({ description: 'The circuit type.', example: 'STREET' }),
})
.openapi('Circuit', { description: 'Represents a circuit.' });
this will generate a openapi spec like:
"components":{
"schemas":{
"CircuitType":{
"type":"string",
"enum":[
"RACE",
"ROAD",
"STREET"
],
"description":"Represents a circuit type."
},
"Circuit":{
"type":"object",
"properties":{
"id":{
"type":"string",
"description":"The unique identifier.",
"example":"melbourne"
},
"name":{
"type":"string",
"description":"The name.",
"example":"Melbourne"
},
"type":{
"$ref":"#/components/schemas/CircuitType"
},
},
"required":[
"id",
"name",
"type" ],
"description":"Represents a circuit."
}
},
which is good except, that I explicitly want to set the description and example for the Circuit.type field (which is now not specified.
So I tried with:
type: CircuitTypeSchema.openapi({ description: 'The circuit type.', example: 'STREET' }),
which unfortunately does not change the Circuit.type but the top-level CircuitType schema only:
"CircuitType": {
"type": "string",
"enum": [
"RACE",
"ROAD",
"STREET"
],
"description": "The circuit type.", <== Should be 'Represents the circuit type.'
"example": "STREET" <== I don't want an example here.
},
and the Circuit.type:
"Circuit":{
"type":"object",
"properties":{
..
"type":{
"$ref":"#/components/schemas/CircuitType"
},
Is there a way to document (openapi) the Circuit.type field, bit not affect the top-level schema type?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels