Skip to content

Changes "void_value" into "no_body" for req/responses with no body #444

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

Merged
merged 4 commits into from
May 6, 2021

Conversation

swallez
Copy link
Member

@swallez swallez commented May 5, 2021

Follow-up to #391 (comment)

This PR changes the way we represent no-body responses (and requests) in schema.json:

  • the body property is now required
  • it can now be a NoBody in addition to the existing PropertyBody | ValueBody
  • the void_value value kind has been removed (it doesn't make sense for a property to be of type void)

We also formalize the the close relation between body type and inheritance: when a request or response extends a class, the parent class defines body properties inherited by the child class. The child class therefore has to have a PropertyBody.

The body is required in the schema but is still optional in the spec (ultimately we should enforce it), and a simple heuristic is used to find the correct body type when it's not present in the TS spec:

  • if the request extends a parent class, the body is set to a PropertyBody with an emptu list of properties
  • otherwise it is set to NoBody

New validations verify this.

Aside:

The only exception to the above is RequestBase which is actually a marker class that also links to the CommonRequestParameter behavior. IMHO we should get rid of RequestBase entirely and have requests directly implement the behavior. This is out of scope of this PR.

There are changes in the schema with the new body type, but the TS output has no change except some formatting that is a side effect of body now being required.

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

Great work! I've left a couple of notes.

Copy link
Contributor

@philkra philkra left a comment

Choose a reason for hiding this comment

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

Can we also directly add a specific Response class to extend from in no body cases? Thanks in advance

@swallez
Copy link
Member Author

swallez commented May 6, 2021

@philkra

Can we also directly add a specific Response class to extend from in no body cases? Thanks in advance

Unfortunately no. Parent classes in responses are regular interfaces and not responses (i.e. they don't have this nested structure with body) and so can only be used to defined body properties that are shared among responses extending them.

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@swallez swallez merged commit 8fd84d3 into master May 6, 2021
@swallez swallez deleted the no-body-type branch May 6, 2021 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants