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

Enhancement: Allow Parameter(schema_extra=...) / ResponseSpec(schema_extra=...) #3022

Open
tuukkamustonen opened this issue Jan 24, 2024 · 2 comments
Labels
Enhancement This is a new feature or request

Comments

@tuukkamustonen
Copy link
Contributor

tuukkamustonen commented Jan 24, 2024

Summary

Pydantic provides Field(json_schema_extra=...) which allows to do something like:

def forbid_internal_labels(value):
    if re.match(r"^reserved-for-internal-use:.*$", value):
        raise ValueError(...)

class Foo(BaseModel):
    label: Annotated[str, AfterValidator(forbid_internal_labels), Field(json_schema_extra={
        "not": {
            {
                "type": "string",
                "pattern": "^reserved-for-internal-use:.*$"
            },
        }
    })]

This would generate:

                "type": "string",
                "not": {
                    {
                        "type": "string",
                        "pattern": "^reserved-for-internal-use:.*$"
                    },
                }

It doesn't actually add/do any validation, it merely impacts the generated JSON schema.

Similar mechanism is needed for Parameter, to inject discriminators (e.g. anyOf, not) into the OpenAPI spec (although the validation is decoupled from the schema declaration).

The builtin generation uses oneOf for union types (IIRC Pydantic uses anyOf for those). But I don't think it's possible to declare something like above.

Workarounds at this point would be:

  • To adjust via custom Operation class (did not try but I assume it could work)
  • To adjust the OpenAPI generation on a more global level (by extending OpenAPIPlugin?)

Both are quite ugly hacks, while something like this should be supported out-of-the-box.

Basic Example

No response

Drawbacks and Impact

No response

Unresolved questions

No response


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@tuukkamustonen tuukkamustonen added the Enhancement This is a new feature or request label Jan 24, 2024
@tuukkamustonen
Copy link
Contributor Author

tuukkamustonen commented Feb 3, 2024

As mentioned in #3018 (comment) Parameter(schema_extra=...) could be supported, and that's what this ticket is about.

Having an independent schema_extra for Parameter seems fine though.

I guess ResponseSpec(schema_extra=...) should exist, too.

@tuukkamustonen tuukkamustonen changed the title Enhancement: Allow customizing/extending Parameter schema Enhancement: Allow Parameter(schema_extra=...) to extend/customize the generated OpenAPI schema Mar 8, 2024
@tuukkamustonen tuukkamustonen changed the title Enhancement: Allow Parameter(schema_extra=...) to extend/customize the generated OpenAPI schema Enhancement: Allow Parameter(schema_extra=...) / ResponseSpec(schema_extra=...) Mar 8, 2024
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 14, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 15, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 15, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 15, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 15, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 15, 2024
…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 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).
provinzkraut pushed a commit to tuukkamustonen/litestar that referenced this issue Mar 16, 2024
…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 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).
provinzkraut pushed a commit to tuukkamustonen/litestar that referenced this issue Mar 16, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 17, 2024
…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 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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 17, 2024
…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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 18, 2024
…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).
tuukkamustonen added a commit to tuukkamustonen/litestar that referenced this issue Mar 18, 2024
…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).
cofin pushed a commit that referenced this issue Mar 19, 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
JacobCoffee added a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
robswc pushed a commit to robswc/litestar that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
JacobCoffee added a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
JacobCoffee added a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit to robswc/litestar that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit to robswc/litestar that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
provinzkraut pushed a commit to robswc/litestar that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
peterschutt pushed a commit that referenced this issue 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 <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

* Update litestar/params.py

Co-authored-by: Jacob Coffee <jacob@z7x.org>

---------

Co-authored-by: Jacob Coffee <jacob@z7x.org>
@tuukkamustonen
Copy link
Contributor Author

Parameter(shema_extra=...) has been merged in #3204.

It did not add the same for ResponseSpec, however (due to technical difficulties, see the PR description).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This is a new feature or request
Projects
Status: Triage
Development

No branches or pull requests

1 participant