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

Allow Void Response Body with Model Fields #5172

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

JamesChen-us
Copy link
Contributor

fix #5070

@JamesChen-us
Copy link
Contributor Author

@chrisradek @markcowl
When you have a moment, please take a look at this pr. I’d appreciate your feedback.

@chrisradek
Copy link
Member

@JamesChen-us Thank you for your contribution!

I don't think we want to treat void as an empty schema object for 2 reasons:

  1. An empty schema ({}) typically means anything would validate against it.
  2. This causes the response content-type to be application/json, when really there shouldn't be any content type.

I think to support void in response contents, we could do something similar to what we did for request bodies: check if a response body is a voidType and ignore it if so. I did a quick test modifying this conditional to also check if data.body.type is void and get results that match when the @statusCode is omitted (except with the correct statusCode instead):

if (data.body === undefined) {

@JamesChen-us
Copy link
Contributor Author

@chrisradek Thank you for clarifying the issue. I appreciate the feedback. Updated to skip content generation for void responses instead of creating empty schemas. Let me know if any adjustments are needed.

packages/openapi3/src/schema-emitter.ts Outdated Show resolved Hide resolved
packages/openapi3/src/openapi.ts Outdated Show resolved Hide resolved
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.

[Bug]: OpenAPI errors for @body _: void if not the only field in model
2 participants