swagger-api / swagger-api/swagger-codegen
[API JAVA] Define elements in json in uppercase
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
We have the following definition:
@XmlRootElement(name ="Beanbody")
@XmlAccessorType(XmlAccessType.FIELD)
public class Beanbody {
@XmlElement(name = "Mensaje")
private String mensaje;
We need a json definition with "mensaje" atribute in Uppercase: "Mensaje" in the example section.
How could I get it?
@JsonProperty doesn't work.
The request is needed with uppercase, but not the example.
In fact, the response is return with lowercase when is defined with uppercase, which doesn't make sense.
Swagger-codegen version
<swagger.version>1.5.10</swagger.version>
Swagger declaration file content or url
Command line used for generation
Soruce code:
private Swagger scan(Class<?> interfaceClass, String interfaceName, String vipaPropertyValue,
String externalServiceNameOnCall, String externalServiceVersion) throws MalformedURLException {
URL vipaUrl = new URL(vipaPropertyValue);
String host = vipaUrl.getHost();
String port = String.valueOf(vipaUrl.getPort());
Swagger swagger = new Swagger();
swagger.tag(new Tag().name(interfaceName).description("Escaner de la interfaz " + interfaceName));
BeanConfig scanner = new BeanConfig();
scanner.setResourcePackage(interfaceClass.getPackage().toString());
scanner.setHost(host + ":" + port);
String[] schemes = new String[] { vipaUrl.getProtocol() };
scanner.setSchemes(schemes);
scanner.setTitle(interfaceName);
scanner.setVersion(externalServiceVersion);
if (externalServiceVersion.equals("NA")) {
scanner.setBasePath(externalServiceNameOnCall + "/" + interfaceName);
} else {
scanner.setBasePath(externalServiceNameOnCall + "/v" + externalServiceVersion + "/" + interfaceName);
}
scanner.setScan(true);
logger.debug("using scanner " + scanner);
SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
Reader reader = new Reader(swagger, defaultReaderConfig);
swagger = reader.read(interfaceClass);
if (scanner instanceof SwaggerConfig) {
swagger = ((SwaggerConfig) scanner).configure(swagger);
}
return swagger;
}
protected String createSwaggerDefinition(String vipaPropertyValue, String swaggerFormat,
String interfaceName, String externalServiceNameOnCall, String externalServiceVersion, Class<?> interfaceClass) {
String response = null;
Swagger swagger = null;
try {
swagger = scan(interfaceClass, interfaceName, vipaPropertyValue, externalServiceNameOnCall, externalServiceVersion);
} catch (MalformedURLException e) {
response = "La propiedad de la url.vipa no contiene una url valida.[" + vipaPropertyValue + "]";
logger.error(response);
}
try {
if (SWAGGER_YAML.equals(swaggerFormat)) {
response = Yaml.mapper().writeValueAsString(swagger);
} else {
// por defecto siempre devolvemos json
response = Json.mapper().writeValueAsString(swagger);
}
} catch (JsonProcessingException e) {
response = "Error al generar el mensaje en json o yaml";
logger.error(response);
}
return response;
}
Steps to reproduce
Main:
Class<?> interfaceClass = es.rest.service.swagger.RestSwaggerService.class;
String result = swaggerDefinition.createSwaggerDefinition(vipaPropertyValue, swaggerFormat,
interfaceName, nameOnCall, eSVersion, interfaceClass);
Related issues/PRs
N/A
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied scan and createSwaggerDefinition entry points, then inspect how Json.mapper serializes the Swagger model for the provided Beanbody definition. Run the supplied reproduction and compare the generated request, response, and example property names; done means the requested uppercase behavior is represented consistently without changing the example unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100