Skip to content

Add support for const property #242

@githubjakob

Description

@githubjakob

OpenAPI supports a const property to indicate that an attribute has exactly one possible value.

Pydantic model_json_schema automatically generates this from Literal fields that define a single value.

class MyResponseModel(BaseModel):
    foobar: Literal["baz"]

Flask-OpenApi3 should produce the following schema:

components:
  schemas:
    MyResponseModel:
      properties:
        foobar:
          const: baz
          title: Foobar
          type: string

I am using Flask-OpenApi3 to generate Typescript types from the API spec, and it would be great to have const so that the Typescript type could be a string literal instead of just a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions