OpenAPITools / OpenAPITools/openapi-generator

[BUG] [DART] Invalid dart file generated for inline schema models (ValidationError/LocationInner)

Open
#13,302 11 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
  • The backend use python FastAPI and it's API doc generation.
  • Openapi-generator is used to generate from http://127.0.0.1:8000/openapi.json to dart.
  • Specific models linked to new endpoints work and are well generated.
  • However there is an issue generating the models for ValidationError model and it's inline model LocationInner that is an invalid dart file.

image

openapi-generator version

openapi-generator-cli-7.0.0-20220719.043604-2.ja

OpenAPI declaration file content or url
http://127.0.0.1:8000/openapi.json

{
  "openapi": "3.0.2",
  "info": {
    "title": "FastAPI",
    "version": "0.1.0"
  },
  "paths": {
    "/": {
      "get": {
        "summary": "Root",
        "operationId": "root__get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    },
    "/task": {
      "get": {
        "summary": "Gat Task",
        "operationId": "gat_task_task_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      },
      "put": {
        "summary": "Add Task",
        "operationId": "add_task_task_put",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "title": "Task",
                "required": [
                  "id",
                  "name"
                ],
                "type": "object",
                "properties": {
                  "id": {
                    "title": "Id",
                    "type": "string"
                  },
                  "name": {
                    "title": "Name",
                    "type": "string"
                  },
                  "done": {
                    "title": "Done",
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "title": "HTTPValidationError",
                  "type": "object",
                  "properties": {
                    "detail": {
                      "title": "Detail",
                      "type": "array",
                      "items": {
                        "title": "ValidationError",
                        "required": [
                          "loc",
                          "msg",
                          "type"
                        ],
                        "type": "object",
                        "properties": {
                          "loc": {
                            "title": "Location",
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "integer"
                                }
                              ]
                            }
                          },
                          "msg": {
                            "title": "Message",
                            "type": "string"
                          },
                          "type": {
                            "title": "Error Type",
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HTTPValidationError": {
        "title": "HTTPValidationError",
        "type": "object",
        "properties": {
          "detail": {
            "title": "Detail",
            "type": "array",
            "items": {
              "title": "ValidationError",
              "required": [
                "loc",
                "msg",
                "type"
              ],
              "type": "object",
              "properties": {
                "loc": {
                  "title": "Location",
                  "type": "array",
                  "items": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "integer"
                      }
                    ]
                  }
                },
                "msg": {
                  "title": "Message",
                  "type": "string"
                },
                "type": {
                  "title": "Error Type",
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Task": {
        "title": "Task",
        "required": [
          "id",
          "name"
        ],
        "type": "object",
        "properties": {
          "id": {
            "title": "Id",
            "type": "string"
          },
          "name": {
            "title": "Name",
            "type": "string"
          },
          "done": {
            "title": "Done",
            "type": "boolean",
            "default": false
          }
        }
      },
      "ValidationError": {
        "title": "ValidationError",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "type": "object",
        "properties": {
          "loc": {
            "title": "Location",
            "type": "array",
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            }
          },
          "msg": {
            "title": "Message",
            "type": "string"
          },
          "type": {
            "title": "Error Type",
            "type": "string"
          }
        }
      }
    }
  }
}

Generation Details

Generate dart.

Steps to reproduce
  1. Get the json file.
  2. java -jar openapi-generator-cli-7.0.0-20220719.043604-2.jar generate -i http://127.0.0.1:8000/openapi.json -g dart -o openapi
Related issues/PRs

/

Suggest a fix

Not able to identify a fix, shema seems valid, this could be an issue with inline/embeded shema models ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied OpenAPI JSON and the java -jar ... generate -i http://127.0.0.1:8000/openapi.json -g dart -o openapi command. Inspect the generated Dart files for ValidationError and its inline LocationInner model, then verify that the generated output is valid Dart and represents the schemas correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.