Skip to content

Support OpenAPI schema 3.1.0 #895

@Aokigahara23

Description

@Aokigahara23

Hello guys, recently got into a need to generate a client for my app written in fastapi 0.104.1 version.
Since version 0.99.0 FastAPI uses openapi of version 3.1.0 and they've also updated swagger-ui to match those updates - i've got into some problems(

OpenAPI Spec File

{
  "openapi": "3.1.0",
  "info": {
    "title": "Some service",
    "description": "Description of some service",
    "version": "0.1.0"
  },
  "paths": {
    "/known_issue/": {
      "get": {
        "tags": ["known_issue"],
        "summary": "Get List",
        "description": "Get list of known issues",
        "operationId": "get_list_known_issue__get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/KnownIssueDBSchema"
                  },
                  "type": "array",
                  "title": "Response Get List Known Issue  Get"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["known_issue"],
        "summary": "Create",
        "description": "Create new known issue item",
        "operationId": "create_known_issue__post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KnownIssueCreateSchema"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/KnownIssueDBSchema" }
              }
            }
          },
          "409": {
            "description": "Entity already exists",
            "content": {
              "application/json": {
                "example": { "message": "Entity already exists" }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
              }
            }
          }
        }
      }
    },
    "/known_issue/{workitem_id}": {
      "patch": {
        "tags": ["known_issue"],
        "summary": "Update",
        "description": "Update a known issue",
        "operationId": "update_known_issue__workitem_id__patch",
        "parameters": [
          {
            "name": "workitem_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 20,
              "pattern": "^\\d{6}$",
              "title": "Issue ID",
              "description": "Issue ID as a TFS workitem in format of #xxxxx",
              "examples": ["123456"]
            },
            "description": "Issue ID as a TFS workitem in format of #xxxxx"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KnownIssueUpdateSchema"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/KnownIssueDBSchema" }
              }
            }
          },
          "404": {
            "description": "Entity not found",
            "content": {
              "application/json": {
                "example": { "message": "Entity not found" }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
              }
            }
          }
        }
      },
      "delete": {
        "tags": ["known_issue"],
        "summary": "Delete",
        "description": "Delete a known issue",
        "operationId": "delete_known_issue__workitem_id__delete",
        "parameters": [
          {
            "name": "workitem_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 20,
              "pattern": "^\\d{6}$",
              "title": "Issue ID",
              "description": "Issue ID as a TFS workitem in format of #xxxxx",
              "examples": ["123456"]
            },
            "description": "Issue ID as a TFS workitem in format of #xxxxx"
          }
        ],
        "responses": {
          "204": { "description": "Successful Response" },
          "404": {
            "description": "Entity not found",
            "content": {
              "application/json": {
                "example": { "message": "Entity not found" }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": { "$ref": "#/components/schemas/ValidationError" },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "KnownIssueCreateSchema": {
        "properties": {
          "workitem_id": {
            "type": "string",
            "maxLength": 20,
            "pattern": "^\\d{6}$",
            "title": "Issue ID",
            "description": "Issue ID as a TFS workitem in format of #xxxxx",
            "examples": ["123456"]
          },
          "workitem_url": {
            "type": "string",
            "maxLength": 200,
            "pattern": "^http(s)?:\\/\\/(.*)",
            "title": "Item URL",
            "description": "Entity URL",
            "examples": [
              "https://dev.azure.com/organization/project/_workitems/edit/123456"
            ]
          }
        },
        "type": "object",
        "required": ["workitem_id", "workitem_url"],
        "title": "KnownIssueCreateSchema"
      },
      "KnownIssueDBSchema": {
        "properties": {
          "workitem_id": {
            "type": "string",
            "maxLength": 20,
            "pattern": "^\\d{6}$",
            "title": "Issue ID",
            "description": "Issue ID as a TFS workitem in format of #xxxxx",
            "examples": ["123456"]
          },
          "workitem_url": {
            "type": "string",
            "maxLength": 200,
            "pattern": "^http(s)?:\\/\\/(.*)",
            "title": "Item URL",
            "description": "Entity URL",
            "examples": [
              "https://dev.azure.com/organization/project/_workitems/edit/123456"
            ]
          }
        },
        "type": "object",
        "required": ["workitem_id", "workitem_url"],
        "title": "KnownIssueDBSchema"
      },
      "KnownIssueUpdateSchema": {
        "properties": {
          "workitem_id": {
            "anyOf": [
              { "type": "string", "maxLength": 20, "pattern": "^\\d{6}$" },
              { "type": "null" }
            ],
            "title": "Issue ID",
            "description": "Issue ID as a TFS workitem in format of #xxxxx",
            "examples": ["123456"]
          },
          "workitem_url": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 200,
                "pattern": "^http(s)?:\\/\\/(.*)"
              },
              { "type": "null" }
            ],
            "title": "Item URL",
            "description": "Entity URL",
            "examples": [
              "https://dev.azure.com/organization/project/_workitems/edit/123456"            ]
          }
        },
        "type": "object",
        "title": "KnownIssueUpdateSchema"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": { "anyOf": [{ "type": "string" }, { "type": "integer" }] },
            "type": "array",
            "title": "Location"
          },
          "msg": { "type": "string", "title": "Message" },
          "type": { "type": "string", "title": "Error Type" }
        },
        "type": "object",
        "required": ["loc", "msg", "type"],
        "title": "ValidationError"
      }
    }
  }
}

I've taken everything out except one entity from my fastapi app. So running the:

openapi-python-client generate --path ./openapi.json

Gives me

11 validation errors for OpenAPI                                                                                                                       
components.schemas.KnownIssueUpdateSchema.Reference.$ref                                                                                               
  Field required [type=missing, input_value={'properties': {'workitem...KnownIssueUpdateSchema'}, input_type=dict]                                     
    For further information visit https://errors.pydantic.dev/2.5/v/missing                                                                            
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_id.Reference.$ref                                                                 
  Field required [type=missing, input_value={'anyOf': [{'type': 'stri... 'examples': ['123456']}, input_type=dict]                                     
    For further information visit https://errors.pydantic.dev/2.5/v/missing                                                                            
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_id.Schema.anyOf.1.Reference.$ref                                                  
  Field required [type=missing, input_value={'type': 'null'}, input_type=dict]                                                                         
    For further information visit https://errors.pydantic.dev/2.5/v/missing                                                                            
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_id.Schema.anyOf.1.Schema.type                                                     
  Input should be 'string', 'number', 'integer', 'boolean', 'array' or 'object' [type=enum, input_value='null', input_type=str]                        
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_url.Reference.$ref                                                                
  Field required [type=missing, input_value={'anyOf': [{'type': 'stri...unCharts&runId=123456']}, input_type=dict]                                     
    For further information visit https://errors.pydantic.dev/2.5/v/missing                                                                            
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_url.Schema.anyOf.1.Reference.$ref                                                 
  Field required [type=missing, input_value={'type': 'null'}, input_type=dict]                                                                         
    For further information visit https://errors.pydantic.dev/2.5/v/missing                                                                            
components.schemas.KnownIssueUpdateSchema.Schema.properties.workitem_url.Schema.anyOf.1.Schema.type                                                    
  Input should be 'string', 'number', 'integer', 'boolean', 'array' or 'object' [type=enum, input_value='null', input_type=str]                        
openapi.`literal['3.0.0']`                                                                                                                             
  Input should be '3.0.0' [type=literal_error, input_value='3.1.0', input_type=str]                                                                    
    For further information visit https://errors.pydantic.dev/2.5/v/literal_error                                                                      
openapi.`literal['3.0.1']`                                                                                                                             
  Input should be '3.0.1' [type=literal_error, input_value='3.1.0', input_type=str]                                                                    
    For further information visit https://errors.pydantic.dev/2.5/v/literal_error                                                                      
openapi.`literal['3.0.2']`                                                                                                                             
  Input should be '3.0.2' [type=literal_error, input_value='3.1.0', input_type=str]                                                                    
    For further information visit https://errors.pydantic.dev/2.5/v/literal_error                                                                      
openapi.`literal['3.0.3']`                                                                                                                             
  Input should be '3.0.3' [type=literal_error, input_value='3.1.0', input_type=str]                                                                    
    For further information visit https://errors.pydantic.dev/2.5/v/literal_error   

Ofc there are more errors but they are very the same, so it is no point in providing full schema.

I'm sorry guys if i don't see the simple solution here, i really don't mind to have one).
But if the solution is "just downgrade thing" - i will consider this, but the problem will remain...

**Desktop

  • OS: Linux Fedora 39
  • Python Version - 3.10.13
  • openapi-python-client version - 0.15.2

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions