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

Add required field to object and request body definitions #399

Merged
merged 3 commits into from
Jan 14, 2024

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Jan 2, 2024

Motivation

As mentioned in #388 (comment) I think it would be good practice to add the required field to object and request body definitions.

This main reasons for this are

  • openapi spec compliance / technical correctness
  • detect missing properties during schema validation by using ajv or similar tooling
  • allows to generate correct types via openapi-generator, properties are no longer optional (type safety)
  • clarity on how to make properties optional (Make getPeersV1 meta element optional #388)

Description

  • Add required properties to object types
  • Add required field to request bodies

Copy link
Member

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

OpenAPI spec clearly states that all properties of objects are optional by default (https://swagger.io/docs/specification/data-models/data-types/#object). All clients and consumers assume otherwise so we should align the spec with reality.

Reviewed all changes (long PR..) and are correct 👍

@jeluard
Copy link
Contributor

jeluard commented Jan 10, 2024

I could also confirm that this PR does the following:

  • explicit all properties of all components as required (openapi defaults to all properties optional)
  • mark all requestBody as required (openapi defaults to not required)

Also note that required is already correctly set for parameters (either true or false) and required: false was already set for some optional requestBody (the default, but better be explicit probably).

Nice job @nflaig ! Great step towards improving API interoperability and making sure testing can be automated.

@rolfyone rolfyone merged commit aca52c9 into ethereum:master Jan 14, 2024
3 checks passed
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.

4 participants