-
-
Notifications
You must be signed in to change notification settings - Fork 638
Closed as not planned
Labels
Description
Describe the feature
Question
Is it possible to configure Nitro OpenAPI to use a generator from @asteasolutions/zod-to-openapi
to automatically add OpenAPI objects to one or more routes?
Example Code
import { extendZodWithOpenApi, OpenApiGeneratorV3 } from '@asteasolutions/zod-to-openapi';
import { z } from 'zod';
extendZodWithOpenApi(z);
const fieldDefinitions = {
'title': {
label: 'Project name',
placeholder: 'Project name',
validation: z
.string()
.min(1, "Project name is required")
.openapi({ description: 'Project name' }),
},
'case-number': {
label: 'Case-number',
placeholder: 'Case-number',
validation: z
.string()
.min(1, "Case-number is required")
.openapi({ description: 'Case-number' }),
},
'case-manager': {
label: 'Case-manager',
placeholder: 'Case-manager',
validation: z
.string()
.min(1, "Case-manager is required")
.openapi({ description: 'Case-manager' }),
},
'contributor': {
label: 'Contributor',
placeholder: 'Contributor',
validation: z
.string()
.min(1, "Contributor is required")
.openapi({ description: 'Project contributor' }),
},
};
export const metadataSchema = z
.object(
Object.fromEntries(
Object.entries(fieldDefinitions).map(([key, { validation }]) => [
key,
validation,
])
)
)
.openapi('Metadata');
export const formFields = Object.entries(fieldDefinitions).map(
([key, { label, placeholder }]) => ({
id: key,
label,
type: 'text',
placeholder,
})
);
const generator = new OpenApiGeneratorV3([metadataSchema]);
### Additional information
- [ ] Would you be willing to help implement this feature?
vdiachenko, mola1129 and de-n3xus