-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Description
Description
We are using an API defining a Boolean-like-element build upon an enum containing boolean values true and false. The element is defined as follows:
Boolean:
type: boolean
description: True or False indicator
enum:
- true
- falseIn general, true and false are interpreted as the boolean values true and false. However, the code-generated generates the following code fragment:
public enum ModelBoolean {
TRUE("true"),
FALSE("false");
private Boolean value;
ModelBoolean(Boolean value) {
this.value = value;
}
@JsonValue
public Boolean getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static ModelBoolean fromValue(String text) {
for (ModelBoolean b : ModelBoolean.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
}Here, true and false are interpreted as string values, whereas the constructor of ModelBoolean requests a Boolean value. In short, this is not a valid Java code.
Note: A similar result appears when using JavaScript as the target language.
Swagger-codegen version
Version 2.4.17 (swagger-codegen-maven-plugin) or SwaggerHub
Swagger declaration file content or url
swagger: '2.0'
info:
description: Demo
version: 1.0.0
title: Demo for Boolean-element Bug
schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
/users:
get:
summary: Returns a list of users.
description: Optional extended description in Markdown.
produces:
- application/json
responses:
200:
description: OK
definitions:
Boolean:
type: boolean
description: True or False indicator
enum:
- true
- falseCommand line used for generation
Steps to reproduce
- Use swagger codegen (for example SwaggerHub) to generate Java code.
Related issues/PRs
Suggest a fix/enhancement
Metadata
Metadata
Assignees
Labels
No labels