Skip to content

Commit

Permalink
Merge pull request swagger-api#2722 from swagger-api/example-tests
Browse files Browse the repository at this point in the history
examples test and improved @content support
  • Loading branch information
frantuma authored Mar 22, 2018
2 parents b7c2faf + 878b20a commit 960e0dc
Show file tree
Hide file tree
Showing 17 changed files with 840 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The OpenAPI Specification has undergone several revisions since initial creation

Swagger core Version | Release Date | OpenAPI Spec compatibility | Notes | Status
------------------------- | ------------ | -------------------------- | ----- | ----
2.0.0 | 2018-03-20 | 3.0 | [tag v2.0.0](https://github.com/swagger-api/swagger-core/tree/v2.0.0) | Supported
2.0.0 | 2018-03-23 | 3.0 | [tag v2.0.0](https://github.com/swagger-api/swagger-core/tree/v2.0.0) | Supported
2.0.0-rc4 | 2018-01-22 | 3.0 | [tag v2.0.0-rc4](https://github.com/swagger-api/swagger-core/tree/v2.0.0-rc4) | Supported
2.0.0-rc3 | 2017-11-21 | 3.0 | [tag v2.0.0-rc3](https://github.com/swagger-api/swagger-core/tree/v2.0.0-rc3) | Supported
2.0.0-rc2 | 2017-09-29 | 3.0 | [tag v2.0.0-rc2](https://github.com/swagger-api/swagger-core/tree/v2.0.0-rc2) | Supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,7 @@ public static Optional<Content> getContent(io.swagger.v3.oas.annotations.media.C
if (StringUtils.isNotBlank(annotationContent.mediaType())) {
content.addMediaType(annotationContent.mediaType(), mediaType);
} else {
if (mediaType.getSchema() != null) {
applyTypes(classTypes, methodTypes, content, mediaType);
}
applyTypes(classTypes, methodTypes, content, mediaType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,18 @@ protected void processRequestBody(Parameter requestBodyParameter, Operation oper
if (requestBodyParameter.getSchema() != null) {
for (MediaType mediaType : requestBody.getContent().values()) {
if (mediaType.getSchema() == null) {
mediaType.setSchema(new Schema());
if (requestBodyParameter.getSchema() == null) {
mediaType.setSchema(new Schema());
} else {
mediaType.setSchema(requestBodyParameter.getSchema());
}
}
if (StringUtils.isBlank(mediaType.getSchema().getType())) {
mediaType.getSchema().setType(requestBodyParameter.getSchema().getType());
}
}
}
}
//requestBody.setExtensions(extensions);
operation.setRequestBody(requestBody);
}
} else {
Expand Down Expand Up @@ -953,9 +956,16 @@ private Operation parseMethod(
);
}
if (operation.getResponses().getDefault() != null &&
StringUtils.isBlank(operation.getResponses().getDefault().get$ref()) &&
operation.getResponses().getDefault().getContent() == null) {
operation.getResponses().getDefault().content(content);
StringUtils.isBlank(operation.getResponses().getDefault().get$ref())) {
if (operation.getResponses().getDefault().getContent() == null) {
operation.getResponses().getDefault().content(content);
} else {
for (String key : operation.getResponses().getDefault().getContent().keySet()) {
if (operation.getResponses().getDefault().getContent().get(key).getSchema() == null) {
operation.getResponses().getDefault().getContent().get(key).setSchema(returnTypeSchema);
}
}
}
}
Map<String, Schema> schemaMap = resolvedSchema.referencedSchemas;
if (schemaMap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.testng.Assert.fail;

public abstract class AbstractAnnotationTest {
public String readIntoYaml(final Class<?> cls) {
Reader reader = new Reader(new OpenAPI());
Expand All @@ -28,6 +30,17 @@ public String readIntoYaml(final Class<?> cls) {
}
}

public void compareToYamlFile(final Class<?> cls, String source){

final String file = source + cls.getSimpleName() + ".yaml";
try {
compareAsYaml(cls, getOpenAPIAsString(file));
} catch (IOException e) {
e.printStackTrace();
fail();
}
}

public void compareAsYaml(final Class<?> cls, final String yaml) throws IOException {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(cls);
Expand Down
Loading

0 comments on commit 960e0dc

Please sign in to comment.