Skip to content

Commit

Permalink
fixing getResponse and getPaths from Swagger #719
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina committed Jun 10, 2018
1 parent 6d6d46e commit 291cfd8
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,7 @@ public class ReaderTest {
@Mock
private Swagger swagger;
@Mock
private Map<String, Path> paths;
private Paths paths;
@Mock
private Path path;
@Mock
Expand Down
80 changes: 80 additions & 0 deletions modules/swagger-models/src/main/java/io/swagger/models/Paths.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.swagger.models;


import java.util.LinkedHashMap;
import java.util.Objects;

public class Paths extends LinkedHashMap<String, Path> {
public Paths() {
}

private java.util.Map<String, Object> 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<String, Object> 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<String, Object> extensions) {
this.vendorExtensions = extensions;
}

public Paths vendorExtensions(java.util.Map<String, Object> 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 ");
}

}

102 changes: 102 additions & 0 deletions modules/swagger-models/src/main/java/io/swagger/models/Responses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.swagger.models;


import java.util.LinkedHashMap;
import java.util.Objects;

public class Responses extends LinkedHashMap<String, Response> {

public static final String DEFAULT = "default";

private java.util.Map<String, Object> 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<String, Object> 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<String, Object> extensions) {
this.vendorExtensions = extensions;
}

public Responses vendorExtensions(java.util.Map<String, Object> 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 ");
}

}
20 changes: 10 additions & 10 deletions modules/swagger-models/src/main/java/io/swagger/models/Swagger.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class Swagger {
protected List<String> consumes;
protected List<String> produces;
protected List<SecurityRequirement> security;
protected Map<String, Path> paths;
protected Paths paths;
protected Map<String, SecuritySchemeDefinition> securityDefinitions;
protected Map<String, Model> definitions;
protected Map<String, Parameter> parameters;
protected Map<String, Response> responses;
protected Responses responses;
protected ExternalDocs externalDocs;
protected Map<String, Object> vendorExtensions;

Expand Down Expand Up @@ -90,27 +90,27 @@ public Swagger produces(String produces) {
return this;
}

public Swagger paths(Map<String, Path> 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<String, Path>();
this.paths = new Paths();
}
this.paths.put(key, path);
return this;
}

public Swagger responses(Map<String, Response> 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<String, Response>();
this.responses = new Responses();
}
this.responses.put(key, response);
return this;
Expand Down Expand Up @@ -262,11 +262,11 @@ public void addProduces(String produces) {
}
}

public Map<String, Path> getPaths() {
public Paths getPaths() {
return paths;
}

public void setPaths(Map<String, Path> paths) {
public void setPaths(Paths paths) {
this.paths = paths;
}

Expand Down Expand Up @@ -371,11 +371,11 @@ public void addParameter(String key, Parameter parameter) {
this.parameters.put(key, parameter);
}

public Map<String, Response> getResponses() {
public Responses getResponses() {
return responses;
}

public void setResponses(Map<String, Response> responses) {
public void setResponses(Responses responses) {
this.responses = responses;
}

Expand Down
16 changes: 14 additions & 2 deletions modules/swagger-models/src/test/java/io/swagger/PojosTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -113,13 +118,20 @@ public void testEqualsAndHashcodes() throws InstantiationException, IllegalAcces
public void testBuildersAndCommonMethods() throws Exception {
Map<Class<?>, Set<String>> classesExclusions = new HashMap<Class<?>, Set<String>>();

ArrayList<Class<?>> excludeMock = new ArrayList<>();
excludeMock.add(Responses.class);
excludeMock.add(Paths.class);
classesExclusions.put(Operation.class, new HashSet<String>(Arrays.asList("deprecated", "vendorExtensions")));
classesExclusions.put(Swagger.class, new HashSet<String>(Arrays.asList("vendorExtensions")));

for (PojoClass clazz : pojoClasses) {
Set<String> 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);

}
}
}
}

0 comments on commit 291cfd8

Please sign in to comment.