nestia
nestia copied to clipboard
Enum as its own schema
Feature Request
I would like to have enums not generated in the swagger as an inline type string schema with enum values but as its own schema element, that can be reused and have its own name. This same functionality is supported by the builtin NestJs swagger generator: https://docs.nestjs.com/openapi/types-and-parameters#enums-schema
If you can give me a few pointers I can try to come up with a PR.
Example method
enum AnimalEnum {
Cat,
Dog
}
interface RequestBody {
animal: AnimalEnum
}
public function exampleRequest(@TypedBody() body: RequestBody)
Expected output
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"animal": {
"$ref": "#/components/schemas/AnimalEnum"
}
}
}
}
}
},
"components": {
"schemas": {
"AnimalEnum": {
"type": "string",
"enum": [
"Cat",
"Dog"
]
},
}
},
Actual output
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"animal": {
"type": "string",
"enum": [
"Cat",
"Dog"
]
}
}
}
}
}
},