Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf needs $ref first #2924

Open
fehguy opened this issue May 20, 2016 · 3 comments
Open

allOf needs $ref first #2924

fehguy opened this issue May 20, 2016 · 3 comments

Comments

@fehguy
Copy link
Contributor

fehguy commented May 20, 2016

Description

When generating a library with an allOf construct in a model definition, the codegen seems to have problems if the first array item is an inline object vs. a model reference

Swagger-codegen version

2.1.6

Command line used for generation

Occurs on java with this trace:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'XXXX'
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:244)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.ClassCastException: io.swagger.models.ModelImpl cannot be cast to io.swagger.models.RefModel
    at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:955)
    at io.swagger.codegen.languages.JavaClientCodegen.fromModel(JavaClientCodegen.java:541)
    at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:799)
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:237)
@alecha
Copy link

alecha commented Jun 14, 2016

same issue here, did you solve?

@wing328
Copy link
Contributor

wing328 commented Jun 14, 2016

As a workaround, you can convert the inline object to reference model or put the reference model first.

@florintene
Copy link

Hi,
Experiencing the same issue with Java, however in this case it just ignores the inline definition of the "allOf" and creates the model with "Object":

Model:

{
    "type": "object",
    "properties": {
        "relatedX": {
            "type": "string",
            "description": "some testing description"
        },
        "airplaneSpec": {
            "type":"object",
            "allOf": [
                {
                    "$ref": "./BasicDefinition.json#/properties/baseComponentType"
                },
                {
                    "type": "object",                 
                    "properties": {
                        "EngineModelCode": {
                            "type": "string",
                            "description": "Engine Model - factory code"
                        }
                    }
                }
            ]
        }
    }
}

Code:

@JsonProperty("airplaneSpec")
  private Object airplaneSpec = null; 

However, if instead of the inline definition of the "allOf" a $ref is used, it generates the code correctly.

Model:

{
    "type": "object",
    "properties": {
        "relatedX": {
            "type": "string",
            "description": "some testing description"
        },
        "airplaneSpec": {
           "$ref":"./test1.json"
        }
    }
}

Code:

  @JsonProperty("airplaneSpec")
  private Test1 airplaneSpec = null;

And the Test1 java file is being generated.

Command line used for generation:
java -jar swagger-codegen-cli-2.3.0-20170822.110351-101.jar generate -i test.swagger -l spring -o Output -Dmodels

I could find two other related issues being raised #3225 and #6148.
If I missed anything in the above test let me know and happy to retest.
I didn't want to create a new issue as I think these 3 issues can be related but if required i can open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants