swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.39k stars 2.19k forks source link

Support JSON-B @JsonbProperty in generated documentation #2789

Open ghost opened 6 years ago

ghost commented 6 years ago
Q A
Bug or feature request? feature request
Which Swagger-Core version? 2.0.0
Which Java version? Java 8
Which JAX-RS framework & version? 2.0

The JSON-B annotation javax.json.bind.annotation.JsonbProperty can be used to set a different property name for a JSON property much like the jackson annotation com.fasterxml.jackson.annotation.JsonProperty can.

@javax.json.bind.annotation.JsonbProperty(value = "_name1")
private String name1;

@com.fasterxml.jackson.annotation.JsonProperty (value = "_name2")
private String name2;

When using the jackson annotation the name is automatically used in the generated swagger documentation.

The generated documentation should also reflect the property name set with the JSON-B annotation.

idefixcert commented 6 years ago

Is there a workaround for that, I also have the same problem.

anachronoxLF commented 6 years ago

Hi, i faced the same problem. Simple, but very ugly workaround is to add @Schema annotation e.g.

public static final String JSON_ATTRIBUTE_ID = "_id";
...
@Schema(name = JSON_ATTRIBUTE_ID)
@JsonbProperty(JSON_ATTRIBUTE_ID)
private Long id;

Other solution I found was to use Jackson annotations instead of JSON-B annotations. The JAX-RS implementation I work with (RESTEasy in Wildfly) can use Jackson annotations for JSON serialization/deserialization out-of-the-box (without any configuration needed). But I try to be not dependent on specific implementations of EE 8 API technologies, therefore I use the solution with @Schema

bcluap commented 5 years ago

+1 for Swagger to read @JsonbProperty

rallampalli commented 3 years ago

I am using swagger plugin to generate classes from api spec (yaml) file. The generated model classes contains Jackson annotations. I would like to have JSON-B annotations instead of Jackson annotations. How this can be achieved?

l-ray commented 3 years ago

+1 for Swagger to read @JsonbProperty