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

feat: Support schema_extra in Parameter and Body #3204

Merged

Conversation

tuukkamustonen
Copy link
Contributor

@tuukkamustonen tuukkamustonen commented Mar 14, 2024

Description

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as dict[str, Any] where the key must match with the
keyword parameter name in Schema. The values are used to override items in
the generated Schema object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting Schema object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for ResponseSpec because response models are
generated as schema components, while ResponseSpec can be locally different.
Handling the logic of creating new components when schema_extra is passed in
ResponseSpec would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

Closes

#3022

@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch from cac47f5 to 4eca4a5 Compare March 14, 2024 17:08
@tuukkamustonen tuukkamustonen changed the base branch from main to develop March 14, 2024 17:09
@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch from 4eca4a5 to 5fb5d31 Compare March 14, 2024 17:15
@tuukkamustonen
Copy link
Contributor Author

Uh, JSONDecodeError on Python 3.11... what what...

@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch 11 times, most recently from 712557e to 010d422 Compare March 15, 2024 08:33
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.25%. Comparing base (c1c9f53) to head (9a1c879).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3204      +/-   ##
===========================================
+ Coverage    98.23%   98.25%   +0.01%     
===========================================
  Files          322      322              
  Lines        14658    14665       +7     
  Branches      2330     2333       +3     
===========================================
+ Hits         14400    14409       +9     
+ Misses         117      116       -1     
+ Partials       141      140       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch from 010d422 to 58ff90f Compare March 15, 2024 09:08
@tuukkamustonen tuukkamustonen marked this pull request as ready for review March 15, 2024 09:28
@tuukkamustonen tuukkamustonen requested review from a team as code owners March 15, 2024 09:28
@provinzkraut provinzkraut force-pushed the schema-extra-for-parameters-and-body branch from 58ff90f to a48ad58 Compare March 16, 2024 09:03
@provinzkraut provinzkraut force-pushed the develop branch 2 times, most recently from 353ebca to 525cd4c Compare March 16, 2024 09:07
@provinzkraut provinzkraut force-pushed the schema-extra-for-parameters-and-body branch from a48ad58 to f5fa87c Compare March 16, 2024 09:13
@JacobCoffee
Copy link
Member

I think this needs a rebase :)

@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch from f5fa87c to a605a2a Compare March 17, 2024 20:06
@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch 2 times, most recently from 0994335 to 991962d Compare March 18, 2024 06:43
@provinzkraut provinzkraut deleted the branch litestar-org:develop March 18, 2024 17:08
@provinzkraut provinzkraut reopened this Mar 18, 2024
@tuukkamustonen
Copy link
Contributor Author

@provinzkraut You seem to have a convention to force push to develop, which generates conflicts in the PRs. Is it intentional or...?

Should I rebase this or...?

tuukkamustonen and others added 4 commits March 18, 2024 22:59
…3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).
Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Jacob Coffee <[email protected]>
@tuukkamustonen tuukkamustonen force-pushed the schema-extra-for-parameters-and-body branch from 991962d to 9a1c879 Compare March 18, 2024 20:59
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3204

Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

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

Thanks for this! LGTM

@cofin cofin merged commit 0c39fa8 into litestar-org:develop Mar 19, 2024
20 checks passed
JacobCoffee added a commit that referenced this pull request Mar 22, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit that referenced this pull request Mar 29, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit that referenced this pull request Mar 29, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit that referenced this pull request Mar 30, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
robswc pushed a commit to robswc/litestar that referenced this pull request Apr 2, 2024
…3204)

* feat: Support `schema_extra` in `Parameter` and `Body` (litestar-org#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
JacobCoffee added a commit that referenced this pull request Apr 5, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
JacobCoffee added a commit that referenced this pull request Apr 5, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit that referenced this pull request Apr 7, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit to robswc/litestar that referenced this pull request Apr 7, 2024
…3204)

* feat: Support `schema_extra` in `Parameter` and `Body` (litestar-org#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit to robswc/litestar that referenced this pull request Apr 7, 2024
…3204)

* feat: Support `schema_extra` in `Parameter` and `Body` (litestar-org#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
provinzkraut pushed a commit to robswc/litestar that referenced this pull request Apr 7, 2024
…3204)

* feat: Support `schema_extra` in `Parameter` and `Body` (litestar-org#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
peterschutt pushed a commit that referenced this pull request Apr 9, 2024
* feat: Support `schema_extra` in `Parameter` and `Body` (#3022)

This adds sort of a backdoor for modifying the generated OpenAPI spec.

The value is given as `dict[str, Any]` where the key must match with the
keyword parameter name in `Schema`. The values are used to override items in
the generated `Schema` object, so they must be in correct types (ie. not in
dictionary/json format).

The values are added at main level, without recursive merging (because we're
adjusting `Schema` object and not a dictionary). Recursive merge would be much
more work.

Chose not to implement the same for `ResponseSpec` because response models are
generated as schema components, while `ResponseSpec` can be locally different.
Handling the logic of creating new components when `schema_extra` is passed in
`ResponseSpec` would be extra effort, and isn't probably as important as being
able to adjust the inbound parameters, which are actually validated (and for
which the documentation is even more important, than for the response).

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <[email protected]>

---------

Co-authored-by: Jacob Coffee <[email protected]>
@tuukkamustonen tuukkamustonen deleted the schema-extra-for-parameters-and-body branch June 3, 2024 06:42
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.

5 participants