Closed imjuni closed 1 year ago
I would say a no here.
You can provide your custom buildLocalReference
through the options. It is already dynamic enough to achieve any feature.
Add another option just for it is overkill.
@climba03003 your right. I set custom buildLocalReference
and I get wished documents.
I will close this issue. Thank you 👍
Hey @climba03003, what do you think of changing the default impl of buildLocalReference
? Something like:
function buildLocalReference(json: any, _: unknown, __: unknown, i: number) {|
if (!json.title && json.$id) {
json.title = json.$id
}
return json.title || json.$id || `def-${i}`
}
We already define our schema title or ID, using an auto generated def-X
seems to be a bad default, specially in production systems that generates code with this spec. I know we can override the buildLocalReference
, but overriding it everywhere shows it could have a better default impl.
"components": {
"schemas": {
"def-0": {},
"def-1": {},
"def-2": {},
// ...
}
},
Current implementation:
I'm open to do a PR :)
Prerequisites
🚀 Feature Proposal
Add new option swagger reference component name generate
$id
instead ofdef-
.eg.
Generated
def-
generate like this,
Motivation
I try to use swagger-typescript-api or openapi-generator.
I apply swagger-typescript-api on my project and I found some enhance point from fastify-swagger.
Below source-code is auto generated TypeScript interface.
I think that more useful
export interface IPokemonDto { ... }
thenexport interface Def2 { ... }
.In fastify-swagger,
Example
I create example repo.
Reproduce this issue,
Open new terminal and change directory maeum.
And you can found auto generated document from
resources/apis/generated
.