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 generation fails to generate proper constructors #7756

Open
jnovotny opened this issue Mar 3, 2018 · 2 comments
Open

java generation fails to generate proper constructors #7756

jnovotny opened this issue Mar 3, 2018 · 2 comments

Comments

@jnovotny
Copy link

jnovotny commented Mar 3, 2018

Description

I'm using the geojson swagger file
https://gist.github.com/bubbobne/fe5f2db65acf039be6a9fd92fc9c7233

to generate code for Point and Polygon. Overall it works fine, however it fails to generate the "type" which should be "point" for Point and "polygon" for Polygon.

Swagger-codegen version

swagger-codegen-maven-plugin 2.2.3

Swagger declaration file content or url

look at Polygon or Point in the geojson swagger above.

Command line used for generation

I use Maven

generate-geojson generate src/main/resources/geometry_geojson.yaml java java8 src/java/main
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

The hack is basically I add a constructor to the class like so:

public Point() {
setType(TypeEnum.POINT);
}

or for Polygon:

public Polygon() {
setType(TypeEnum.POLYGON);
}

@jmini
Copy link
Contributor

jmini commented Mar 3, 2018

From a swagger-spec point of view, it is not defined that the type of a #/definitions/Point should be TypeEnum.POINT and that the type of a #/definitions/Polygon will be TypeEnum.POLYGON.

This is something that can be figured out when you read the external doc page referenced in the swagger-spec:

For a use case like this, the possibility to define constant values in the Schema definitions is currently missing. This is a requested feature for the next version of the specification:
OAI/OpenAPI-Specification#1313 (maybe you could mention your use case, the geojson swagger file in this issue)

As pointed out in the discussion, without the possibility to have constant value in schema, it is not possible for a code generator to know that a fixed value needs to be set for a specific model class.

@jnovotny
Copy link
Author

jnovotny commented Mar 3, 2018

Thanks so much for your help and suggestion! Much appreciated :-)

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