Giter Site home page Giter Site logo

Comments (12)

Goldziher avatar Goldziher commented on May 24, 2024

When time allows we will add examples. Checkout the util tests.

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

@Goldziher Thanks, found everything. There's no feature to generate GET parameters from a schema yet I suppose?

from pydantic-openapi-schema.

Goldziher avatar Goldziher commented on May 24, 2024

Can you elaborate on what you have in mind?

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

Better to give an example - as you can see for POST parameters and response body I can pass pydantic class directly, but for GET parameters I have to write it manually.

So is there anything which allows to pass GET parameters to openapi from a pydantic class? Or I simply add missing properties (in, explode) as keywords to pydantic class?

        schema = add_common_parts({}, f"/w2s/schema", "v8", "W2S")
        post = dict(
            requestBody=dict(
                content={
                    "application/json": dict(
                        schema=OpenAPI310PydanticSchema(schema_class=w2s.POSTJSONParameters)
                    ),
                    "multipart/form-data": dict(
                        schema=OpenAPI310PydanticSchema(schema_class=w2s.POSTMultipartParameters)
                    ),
                }
            ),
            responses={
                "201": dict(
                    description="Processed W2 response",
                    content={
                        "application/json": dict(
                            schema=OpenAPI310PydanticSchema(schema_class=w2s.W2)
                        )
                    },
                ),
                "default": DEFAULT_RESPONSE,
            },
        )
        get = dict(
            responses={
                "200": dict(
                    description="List of previously processed documents",
                    content={
                        "application/json": dict(
                            schema=OpenAPI310PydanticSchema(schema_class=w2s.W2S)
                        )
                    },
                ),
                "default": DEFAULT_RESPONSE,
            },
        )
        parameters = [
            {
                "name": "document_id",
                "in": "path",
                "description": "ID of the document",
                "required": True,
                "style": "simple",
                "explode": False,
                "schema": {"type": "integer", "format": "int64"},
            }
        ]

        get_object = dict(
            parameters=parameters,
            responses={
                "200": dict(
                    description="Processed document response.",
                    content={
                        "application/json": dict(
                            schema=OpenAPI310PydanticSchema(schema_class=w2s.W2)
                        )
                    },
                ),
                "default": DEFAULT_RESPONSE,
            },
        )

        schema.update(
            paths={"/w2s": {"post": post, "get": get}, "/w2s/{document_id}": {"get": get_object}},
        )

        open_api_schema = construct_open_api_with_schema_class(OpenAPI.parse_obj(schema))

from pydantic-openapi-schema.

Goldziher avatar Goldziher commented on May 24, 2024

Can't you use the Parameter class?

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

What does it give me?

from pydantic-openapi-schema.

Goldziher avatar Goldziher commented on May 24, 2024

lets start with terminology. What are GET parameters? i think there is some confusion here.

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

query and path parameters in https://swagger.io/docs/specification/describing-parameters/

from pydantic-openapi-schema.

Goldziher avatar Goldziher commented on May 24, 2024

Ok, then to define parameters you have to use the parameter class.

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

Right, what I am asking if there's any helper similar toOpenAPI310PydanticSchema.schema_class which maps a Pydantic class to Parameters?

from pydantic-openapi-schema.

Goldziher avatar Goldziher commented on May 24, 2024

Not at the moment. How would this look?

from pydantic-openapi-schema.

manycoding avatar manycoding commented on May 24, 2024

@Goldziher I think since pydantic allows any keywords in Field, we can just pull all parameter settings from them.
I wrote a simple function which serves me well.

GETParameters(BaseModel):
    id: int = Field(in=path, description="doc id", required=True, schema={"type": "integer", "format": "int64"})

get_object = dict(
    parameters=OpenAPI310PydanticSchema(parameter_schema_class= GETParameters),
    responses={
                "200": dict(
                    description="Processed document response.",
                    content={
                        "application/json": dict(
                            schema=OpenAPI310PydanticSchema(schema_class=DOC)
                        )
                    },
                )            },

Then we can maybe map schema types and required to pydantic schema field type, minimizing it to:

GETParameters(BaseModel):
    id: int = Field(in=path, description="doc id")

from pydantic-openapi-schema.

Related Issues (8)

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.