Coder Social home page Coder Social logo

Enhancement: Only generate example once when `Parameter(examples=[...])` is specified for path arg and its schema about litestar HOT 4 OPEN

tuukkamustonen avatar tuukkamustonen commented on June 16, 2024
Enhancement: Only generate example once when `Parameter(examples=[...])` is specified for path arg and its schema

from litestar.

Comments (4)

provinzkraut avatar provinzkraut commented on June 16, 2024

Not really a bug I think but rather an enhancement. We have a few instances where this kind of duplication occurs and it's reasonable to optimise some of these away. Iirc @peterschutt you were discussing a similar case recently regarding DTOs?

from litestar.

tuukkamustonen avatar tuukkamustonen commented on June 16, 2024

This perhaps-too-eager-example-generation also applies to the response examples created via OpenAPIConfig(..., create_examples=True) as well, e.g.:

  "components": {
    "schemas": {
      "Response": {
        "properties": {
          "text": {
            "type": "string",
            "examples": {
              "text-example-1": {  <---- example per field, unnecessary?
                "description": "Example text value",
                "value": "DwEkQQHiBrmXZcSFtoJx"
              }
            }
          },
          "num": {
            "type": "integer",
            "examples": {
              "num-example-1": {  <---- example per field, unnecessary?
                "description": "Example num value",
                "value": 4966
              }
            }
          }
        },
        "type": "object",
        "required": [
          "num",
          "text"
        ],
        "title": "Response",
        "examples": {
          "response-example-1": {  <---- example per model, this is ok
            "description": "Example  value",
            "value": {
              "text": "IgNZYFcagWptUqCwdERi",
              "num": 3674
            }
          }
        }
      }
    }
  }

I don't know if the GUIs actually need or benefit from field-specific examples, but perhaps the model level one would suffice.

from litestar.

provinzkraut avatar provinzkraut commented on June 16, 2024

I don't know if the GUIs actually need or benefit from field-specific examples, but perhaps the model level one would suffice.

IMO as long as we don't have more granular settings for turning example generation on/off, generating them everywhere it's supported is the more reasonable approach since it covers more use cases. Say we don't generate examples for the fields but a user wanted examples generated for that, they would have no way of turning this on. This way, we might make the schema a bit more verbose, but it actually doesn't do any harm to have these examples in there.

from litestar.

tuukkamustonen avatar tuukkamustonen commented on June 16, 2024

That's a fair statement. All off by default, all enabled with create_examples=True.

However, currently errors do get examples by default, e.g.:

                  "examples": {
                    "NotAuthorized": {
                      "value": {
                        "status_code": 401,
                        "detail": "Missing or invalid credentials",
                        "extra": {}
                      }
                    }
                  }
                }

That's an exception to the rule.

And then you allow disabling example generation with ResponseSpec. Another exception, perhaps (but no harm in that).


I guess there are roughly 4 modes here:

  1. JSON schema only
  2. OpenAPI schema only
  3. Both JSON + OpenAPI
  4. None

There could be a toggle, but I agree that global on/off should be sufficient, as the OpenAPI schema is really intended as machine-readable and not really for humans.

(The other issue #3058 confused me a bit here.)

from litestar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.