-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[BUG][JAVA] Client generator ignores 'nullable' property #4530
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
Comments
I will post it here, as it is somehow related (I think). I can see that support for
For example, in pet model package org.openapitools.model;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import org.openapitools.model.Category;
import org.openapitools.model.Tag;
import org.openapitools.jackson.nullable.JsonNullable;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* A pet for sale in the pet store
*/
@ApiModel(description = "A pet for sale in the pet store")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2020-06-01T12:00:04.904781+02:00[Europe/Warsaw]")
public class Pet {
@JsonProperty("id")
private Long id;
@JsonProperty("category")
private Category category;
@JsonProperty("name")
private String name;
@JsonProperty("photoUrls")
@Valid
private List<String> photoUrls = new ArrayList<>();
@JsonProperty("tags")
@Valid
private List<Tag> tags = null;
/**
* pet status in the store
*/
public enum StatusEnum {
AVAILABLE("available"),
PENDING("pending"),
SOLD("sold");
private String value;
StatusEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static StatusEnum fromValue(String value) {
for (StatusEnum b : StatusEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}
@JsonProperty("status")
private StatusEnum status;
public Pet id(Long id) {
this.id = id;
return this;
}
/**
* Get id
* @return id
*/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Pet category(Category category) {
this.category = category;
return this;
}
/**
* Get category
* @return category
*/
@ApiModelProperty(value = "")
@Valid
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public Pet name(String name) {
this.name = name;
return this;
}
/**
* Get name
* @return name
*/
@ApiModelProperty(example = "doggie", required = true, value = "")
@NotNull
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Pet photoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
}
public Pet addPhotoUrlsItem(String photoUrlsItem) {
this.photoUrls.add(photoUrlsItem);
return this;
}
/**
* Get photoUrls
* @return photoUrls
*/
@ApiModelProperty(required = true, value = "")
@NotNull
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
public Pet tags(List<Tag> tags) {
this.tags = tags;
return this;
}
public Pet addTagsItem(Tag tagsItem) {
if (this.tags == null) {
this.tags = new ArrayList<>();
}
this.tags.add(tagsItem);
return this;
}
/**
* Get tags
* @return tags
*/
@ApiModelProperty(value = "")
@Valid
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public Pet status(StatusEnum status) {
this.status = status;
return this;
}
/**
* pet status in the store
* @return status
*/
@ApiModelProperty(value = "pet status in the store")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
// rest ommited
} |
I can confirm that. |
I also ran into this behaviour today. At the moment it seems the only option is to use |
The semantics posted by @kkosmrli are what I would expect too. This issue is also impacting us and requires manual post-processing of the generated files. It would be nice to get a fix for this. Thank you! |
I can see the same issue with python aiohttp generator |
We see the same behaviour in the Java generator.
We'd as well be happy, if this could be addressed :) |
Uh oh!
There was an error while loading. Please reload this page.
Description
Client generator ignores 'nullable' property of the object schema. Instead, javax.annotation.Nullable generation seems to be based on 'required' property. This behaviour is incorrect - required fields have to be provided, but not necessarily non-null, i.e
{ "field" : null }
satisfies the 'required'.Nullable is part of OpenAPI 3.0 spec. To make it more robust, x-nullable could be handled, too.
OpenAPI declaration file content or url
Related issues/PRs
#3264
The text was updated successfully, but these errors were encountered: