Skip to content

Commit

Permalink
fix #3094 - avoid duplicate fields in schema classes
Browse files Browse the repository at this point in the history
Why:
The various Schema subclasses (ArraySchema, BinarySchema, etc.) are
defined such that they actually duplicate some of the fields from
the Schema super class (e.g. type, format, default, etc.).  This
can create confusion when examining instances of these classes within
a debugger as you will see two "type" fields for example, the base class'
"type" field will be set to null and the subclass' "type" field will be set
to "array" (or "binary", or "boolean", etc.).   We have similar issues with
the format and default fields.

What:
In this PR, I've fixed this by adding a protected ctor to Schema, and default ctors to
the subclasses, plus I've removed some getters/setters from the subclasses
that are no longer needed.
  • Loading branch information
padamstx committed Feb 1, 2019
1 parent cab9b4e commit 3e4eb12
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 824 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ samples/scala-play2/logs
atlassian-ide-plugin.xml
*.iml
.java-version
sonar-project.properties
sonar-project.properties
test-output/
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@
* ArraySchema
*/

public class ArraySchema extends Schema {
private String type = "array";
private Schema items = null;
public class ArraySchema extends Schema<Object> {
private Schema<?> items = null;

/**
* returns the type property from a ArraySchema instance.
*
* @return String type
**/

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
public ArraySchema() {
super("array", null);
}

public ArraySchema type(String type) {
this.type = type;
super.setType(type);
return this;
}

Expand All @@ -51,15 +40,15 @@ public ArraySchema type(String type) {
* @return Schema items
**/

public Schema getItems() {
public Schema<?> getItems() {
return items;
}

public void setItems(Schema items) {
public void setItems(Schema<?> items) {
this.items = items;
}

public ArraySchema items(Schema items) {
public ArraySchema items(Schema<?> items) {
this.items = items;
return this;
}
Expand All @@ -73,37 +62,23 @@ public boolean equals(java.lang.Object o) {
return false;
}
ArraySchema arraySchema = (ArraySchema) o;
return Objects.equals(this.type, arraySchema.type) &&
Objects.equals(this.items, arraySchema.items) &&
return Objects.equals(this.items, arraySchema.items) &&
super.equals(o);
}

@Override
public int hashCode() {
return Objects.hash(type, items, super.hashCode());
return Objects.hash(items, super.hashCode());
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ArraySchema {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" items: ").append(toIndentedString(items)).append("\n");
sb.append(" _default: ").append(toIndentedString(_default)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.swagger.v3.oas.models.media;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand All @@ -25,44 +24,18 @@
*/

public class BinarySchema extends Schema<byte[]> {
private String type = "string";
private String format = "binary";

/**
* returns the type property from a BinarySchema instance.
*
* @return String type
**/

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
public BinarySchema() {
super("string", "binary");
}

public BinarySchema type(String type) {
this.type = type;
super.setType(type);
return this;
}

/**
* returns the format property from a BinarySchema instance.
*
* @return String format
**/

public String getFormat() {
return format;
}

public void setFormat(String format) {
this.format = format;
}

public BinarySchema format(String format) {
this.format = format;
super.setFormat(format);;
return this;
}

Expand All @@ -85,15 +58,12 @@ protected byte[] cast(Object value) {
}

public BinarySchema _enum(List<byte[]> _enum) {
this._enum = _enum;
super.setEnum(_enum);
return this;
}

public BinarySchema addEnumItem(byte[] _enumItem) {
if (this._enum == null) {
this._enum = new ArrayList<byte[]>();
}
this._enum.add(_enumItem);
super.addEnumItemObject(_enumItem);
return this;
}

Expand All @@ -105,42 +75,21 @@ public boolean equals(java.lang.Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
BinarySchema binarySchema = (BinarySchema) o;
return Objects.equals(this.type, binarySchema.type) &&
Objects.equals(this.format, binarySchema.format) &&
Objects.equals(this._default, binarySchema._default) &&
Objects.equals(this._enum, binarySchema._enum) &&
super.equals(o);
return super.equals(o);
}

@Override
public int hashCode() {
return Objects.hash(type, format, _default, _enum, super.hashCode());
return Objects.hash(_default, _enum, super.hashCode());
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class BinarySchema {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" format: ").append(toIndentedString(format)).append("\n");
sb.append(" _default: ").append(toIndentedString(_default)).append("\n");
sb.append(" _enum: ").append(toIndentedString(_enum)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,14 @@
* BooleanSchema
*/

public class BooleanSchema extends Schema {
private String type = "boolean";
public class BooleanSchema extends Schema<Boolean> {

/**
* returns the type property from a BooleanSchema instance.
*
* @return String type
**/

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
public BooleanSchema() {
super("boolean", null);
}

public BooleanSchema type(String type) {
this.type = type;
super.setType(type);
return this;
}

Expand Down Expand Up @@ -83,40 +72,21 @@ public boolean equals(java.lang.Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
BooleanSchema booleanSchema = (BooleanSchema) o;
return Objects.equals(this.type, booleanSchema.type) &&
Objects.equals(this._default, booleanSchema._default) &&
Objects.equals(this._enum, booleanSchema._enum) &&
super.equals(o);
return super.equals(o);
}

@Override
public int hashCode() {
return Objects.hash(type, _default, _enum, super.hashCode());
return Objects.hash(super.hashCode());
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class BooleanSchema {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" _default: ").append(toIndentedString(_default)).append("\n");
sb.append(" _enum: ").append(toIndentedString(_enum)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Loading

0 comments on commit 3e4eb12

Please sign in to comment.