cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
403 stars 134 forks source link

Better error reporting / handling #321

Open alex-aveva opened 6 months ago

alex-aveva commented 6 months ago

I came across rather large OpenAPI spec with over 3K of lines which had one of properties object defined incorrectly, here's example:

{
  "openapi": "3.0.1",
  "paths": {
    "/users": {
      "get": {
        "summary": "Get all users",
        "responses": {
          "200": {
            "description": "List of user object",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/User"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "type": null
        }
      }
    }
  }
}

Nnotice that components.schemas.User.properties has type: null.

If you attempt to run npx ng-openapi-gen -i test.json error will be quite missleading: Error on API generation from test.json: TypeError: Cannot read properties of null (reading 'description')

I wonder if it will be possible to have better error handling and perhaps show line number where JSON schema parser chocked?

luisfpg commented 2 months ago

Sorry, I'm not having any time for this project. Except that a PR is provided, it won't be done. Even with a PR it might take some time until I'm able to review and merge.