Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1095
Closed
Open
Issue created Sep 24, 2018 by Administrator@rootContributor

Invalid code generated for missing discriminator property, but validation passes

Created by: wheezil

Description

A spec with missing discriminator property passes validation, but generates invalid (Java) code.

openapi-generator version

3.3.0-SNAPSHOT

OpenAPI declaration file content or url
{
    "openapi": "3.0.0",
    "info": {
        "description": "blah",
        "version": "1.0.0",
        "title": "blah"
    },
    "paths": {
        "/test": {
            "post": {
                "tags": [
                  "test"
                ],
                "operationId": "testOp",
                "responses": {
                    "405": {
                        "description": "Invalid input"
                    }
                },
                "requestBody": {
                    "$ref": "#/components/requestBodies/Test"
                }
            }
        }
    },
    "components": {
        "requestBodies": {
            "Test": {
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Test"
                        }
                    }
                }
            }
        },
        "schemas": {
            "Base": {
                "properties": {
                    "status": {
                        "type": "string"
                    }
                },
                "discriminator":{
                    "propertyName": "type"
                }
            },
            "Test": {
                "allOf":[
                    { "$ref": "#/components/schemas/Base" },
                    {
                        "type":"object",
                        "properties": {
                            "name": {
                                "type": "string"
                            }
                        }
                    }
                ]
            }
        }
    }
}

rpdmcpp.config is

{
	"declspec" : "DL_GLOBAL_CLASS",
	"appName" : "RPDM",
	"appDescription" : "RedPoint Data Management services"
}
Command line used for generation

Validate succeeds

java -cp openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator validate -i test2.json
Validating spec (test2.json)
No validation issues detected.

But java code generation: java -cp openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator generate -v -o genjava -g java -i test2.json -c rpdmcpp.config produces non-compiling code. The problem is that the type field is not defined. In Base.java:

  public Base() {
    this.type = this.getClass().getSimpleName();
  }
Suggest a fix/enhancement

Validation should flag the spec as being in error.

Assignee
Assign to
Time tracking