We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm using it with:
import fastifySwagger from "@fastify/swagger"; import fastifySwaggerUI from "@fastify/swagger-ui";
As it is described in the documentation of this lib.
Try the following:
app.get( "/", { schema: z.union([z.object({ x: 1 }), z.object({ a: 2 }) ]), },
I believe that z.union should be mapped to anyOf while z.discriminatedUnion should be mapped to oneOf
z.union
z.discriminatedUnion
My complete setup is more or less the following:
import 'zod-openapi/extend'; import fastifySwagger from "@fastify/swagger"; import fastifySwaggerUI from "@fastify/swagger-ui"; import Fastify from "fastify"; import { type FastifyZodOpenApiTypeProvider, fastifyZodOpenApiPlugin, fastifyZodOpenApiTransform, fastifyZodOpenApiTransformObject, serializerCompiler, validatorCompiler, } from 'fastify-zod-openapi'; import { type ZodOpenApiVersion } from 'zod-openapi'; import { logger } from "@/logger"; export async function buildFastifyApp() { const app = Fastify({ loggerInstance: logger, }).withTypeProvider<FastifyZodOpenApiTypeProvider>(); // Add schema validator and serializer app.setValidatorCompiler(validatorCompiler); app.setSerializerCompiler(serializerCompiler); await app.register(fastifyZodOpenApiPlugin, { documentOpts: { unionOneOf: true, } }); await app.register(fastifySwagger, { openapi: { openapi: '3.0.3' satisfies ZodOpenApiVersion, info: { title: "My Project", description: "My Project API", version: "1.0.0", }, servers: [ ], }, transform: fastifyZodOpenApiTransform, transformObject: fastifyZodOpenApiTransformObject, }); await app.register(fastifySwaggerUI, { routePrefix: "/documentation", });
Any thoughts?
The text was updated successfully, but these errors were encountered:
Hey, openapi does not support unions for parameters. If you can find me some examples where it does I'd be happy to help you out
Sorry, something went wrong.
Though, it may be possible to "flatten" the properties in the headers out into an "optional"-esque main object.
I'm referring to this: https://swagger.io/docs/specification/v3_0/data-models/oneof-anyof-allof-not/
From the OpenAPI specs:
And the link to it: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-object
Like I said
Does that make sense?
Yes but you mentioned query strings which are parameters which are cannot use oneOf or anyOf.
https://learn.openapis.org/specification/parameters.html
fastify-zod-openapi/src/transformer.test.ts
Line 962 in 375656f
Here's oneOf working.
No branches or pull requests
I'm using it with:
As it is described in the documentation of this lib.
Try the following:
I believe that
z.union
should be mapped to anyOf whilez.discriminatedUnion
should be mapped to oneOfMy complete setup is more or less the following:
Any thoughts?
The text was updated successfully, but these errors were encountered: