Skip to content
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

added support for zod object for response headers #128

Conversation

AGalabov
Copy link
Collaborator

Resolves #116.

Side note: right now there are 3 approaches to generate response headers:

  1. Directly specifying a HeadersObject through the response
responses: {
  204: {
    description: 'Success',
    headers: { 'Set-Cookie': { schema: { type: 'string' } } },
  },
},
  1. Using custom components:
const apiKeyHeader = registry.registerComponent('headers', 'api-key', {
      example: '1234',
      required: true,
    });

// ...
responses: {
  200: { description: 'Sample response', headers: { 'x-api-key': apiKeyHeader.ref }  }
};
  1. Using ZodObject:
responses: {
  204: {
    description: 'Success',
    headers: z.object({
      'Set-Cookie': z.string().openapi({ example: 'token=test' }),
    }),
  },
},

However I do feel that all are valid because:

  1. Obviouslly we should allow plain documentation to be written as everywhere else in the codde
  2. The custom schemas are a mechanism that can be utilized for response headers but are not necessarily made for that
  3. Adding support for ZodObject seems logical since this is something that could be validated and it is a convenience to support.

Copy link
Collaborator

@georgyangelov georgyangelov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@AGalabov AGalabov merged commit 38b74cb into master May 2, 2023
@AGalabov AGalabov deleted the feature/#116-add-support-for-response-headers-using-zod-objects branch May 2, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZodObjects not accepted in some places
2 participants