Repository navigation
Closed
Description
Hi,
I am trying to generate static documentation for my API definition
java -XX:MaxPermSize=256M -Xmx1024M -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i swagger.json -l html -o target
using both master & develop_2.0 branch I have the following exception
java.lang.ClassCastException: io.swagger.models.RefModel cannot be cast to io.swagger.models.ModelImpl
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:532)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:452)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:125)
at io.swagger.codegen.cmd.Generate.run(Generate.java:124)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
I have isolated my issue. It comes from the definition of a model using allOf and 2 references to other models.
Here is a simplified json swagger api definition to reproduce:
{
"swagger": "2.0",
"info": {
"title": "My demo API",
"description": "My demo API documentation",
"version": "1.0.0"
},
"host": "myserver",
"schemes": [
"http"
],
"basePath": "/resources/v1",
"paths": {
"/clients/{clientId}": {
"get": {
"summary": "get info on a specific client",
"tags": [
"Clients"
],
"parameters": [
{
"in": "path",
"name": "clientId",
"type": "integer",
"required": true,
"format": "int64"
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "retrieve data of the corresponding client",
"schema": {
"$ref": "#/definitions/Client"
}
}
}
}
}
},
"definitions": {
"Client": {
"allOf": [
{
"$ref": "#/definitions/Person"
},
{
"$ref": "#/definitions/Address"
}
]
},
"Person": {
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
},
"Address": {
"required": [
"postalCode",
"city"
],
"properties": {
"street": {
"type": "string"
},
"postalCode": {
"type": "integer"
},
"city": {
"type": "string"
}
}
}
}
}Metadata
Metadata
Assignees
Labels
No labels
Activity
wing328 commentedon Jun 30, 2015
@McFoggy I'm able to repeat the issue. Based on some testing, seems like codegen is expecting the model to have "properties". If I update
Clientas follows, I could no longer repeat the issue:I wonder if you can try adding the same (a property) to see if the issue goes away.
This is not to say it's an acceptable workaround but to confirm codegen is expecting a model to have at least one property defined.
McFoggy commentedon Jun 30, 2015
I confirmed that your workaround worked when I added a dummy property at all places where I used 'only' allOf for composition.
wing328 commentedon Jun 30, 2015
@McFoggy Thanaks. I'll look into the issue and hopefully can find a fix tomorrow.