diff --git a/modules/swagger-jaxrs/src/test/java/io/swagger/jaxrs/ReaderTest.java b/modules/swagger-jaxrs/src/test/java/io/swagger/jaxrs/ReaderTest.java index eaf2730ecd..f033a0d343 100644 --- a/modules/swagger-jaxrs/src/test/java/io/swagger/jaxrs/ReaderTest.java +++ b/modules/swagger-jaxrs/src/test/java/io/swagger/jaxrs/ReaderTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.when; import io.swagger.models.Operation; import io.swagger.models.Path; +import io.swagger.models.Paths; import io.swagger.models.Swagger; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -22,7 +23,7 @@ public class ReaderTest { @Mock private Swagger swagger; @Mock - private Map paths; + private Paths paths; @Mock private Path path; @Mock diff --git a/modules/swagger-models/src/main/java/io/swagger/models/Paths.java b/modules/swagger-models/src/main/java/io/swagger/models/Paths.java new file mode 100644 index 0000000000..a18c741739 --- /dev/null +++ b/modules/swagger-models/src/main/java/io/swagger/models/Paths.java @@ -0,0 +1,80 @@ +package io.swagger.models; + + +import java.util.LinkedHashMap; +import java.util.Objects; + +public class Paths extends LinkedHashMap { + public Paths() { + } + + private java.util.Map vendorExtensions = null; + + public Paths addPath(String name, Path item) { + this.put(name, item); + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Paths paths = (Paths) o; + return Objects.equals(this.vendorExtensions, paths.vendorExtensions) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(vendorExtensions, super.hashCode()); + } + + public java.util.Map getVendorExtensions() { + return vendorExtensions; + } + + public void addVendorExtension(String name, Object value) { + if (name == null || name.isEmpty() || !name.startsWith("x-")) { + return; + } + if (this.vendorExtensions == null) { + this.vendorExtensions = new java.util.HashMap<>(); + } + this.vendorExtensions.put(name, value); + } + + public void setVendorExtensions(java.util.Map extensions) { + this.vendorExtensions = extensions; + } + + public Paths vendorExtensions(java.util.Map extensions) { + this.vendorExtensions = extensions; + return this; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Paths {\n"); + sb.append(" ").append(toIndentedString(super.toString())).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 "); + } + +} + diff --git a/modules/swagger-models/src/main/java/io/swagger/models/Responses.java b/modules/swagger-models/src/main/java/io/swagger/models/Responses.java new file mode 100644 index 0000000000..30cac5523f --- /dev/null +++ b/modules/swagger-models/src/main/java/io/swagger/models/Responses.java @@ -0,0 +1,102 @@ +package io.swagger.models; + + +import java.util.LinkedHashMap; +import java.util.Objects; + +public class Responses extends LinkedHashMap { + + public static final String DEFAULT = "default"; + + private java.util.Map vendorExtensions = null; + + public Responses addResponse(String name, Response item) { + this.put(name, item); + return this; + } + + /** + * returns the default property from a ApiResponses instance. + * + * @return ApiResponse _default + **/ + + public Response getDefault() { + return this.get(DEFAULT); + } + + public void setDefault(Response _default) { + addResponse(DEFAULT, _default); + } + + public Responses _default(Response _default) { + setDefault(_default); + return this; + } + + public java.util.Map getVendorExtensions() { + return vendorExtensions; + } + + public void addVendorExtension(String name, Object value) { + if (name == null || name.isEmpty() || !name.startsWith("x-")) { + return; + } + if (this.vendorExtensions == null) { + this.vendorExtensions = new java.util.HashMap<>(); + } + this.vendorExtensions.put(name, value); + } + + public void setVendorExtensions(java.util.Map extensions) { + this.vendorExtensions = extensions; + } + + public Responses vendorExtensions(java.util.Map extensions) { + this.vendorExtensions = extensions; + return this; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + Responses apiResponses = (Responses) o; + return Objects.equals(this.vendorExtensions, apiResponses.vendorExtensions); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), vendorExtensions); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiResponses {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" vendorExtensions: ").append(toIndentedString(vendorExtensions)).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 "); + } + +} diff --git a/modules/swagger-models/src/main/java/io/swagger/models/Swagger.java b/modules/swagger-models/src/main/java/io/swagger/models/Swagger.java index 459c329908..28065dfcd7 100644 --- a/modules/swagger-models/src/main/java/io/swagger/models/Swagger.java +++ b/modules/swagger-models/src/main/java/io/swagger/models/Swagger.java @@ -21,11 +21,11 @@ public class Swagger { protected List consumes; protected List produces; protected List security; - protected Map paths; + protected Paths paths; protected Map securityDefinitions; protected Map definitions; protected Map parameters; - protected Map responses; + protected Responses responses; protected ExternalDocs externalDocs; protected Map vendorExtensions; @@ -90,27 +90,27 @@ public Swagger produces(String produces) { return this; } - public Swagger paths(Map paths) { + public Swagger paths(Paths paths) { this.setPaths(paths); return this; } public Swagger path(String key, Path path) { if (this.paths == null) { - this.paths = new LinkedHashMap(); + this.paths = new Paths(); } this.paths.put(key, path); return this; } - public Swagger responses(Map responses) { + public Swagger responses(Responses responses) { this.responses = responses; return this; } public Swagger response(String key, Response response) { if (this.responses == null) { - this.responses = new LinkedHashMap(); + this.responses = new Responses(); } this.responses.put(key, response); return this; @@ -262,11 +262,11 @@ public void addProduces(String produces) { } } - public Map getPaths() { + public Paths getPaths() { return paths; } - public void setPaths(Map paths) { + public void setPaths(Paths paths) { this.paths = paths; } @@ -371,11 +371,11 @@ public void addParameter(String key, Parameter parameter) { this.parameters.put(key, parameter); } - public Map getResponses() { + public Responses getResponses() { return responses; } - public void setResponses(Map responses) { + public void setResponses(Responses responses) { this.responses = responses; } diff --git a/modules/swagger-models/src/test/java/io/swagger/PojosTest.java b/modules/swagger-models/src/test/java/io/swagger/PojosTest.java index ba711628cc..b1c576afad 100644 --- a/modules/swagger-models/src/test/java/io/swagger/PojosTest.java +++ b/modules/swagger-models/src/test/java/io/swagger/PojosTest.java @@ -10,8 +10,12 @@ import io.swagger.models.ComposedModel; import io.swagger.models.ModelImpl; import io.swagger.models.Operation; + +import io.swagger.models.Paths; import io.swagger.models.RefModel; import io.swagger.models.RefResponse; + +import io.swagger.models.Responses; import io.swagger.models.Swagger; import io.swagger.models.auth.ApiKeyAuthDefinition; import io.swagger.models.auth.In; @@ -34,6 +38,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -113,13 +118,20 @@ public void testEqualsAndHashcodes() throws InstantiationException, IllegalAcces public void testBuildersAndCommonMethods() throws Exception { Map, Set> classesExclusions = new HashMap, Set>(); + ArrayList> excludeMock = new ArrayList<>(); + excludeMock.add(Responses.class); + excludeMock.add(Paths.class); classesExclusions.put(Operation.class, new HashSet(Arrays.asList("deprecated", "vendorExtensions"))); classesExclusions.put(Swagger.class, new HashSet(Arrays.asList("vendorExtensions"))); for (PojoClass clazz : pojoClasses) { Set exclusions = classesExclusions.get(clazz.getClazz()); - TestUtils.testBuilders(clazz.getClazz(), exclusions); - TestUtils.testCommonMethods(clazz.getClazz(), exclusions); + Class pojoClass = clazz.getClazz(); + if (!excludeMock.contains(pojoClass)) { + TestUtils.testBuilders(clazz.getClazz(), exclusions); + TestUtils.testCommonMethods(clazz.getClazz(), exclusions); + + } } } }