-
Notifications
You must be signed in to change notification settings - Fork 6k
How to code generate nested array property using swagger-code-gen client #989
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
Comments
@vijayrcse would be nice if you can share the full swagger spec definition with us (assuming it can be shared publicly) and also I wonder if you can do a test with the latest |
wing328 This was the original .json file {"apiVersion": "1.0", "swaggerVersion": "1.2", "basePath": "/", "resourcePath": "/service-v1", "produces": ["application/json"], "consumes": ["application/json"], "apis": [
{
"path": "/service-v1/evaluate",
"operations": [
{
"method": "POST",
"summary": "Summary",
"notes": "notes",
"type": "Response",
"nickname": "evaluate",
"produces": ["application/json"],
"parameters": [
{
"name": "body",
"description": "Request description",
"required": true,
"type": "array",
"items": {
"$ref": "Request"
},
"paramType": "body",
"allowMultiple": false
}
],
"responseMessages": [
{
"code": 200,
"message": "Successful evaluation",
"responseModel": "Response"
},
{
"code": 404,
"message": "service does not exist"
},
{
"code": 500,
"message": "Internal service error"
}
]
}
]
}
], "models": {
"Attribute": {
"id": "Attribute",
"description": "Attribute representation",
"properties": {
"id": {
"type": "integer",
"format": "int32",
"description": "Id"
},
"attributeId": {
"type": "integer",
"format": "int32",
"description": "Attribute Id"
},
"attributeName": {
"type": "string",
"description": "Attribute Name"
},
"attributeValue": {
"type": "string",
"description": "Attribute Value"
},
"attributeValueCode": {
"type": "string",
"description": "Attribute Value Code"
}
}
},
"Response": {
"id": "Response",
"description": "response representation",
"required": ["id", "exceptionType", "chains"],
"properties": {
"requestId": {
"type": "string",
"description": "Unique ID for mapping input and output"
},
"id": {
"type": "integer",
"format": "int32",
"description": "ID"
},
"exceptionType": {
"type": "string",
"description": "Exception Type description"
},
"exceptionDetail": {
"type": "string",
"description": "Exception Details description"
},
"chains": {
"$ref": "List[List[Descriptor]]",
"description": "Ordered collection of Descriptor"
}
}
},
"Request": {
"id": "Request",
"description": "request representation",
"required": ["id"],
"properties": {
"requestId": {
"type": "string",
"description": "Unique ID for mapping input and output"
},
"id": {
"type": "integer",
"format": "int32",
"description": "ID"
},
"allAttribute": {
"type": "array",
"description": "Attributes",
"items": {
"$ref": "Attribute"
}
}
}
}
}} This doesn't complie while i try to generate code using swaggercode gen cli - 2.1.2. I noticed that List Of List of decriptor is not generated properly( So i edited to below {"apiVersion": "1.0", "swaggerVersion": "1.2", "basePath": "/", "resourcePath": "/service-v1", "produces": ["application/json"], "consumes": ["application/json"], "apis": [
{
"path": "/service-v1/evaluate",
"operations": [
{
"method": "POST",
"summary": "Summary",
"notes": "notes",
"type": "Response",
"nickname": "evaluate",
"produces": ["application/json"],
"parameters": [
{
"name": "body",
"description": "Request description",
"required": true,
"type": "array",
"items": {
"$ref": "Request"
},
"paramType": "body",
"allowMultiple": false
}
],
"responseMessages": [
{
"code": 200,
"message": "Successful evaluation",
"responseModel": "Response"
},
{
"code": 404,
"message": "service does not exist"
},
{
"code": 500,
"message": "Internal service error"
}
]
}
]
}
], "models": {
"Attribute": {
"id": "Attribute",
"description": "Attribute representation",
"properties": {
"id": {
"type": "integer",
"format": "int32",
"description": "Id"
},
"attributeId": {
"type": "integer",
"format": "int32",
"description": "Attribute Id"
},
"attributeName": {
"type": "string",
"description": "Attribute Name"
},
"attributeValue": {
"type": "string",
"description": "Attribute Value"
},
"attributeValueCode": {
"type": "string",
"description": "Attribute Value Code"
}
}
},
"Descriptor": {
"id": "class_id",
"description": "Description for Descriptor",
"properties": {
"propertyName1": {
"type": "string",
"description": "Property Name 1"
},
"propertyName2": {
"type": "string",
"description": "Property Name 1"
}
}
},
"Response": {
"id": "Response",
"description": "response representation",
"required": ["id", "exceptionType", "chains"],
"properties": {
"requestId": {
"type": "string",
"description": "Unique ID for mapping input and output"
},
"id": {
"type": "integer",
"format": "int32",
"description": "ID"
},
"exceptionType": {
"type": "string",
"description": "Exception Type description"
},
"exceptionDetail": {
"type": "string",
"description": "Exception Details description"
},
"chains": {
"type": "array",
"description": "description 1",
"items": {
"type": "array",
"description": "description 2",
"items": {
"$ref": "Descriptor"
}
}
}
}
},
"Request": {
"id": "Request",
"description": "request representation",
"required": ["id"],
"properties": {
"requestId": {
"type": "string",
"description": "Unique ID for mapping input and output"
},
"id": {
"type": "integer",
"format": "int32",
"description": "ID"
},
"allAttribute": {
"type": "array",
"description": "Attributes",
"items": {
"$ref": "Attribute"
}
}
}
}
}} Now i get the below exception
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
at java.util.regex.Matcher.reset(Matcher.java:309)
at java.util.regex.Matcher.<init>(Matcher.java:229)
at java.util.regex.Pattern.matcher(Pattern.java:1093)
at io.swagger.codegen.DefaultCodegen.camelize(DefaultCodegen.java:1237)
at io.swagger.codegen.DefaultCodegen.camelize(DefaultCodegen.java:1212)
at io.swagger.codegen.languages.JavaClientCodegen.toModelName(JavaClientCodegen.java:179)
at io.swagger.codegen.languages.JavaClientCodegen.getSwaggerType(JavaClientCodegen.java:215)
at io.swagger.codegen.DefaultCodegen.getTypeDeclaration(DefaultCodegen.java:490)
at io.swagger.codegen.languages.JavaClientCodegen.getTypeDeclaration(JavaClientCodegen.java:200)
at io.swagger.codegen.languages.JavaClientCodegen.getTypeDeclaration(JavaClientCodegen.java:193)
at io.swagger.codegen.languages.JavaClientCodegen.getTypeDeclaration(JavaClientCodegen.java:193)
at io.swagger.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:606)
at io.swagger.codegen.DefaultCodegen.addVars(DefaultCodegen.java:1191)
at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:540)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:451 is this becoz of swagger spec 1.2 being used to generate .json file ? I am using swagger code gen 2.1.2 at client side but service is owned by different team where they provide .json file to us. Please help how to proceed . |
Swagger spec 1.2 does not support nested array. Would you consider converting the spec to the latest Swagger spec 2.0, which supports nested array ? |
Yes. I am following this to move to swagger spec 2.0 please let me know if this is correct |
I have converted to 2.0 spec but i am getting below code generated at client side which doesn't compile private List<List<Descriptor>> chains = new ArrayList<List>() ; how should we get past this issue ? generated json snippet "chains": {
"type": "array",
"description": "Ordered descriptor chains",
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/Descriptor"
}
}
} |
This is simply not supported in codegen right now. Is there another way you can describe the data other than |
if this is not supported the only option is change the response not to contain List<List<Descriptor>> if spec 2.0 supports nested array , would like to know why code gen is not supporting that other option for us to change as follows List<DescriptorList>
class DescriptorList
{
List<Descriptor> descriptor;
} but this is going to change more things at service side |
Hi @vijayrcse, were you using the latest code from the develop_2.0 branch when you tried it? private List<List<Descriptor>> chains = new ArrayList<List<Descriptor>>(); |
could you please tell me what is the certified version that needs to be used ? I am using the below version
|
|
I cannot build using develop_2.0 branch. It is prohibited and i can only use a certified maven release. |
If that's the case, I'm afraid you've to wait for the next major release (no date has been set). Maybe you can ask for an exception ? |
nope not possible. is it possible if you can give something like 2.1.3 ? |
@vijayrcse 2.1.3 released: https://github.com/swagger-api/swagger-codegen/releases please give it a try. |
closing this as there's no further update. |
I have a property which is List<List>
I tried to add the below in my .json file( using swaggercode gen cli - 2.1.2 )
"listOfListOfClassA": {
"type": "array",
"description": "description 1",
"items": {
"type": "array",
"description": "description 2",
"items": {
"$ref": "ClassA"
}
}
}
"ClassA": {
"id": "class_id",
"description": "Description for class A",
"properties": {
"propertyName1": {
"type": "string",
"description": "Property Name 1"
},
"propertyName2": {
"type": "string",
"description": "Property Name 1"
},
}
},
But I am getting the below exception
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
at java.util.regex.Matcher.reset(Matcher.java:309)
at java.util.regex.Matcher.(Matcher.java:229)
at java.util.regex.Pattern.matcher(Pattern.java:1093)
at io.swagger.codegen.DefaultCodegen.camelize(DefaultCodegen.java:1237)
at io.swagger.codegen.DefaultCodegen.camelize(DefaultCodegen.java:1212)
at io.swagger.codegen.languages.JavaClientCodegen.toModelName(JavaClientCodegen.java:179)
at io.swagger.codegen.languages.JavaClientCodegen.getSwaggerType(JavaClientCodegen.java:215)
at io.swagger.codegen.DefaultCodegen.getTypeDeclaration(DefaultCodegen.java:490)
Could you please advise ?
The text was updated successfully, but these errors were encountered: