Skip to content

Commit

Permalink
Add nullable property support from OAS 3.0 spec
Browse files Browse the repository at this point in the history
When I wrote this, I missed the changes on CodegenParameter and I had
some unnecessary changes on CodegenModel. I realized my mistake when I
went to add a similar change to openapi-generator and saw it was already
there, and they knew more about what to do than I did.

So, this is based in part on work by @wing328 and @jmini
- OpenAPITools/openapi-generator#873
- OpenAPITools/openapi-generator#889
- OpenAPITools/openapi-generator#930
  • Loading branch information
cognifloyd committed Oct 13, 2018
1 parent 2807c71 commit 1c5d60e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CodegenParameter extends CodegenObject {
public List<String> _enum;
public Map<String, Object> allowableValues;
public CodegenProperty items;
public boolean nullable;

/**
* Determines whether this parameter is mandatory. If the parameter is in "path",
Expand Down Expand Up @@ -106,6 +107,7 @@ public CodegenParameter copy() {
output.description = this.description;
output.unescapedDescription = this.unescapedDescription;
output.baseType = this.baseType;
output.nullable = this.nullable;
output.required = this.required;
output.maximum = this.maximum;
output.exclusiveMaximum = this.exclusiveMaximum;
Expand Down Expand Up @@ -186,6 +188,8 @@ public boolean equals(Object o) {
return false;
if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null)
return false;
if (nullable != that.nullable)
return false;
if (required != that.required)
return false;
if (maximum != null ? !maximum.equals(that.maximum) : that.maximum != null)
Expand Down Expand Up @@ -232,6 +236,7 @@ public int hashCode() {
result = 31 * result + (allowableValues != null ? allowableValues.hashCode() : 0);
result = 31 * result + (items != null ? items.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
result = 31 * result + (nullable ? 13:31);
result = 31 * result + (required ? 13:31);
result = 31 * result + (maximum != null ? maximum.hashCode() : 0);
result = 31 * result + (exclusiveMaximum ? 13:31);
Expand Down Expand Up @@ -323,6 +328,10 @@ public CodegenProperty getItems() {
return items;
}

public boolean getNullable() {
return nullable;
}

public boolean getRequired() {
return required;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CodegenProperty extends CodegenObject implements Cloneable {
public boolean exclusiveMinimum;
public boolean exclusiveMaximum;
public boolean required, secondaryParam;
public boolean nullable;

public List<String> _enum;
public Map<String, Object> allowableValues;
Expand Down Expand Up @@ -279,6 +280,14 @@ public void setSecondaryParam(boolean secondaryParam) {
this.secondaryParam = secondaryParam;
}

public boolean getNullable() {
return nullable;
}

public void setNullable(boolean nullable) {
this.nullable = nullable;
}

public List<String> get_enum() {
return _enum;
}
Expand Down Expand Up @@ -403,6 +412,7 @@ public int hashCode()
result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
result = prime * result + ((required ? 13:31));
result = prime * result + ((secondaryParam ? 13:31));
result = prime * result + ((nullable ? 13:31));
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode());
result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode());
Expand Down Expand Up @@ -503,6 +513,9 @@ public boolean equals(Object obj) {
if (this.secondaryParam != other.secondaryParam) {
return false;
}
if (this.nullable != other.nullable) {
return false;
}
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
return false;
}
Expand Down

0 comments on commit 1c5d60e

Please sign in to comment.