-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
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
schema response per content type #621
Comments
I think you can define separate routes using the constraint option: https://www.fastify.io/docs/latest/Reference/Routes/#constraints. However you are a bit on uncharted territories as I do not think anybody as tested this pattern. Officially supporting it would be great in both fastify and fastify-swagger. Would you like to send a few PRs? |
Cool. I'll try and find time to add this. Care to point me where in fastify source I should probably start? |
Here is where the response's schemas are compiled: |
I'm running into the same issue, especially the OpenAPI/Swagger part. I'm willing to contribute a solution for this, but constraints are dynamic, so I struggle to see how we'd be able to infer the correct response or request body for the OpenAPI specification. Any guidance would be very helpful! import headerConstraintStrategy from "header-constraint-strategy";
const api = fastify({
// ...
constraints: {
accept: headerConstraintStrategy("accept");
},
});
api.post(
`/assets`,
{
schema: Type.Object({ file: Type.String({ format: "binary" }) }),
// While the constraint doesn't look dynamic, it only works because we registered the constraint in the `fastify` constructor. Using this to infer the accept header could work if we standardize the `accept` constraint?
constraints: { accept: "multipart/form-data" },
},
async function(request, reply) {
// ...
},
);
api.post(
`/assets`,
{
schema: Type.Object({ fileUrl: Type.String() }),
constraints: { accept: "application/json" },
},
async function(request, reply) {
// ...
},
); |
Related issue: fastify/fastify#3902 |
💬 Question here
Would you consider updating the schema response config to also support a response per the request "accept" header?
This would also be beneficial when fastify-swagger dynamically generates an OAS v3 definition.
fastify/fastify-swagger#117
The text was updated successfully, but these errors were encountered: