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

Java codegen - generates class name Collection<Model>.java #514

Closed
rajeshkamal5050 opened this issue Mar 18, 2015 · 4 comments
Closed

Java codegen - generates class name Collection<Model>.java #514

rajeshkamal5050 opened this issue Mar 18, 2015 · 4 comments

Comments

@rajeshkamal5050
Copy link

Using the swagger springmvc to generate the swagger spec from a Spring REST impementation.
The Spring REST controller class returns a Collection Ex:

@ApiOperation(value = "List all contacts")
@RequestMapping(value = "/contacts", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
public Collection<Contact> list() {
    return contactService.list();
}

Running the swagger codegen onto the generated swagger spec 1.2(because of swagger springmvc currently only supports 1.2).

Then, changed the Collection<> to List<> and the problem was gone. Just wanted to see if this is a bug.

Lets say if the Spring REST implementation that we have remains the same and we currently use codegen with 1.2 spec. If in future when, swagger springmvc starts producing swagger 2.0 spec. Will the generated code for the model classes and the API/service classes be backward compatible.

@fehguy
Copy link
Contributor

fehguy commented Mar 18, 2015

Are you using 2.1.x-M1? That should support the 1.2 swagger specifications. It is possible, however, that your API is not creating valid JSON. Can you share the JSON output?

@rajeshkamal5050
Copy link
Author

Yes, I am using 2.1.2-M1 - java -jar swagger-codegen-distribution-2.1.2-M1.jar -l java -i http://localhost:8080/api-docs/default/bundle-controller

  1. The generated 1.2 Swagger Spec(using swagger springmvc) contains these models which are not correct.

"Collection«Bundle»": {
"description": "",
"id": "Collection«Bundle»",
"properties": {
"empty": {
"required": false,
"type": "boolean"
}
}
},
"Void": {
"description": "",
"id": "Void",
"properties": {}
}

  1. The generated JSON OUTPUT is a valid one,

[
{
"name":"REST-Demo-Bundle",
"id":"d26c4979-a7eb-48e0-be0d-a68918261c8b",
"description":"REST-Demo-Bundle-Desc",
"fileNames":[
"file1",
"file2"
],
"version":"1.0.1",
}
]

  1. The code generation logs,

java -jar swagger-codegen-distribution-2.1.2-M1.jar -l java -i http://localhost:8080/api-docs/default/bundle-controller
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
reading from http://localhost:8080/api-docs/default/bundle-controller
reading from http://localhost:8080/api-docs/default/bundle-controller
writing file generated-code/java/src/main/java/io\swagger\client\model\BundleElement.java
writing file generated-code/java/src/main/java/io\swagger\client\model\Bundle.java
writing file generated-code/java/src/main/java/io\swagger\client\model\Void.java
writing file generated-code/java/src/main/java/io\swagger\client\model\Collection«Bundle».java
writing file generated-code/java/src/main/java/io\swagger\client\api\BundleApi.java
writing file generated-code/java\pom.xml
writing file generated-code/java\src/main/java\io\swagger\client\ApiInvoker.java
writing file generated-code/java\src/main/java\io\swagger\client\JsonUtil.java
writing file generated-code/java\src/main/java\io\swagger\client\ApiException.java

@rajeshkamal5050
Copy link
Author

@dilipkrish do you think this is an issue with the swagger-springmvc ?

@rajeshkamal5050
Copy link
Author

Closing this since I had created a bug on @springdox - springfox/springfox#620

@fehguy fehguy closed this as completed Apr 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants