OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.54k stars 6.51k forks source link

Readonly parameter generates error in csharp templates during build #412

Open mdulisch opened 6 years ago

mdulisch commented 6 years ago
Description

In line 58 ind the modelGeneric.mustache there is a problem with the read Only vars. The constructor of the parent does not have the read only Variables defined. But the base call does.

So if you have a read only property which inherited (allOf) by another class, the build will fail.

openapi-generator version

3.0.2

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "version": "1.0.0",
    "title": "Simple API",
    "description": "A simple API to learn how to write OpenAPI Specification"
  },
  "paths": {
    "/test": {
      "get": {
        "responses": {
          "200": {
            "description": "test"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ModelBase": {
        "description": "Base model definition for models.",
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "General-purpose alphanumeric unique identifier.",
            "maxLength": 11
          },
          "autoId": {
            "type": "integer",
            "format": "int32",
            "description": "An automatic generated unique identifier used for internal purposes like faster sorting or filtering.",
            "readOnly": true
          }
        }
      },
      "CommonModel": {
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/ModelBase"
          },
          {
            "type": "object",
            "properties": {
              "commonProp": {
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 11,
                  "description": "The id of the grouping."
                }
              }
            }
          }
        ]
      }
    }
  }
}
Command line used for generation

java -jar .\openapi-generator-cli-3.0.2.jar generate --generator-name csharp -i .\swagger.json -o ./out

Steps to reproduce

try to build the result :-)

Related issues/PRs
Suggest a fix/enhancement

rename parentVars in parentReadWriteVars in the file mentioned above.

jmini commented 6 years ago

@mdulisch: Thank you for your message. I have updated your message to format your spec. This goes like this on GitHub (without the spaces at the beginning of each line):

    ##### OpenAPI declaration file content

    ```json
    <your json spec here>