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

openapi: remove JSON body second validation and type casting (#1170) #53

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

gaetano-guerriero
Copy link

  • openapi: remove body preprocessing

Body is already validated using jsonschema. There was also some type
casting but it was wrong: e.g. not recurring deeply into dicts and lists,
relying on existence of "type" in schema (which is not there e.g. if
oneOf is used). Anyway, the only reason why types should be casted is
converting integer values to float if the type is number. But this is in
most cases irrelevant.

Added an example, which did not work before this commit (echoed {})
e.g. for

curl localhost:8080/api/foo -H 'content-type: application/json' -d
'{"foo": 1}'

but now the example works (echoes {"foo": 1}).

  • test with oneOf in the requestBody

  • remove oneof examples: superseded by tests

Co-authored-by: Pavol Vargovcik pavol.vargovcik@kiwi.com

Fixes #.

…rst#1170)

* openapi: remove body preprocessing

Body is already validated using jsonschema. There was also some type
casting but it was wrong: e.g. not recurring deeply into dicts and lists,
relying on existence of "type" in schema (which is not there e.g. if
oneOf is used). Anyway, the only reason why types should be casted is
converting integer values to float if the type is number. But this is in
most cases irrelevant.

Added an example, which did not work before this commit (echoed `{}`)
e.g. for
```
curl localhost:8080/api/foo -H 'content-type: application/json' -d
'{"foo": 1}'
```
but now the example works (echoes `{"foo": 1}`).

* test with oneOf in the requestBody

* remove oneof examples: superseded by tests

Co-authored-by: Pavol Vargovcik <pavol.vargovcik@kiwi.com>
@gaetano-guerriero
Copy link
Author

Cherry pick from spec-first#1170

Basically now this works:

requestBody:
  content:
    application/json:
      schema:
        oneOf:
        - type: int
        - type: str

Unexpectedly this already worked:

requestBody:
  content:
    application/json:
      schema:
        type: object
        properties:
        foo:
          oneOf:
            - type: int
            - type: str

Copy link

@vmarkovtsev vmarkovtsev left a comment

Choose a reason for hiding this comment

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

Thanks!

@vmarkovtsev vmarkovtsev merged commit a77c923 into main Aug 12, 2022
@vmarkovtsev vmarkovtsev deleted the backport-fix-for-oneof-body-properties branch August 12, 2022 08:19
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.

3 participants