diff --git a/modules/swagger-annotations/src/main/java/io/swagger/v3/oas/annotations/media/Schema.java b/modules/swagger-annotations/src/main/java/io/swagger/v3/oas/annotations/media/Schema.java index 244d3fe92c..6a09740fc9 100644 --- a/modules/swagger-annotations/src/main/java/io/swagger/v3/oas/annotations/media/Schema.java +++ b/modules/swagger-annotations/src/main/java/io/swagger/v3/oas/annotations/media/Schema.java @@ -23,7 +23,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.nio.file.AccessMode; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.TYPE; @@ -335,4 +334,14 @@ enum AccessMode { WRITE_ONLY, READ_WRITE; } + + /** + * Marker class to use on the {@link Schema} implementation field to set that a + * response has no content. + * + * @author Ariel Carrera + * + */ + public static class Empty { + } } diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java index 10ecfe84a1..9df03a14f8 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java @@ -13,6 +13,7 @@ import io.swagger.v3.oas.annotations.links.LinkParameter; import io.swagger.v3.oas.annotations.media.DiscriminatorMapping; import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema.Empty; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.ExternalDocumentation; import io.swagger.v3.oas.models.examples.Example; @@ -540,12 +541,17 @@ public static Optional getSchemaFromAnnotation(io.swagger.v3.oas.annotat } } - + if (schemaObject.isEmpty()) { + return Optional.of(schemaObject.noContent(true)); + } return Optional.of(schemaObject); } public static Schema resolveSchemaFromType(Class schemaImplementation, Components components, JsonView jsonViewAnnotation) { - Schema schemaObject; + if (Empty.class.equals(schemaImplementation)) { + return new Schema().noContent(true); + } + Schema schemaObject; PrimitiveType primitiveType = PrimitiveType.fromType(schemaImplementation); if (primitiveType != null) { schemaObject = primitiveType.createProperty(); @@ -1088,6 +1094,8 @@ public static Optional getSchema(io.swagger.v3.oas.annotations if (schemaImplementation != Void.class) { isArray = true; } + } else if (schemaImplementation == Empty.class) { + return Optional.of(new Schema<>().noContent(true)); } return getSchema(annotationContent.schema(), annotationContent.array(), isArray, schemaImplementation, components, jsonViewAnnotation); } diff --git a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java index a2996860f7..491da4f4c9 100644 --- a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java +++ b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java @@ -1089,6 +1089,38 @@ protected Operation parseMethod( } } } + operation.getResponses().forEach((k, value) -> { + if (value.getContent() == null) { // no content annotation -> DEFAULT CONTENT/SCHEMA + value.setContent(content); + } else if (!"default".equals(k)) { + Set contentsToRemove = new HashSet<>(); + value.getContent().forEach((mediaStr, mediaObj) -> { + if (mediaObj.isEmpty()) { // content annotation empty or only mediaType field defined -> DEFAULT CONTENT/SCHEMA + if (value.getContent().size() == 1) { + value.setContent(new Content().addMediaType(mediaStr, mediaType)); + } else { + mediaObj.setSchema(returnTypeSchema); + } + } else { + Schema schemaObj = mediaObj.getSchema(); + if (schemaObj == null || schemaObj.isEmpty()) { + mediaObj.setSchema(returnTypeSchema); + } else if (schemaObj.isNoContent()) { + mediaObj.setSchema(null); + if (mediaObj.isEmpty()) { + contentsToRemove.add(mediaStr); + } + } + } + }); + + contentsToRemove.stream().forEach(s -> value.getContent().remove(s)); + if (value.getContent().isEmpty()) { + value.setContent(null); + } + } + }); + Map schemaMap = resolvedSchema.referencedSchemas; if (schemaMap != null) { schemaMap.forEach((key, schema) -> components.addSchemas(key, schema)); @@ -1108,7 +1140,7 @@ protected Operation parseMethod( return operation; } - + private boolean shouldIgnoreClass(String className) { if (StringUtils.isBlank(className)) { return true; diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java index 65b33fa195..2792c4663b 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java @@ -39,6 +39,8 @@ import io.swagger.v3.jaxrs2.resources.RefSecurityResource; import io.swagger.v3.jaxrs2.resources.ResourceWithSubResource; import io.swagger.v3.jaxrs2.resources.ResponseContentWithArrayResource; +import io.swagger.v3.jaxrs2.resources.ResponseEmptySchemaResource; +import io.swagger.v3.jaxrs2.resources.ResponseEmptySchemaResource.ResponseEmptySchemaJsonResource; import io.swagger.v3.jaxrs2.resources.ResponsesResource; import io.swagger.v3.jaxrs2.resources.SecurityResource; import io.swagger.v3.jaxrs2.resources.ServersResource; @@ -522,6 +524,804 @@ public void testGetResponsesWithComposition() { SerializationMatchers.assertEqualsToYaml(openAPI, yaml); } + @Test(description = "Response with empty schema") + public void testGetResponseWithEmptySchema() { + Reader reader = new Reader(new OpenAPI()); + + OpenAPI openAPI = reader.read(ResponseEmptySchemaResource.class); + String yaml = "openapi: 3.0.1\n" + + "paths:\n" + + " /noContentResource/default:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: default\n" + + " responses:\n" + + " default:\n" + + " description: default response\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " /noContentResource/schema:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: schema\n" + + " responses:\n" + + " \"200\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " \"205\":\n" + + " description: Ok\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"210\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"211\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"212\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/multipleContents:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: multiContent\n" + + " responses:\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"205\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example2:\n" + + " description: example2\n" + + " value: test\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/arraySchema:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: array\n" + + " responses:\n" + + " \"200\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " \"205\":\n" + + " description: Ok\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"210\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"211\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"212\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"213\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"214\":\n" + + " description: Ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/allOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: allOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " allOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + " /noContentResource/anyOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: anyOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " anyOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + " /noContentResource/oneOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: oneOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " oneOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + "components:\n" + + " schemas:\n" + + " User:\n" + + " type: object\n" + + " properties:\n" + + " foo:\n" + + " type: string\n" + + " CustomUser:\n" + + " type: object\n" + + " properties:\n" + + " foo:\n" + + " type: string\n" + + " foo2:\n" + + " type: string"; + SerializationMatchers.assertEqualsToYaml(openAPI, yaml); + } + + @Test(description = "Response with empty schema (Json content type)") + public void testGetJsonResponseWithEmptySchema() { + Reader reader = new Reader(new OpenAPI()); + + OpenAPI openAPI = reader.read(ResponseEmptySchemaJsonResource.class); + String yaml = "openapi: 3.0.1\n" + + "paths:\n" + + " /noContentResource/default:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: default\n" + + " responses:\n" + + " default:\n" + + " description: default response\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " /noContentResource/schema:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: schema\n" + + " responses:\n" + + " \"200\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " \"205\":\n" + + " description: Ok\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"210\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"211\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"212\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/multipleContents:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: multiContent\n" + + " responses:\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"205\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example2:\n" + + " description: example2\n" + + " value: test\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/arraySchema:\n" + + " get:\n" + + " summary: Summary\n" + + " description: Desc\n" + + " operationId: array\n" + + " responses:\n" + + " \"200\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"201\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"202\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"203\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"204\":\n" + + " description: Ok\n" + + " \"205\":\n" + + " description: Ok\n" + + " \"206\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"207\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " \"208\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"209\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"210\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/CustomUser'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"211\":\n" + + " description: Ok\n" + + " content:\n" + + " application/xml:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"212\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " \"213\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " \"214\":\n" + + " description: Ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " type: array\n" + + " items:\n" + + " $ref: '#/components/schemas/User'\n" + + " examples:\n" + + " example1:\n" + + " description: example1\n" + + " value: test\n" + + " /noContentResource/allOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: allOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " allOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + " /noContentResource/anyOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: anyOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " anyOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + " /noContentResource/oneOf:\n" + + " get:\n" + + " summary: Summary\n" + + " operationId: oneOf\n" + + " responses:\n" + + " \"200\":\n" + + " description: ok\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " oneOf:\n" + + " - $ref: '#/components/schemas/User'\n" + + " - $ref: '#/components/schemas/CustomUser'\n" + + "components:\n" + + " schemas:\n" + + " User:\n" + + " type: object\n" + + " properties:\n" + + " foo:\n" + + " type: string\n" + + " CustomUser:\n" + + " type: object\n" + + " properties:\n" + + " foo:\n" + + " type: string\n" + + " foo2:\n" + + " type: string"; + SerializationMatchers.assertEqualsToYaml(openAPI, yaml); + } + @Test(description = "External Docs") public void testGetExternalDocs() { Reader reader = new Reader(new OpenAPI()); @@ -1883,24 +2683,28 @@ public void testCallbackWithRef() { Reader reader = new Reader(oas); OpenAPI openAPI = reader.read(RefCallbackResource.class); - String yaml = "openapi: 3.0.1\n" + - "info:\n" + - " description: info\n" + - "paths:\n" + - " /simplecallback:\n" + - " get:\n" + - " summary: Simple get operation\n" + - " operationId: getWithNoParameters\n" + - " responses:\n" + - " \"200\":\n" + - " description: voila!\n" + - " callbacks:\n" + - " testCallback1:\n" + - " $ref: '#/components/callbacks/Callback'\n" + - "components:\n" + - " callbacks:\n" + - " Callback:\n" + - " /post:\n" + + String yaml = "openapi: 3.0.1\n" + + "info:\n" + + " description: info\n" + + "paths:\n" + + " /simplecallback:\n" + + " get:\n" + + " summary: Simple get operation\n" + + " operationId: getWithNoParameters\n" + + " responses:\n" + + " \"200\":\n" + + " description: voila!\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + + " callbacks:\n" + + " testCallback1:\n" + + " $ref: '#/components/callbacks/Callback'\n" + + "components:\n" + + " callbacks:\n" + + " Callback:\n" + + " /post:\n" + " description: Post Path Item\n"; SerializationMatchers.assertEqualsToYaml(openAPI, yaml); } @@ -2688,13 +3492,29 @@ public void testTicket3149() { " $ref: '#/components/schemas/SampleDTO'\n" + " responses:\n" + " \"201\":\n" + - " description: Created\n" + + " description: Created\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"400\":\n" + " description: Bad Request\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"403\":\n" + " description: Forbidden\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"404\":\n" + " description: Not Found\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " /test/{id}:\n" + " get:\n" + " tags:\n" + @@ -2708,12 +3528,28 @@ public void testTicket3149() { " responses:\n" + " \"200\":\n" + " description: OK\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"400\":\n" + " description: Bad Request\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"403\":\n" + " description: Forbidden\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"404\":\n" + " description: Not Found\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " /test/original/{id}:\n" + " get:\n" + " tags:\n" + @@ -2727,12 +3563,28 @@ public void testTicket3149() { " responses:\n" + " \"200\":\n" + " description: OK\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"400\":\n" + " description: Bad Request\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"403\":\n" + " description: Forbidden\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + " \"404\":\n" + " description: Not Found\n" + + " content:\n" + + " '*/*':\n" + + " schema:\n" + + " type: string\n" + "components:\n" + " schemas:\n" + " SampleDTO:\n" + diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java index 6d9f4aede4..d4418db6ec 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java @@ -986,6 +986,13 @@ public void testSimpleUserResource() throws IOException { " responses:\n" + " \"200\":\n" + " description: aaa\n" + + " content:\n" + + " application/json:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + + " application/xml:\n" + + " schema:\n" + + " $ref: '#/components/schemas/User'\n" + "components:\n" + " schemas:\n" + " User:\n" + diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/petstore/responses/ComplexResponseResource.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/petstore/responses/ComplexResponseResource.java index ba876aca12..ef3f04f22f 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/petstore/responses/ComplexResponseResource.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/petstore/responses/ComplexResponseResource.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.media.Schema.Empty; import io.swagger.v3.oas.annotations.responses.ApiResponse; import javax.ws.rs.GET; @@ -27,7 +28,7 @@ public class ComplexResponseResource { @Schema(name = "Default Pet", description = "Default Pet", required = true, example = "New Pet"))) }) - @ApiResponse(responseCode = "404", description = "Couldn't find pet") + @ApiResponse(responseCode = "404", description = "Couldn't find pet", content = @Content(schema = @Schema(implementation = Empty.class))) public Pet getPets() throws NotFoundException { return new Pet(); } diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/ResponseEmptySchemaResource.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/ResponseEmptySchemaResource.java new file mode 100644 index 0000000000..5d752ec20f --- /dev/null +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/ResponseEmptySchemaResource.java @@ -0,0 +1,127 @@ +package io.swagger.v3.jaxrs2.resources; + +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.media.Schema.Empty; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +@Path("/noContentResource") +public class ResponseEmptySchemaResource { + + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public static class ResponseEmptySchemaJsonResource extends ResponseEmptySchemaResource { + } + + @GET + @Path("/default") + @Operation(summary = "Summary", description = "Desc", operationId = "default") + public User getDefault() { + return null; + } + + @GET + @Path("/schema") + @Operation(summary = "Summary", description = "Desc", operationId = "schema") + @ApiResponse(responseCode = "200", description = "Ok") // CLASS MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "201", description = "Ok", content = @Content()) // CLASS MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "202", description = "Ok", content = @Content(schema = @Schema())) // CLASS MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "203", description = "Ok", content = @Content(mediaType = "application/xml")) // XML MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "204", description = "Ok", content = @Content(schema = @Schema(implementation = Empty.class))) // NO CONTENT + @ApiResponse(responseCode = "205", description = "Ok", content = @Content(mediaType = "application/xml", schema = @Schema(implementation = Empty.class))) // NO CONTENT + @ApiResponse(responseCode = "206", description = "Ok", content = @Content(schema = @Schema(implementation = CustomUser.class))) // CLASS MEDIA TYPE (CUSTOM USER SCHEMA) + @ApiResponse(responseCode = "207", description = "Ok", content = @Content(mediaType = "application/xml", schema = @Schema(implementation = CustomUser.class))) // XML MEDIA TYPE (CUSTOM USER SCHEMA) + @ApiResponse(responseCode = "208", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"))) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT SCHEMA) + @ApiResponse(responseCode = "209", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema(implementation = Empty.class))) // CLASS MEDIA TYPE (EXAMPLE AND NO SCHEMA) + @ApiResponse(responseCode = "210", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema(implementation = CustomUser.class))) // CLASS MEDIA TYPE (EXAMPLE AND CUSTOM USER SCHEMA) + @ApiResponse(responseCode = "211", description = "Ok", content = @Content(mediaType = "application/xml", examples = @ExampleObject(name = "example1", value="test"))) // XML MEDIA TYPE (EXAMPLE AND DEFAULT SCHEMA) + @ApiResponse(responseCode = "212", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema())) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT SCHEMA) + public User getUser() { + return null; + } + + @GET + @Path("/arraySchema") + @Operation(summary = "Summary", description = "Desc", operationId = "array") + @ApiResponse(responseCode = "200", description = "Ok") // CLASS MEDIA TYPE (DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "201", description = "Ok", content = @Content()) // CLASS MEDIA TYPE (DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "202", description = "Ok", content = @Content(schema = @Schema())) // CLASS MEDIA TYPE (DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "203", description = "Ok", content = @Content(mediaType = "application/xml")) // XML MEDIA TYPE (DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "204", description = "Ok", content = @Content(schema = @Schema(implementation = Empty.class))) // NO CONTENT + @ApiResponse(responseCode = "205", description = "Ok", content = @Content(mediaType = "application/xml", schema = @Schema(implementation = Empty.class))) // NO CONTENT + @ApiResponse(responseCode = "206", description = "Ok", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CustomUser.class)))) // CLASS MEDIA TYPE (CUSTOM USER ARRAY SCHEMA) + @ApiResponse(responseCode = "207", description = "Ok", content = @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = CustomUser.class)))) // XML MEDIA TYPE (CUSTOM USER ARRAY SCHEMA) + @ApiResponse(responseCode = "208", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"))) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "209", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema(implementation = Empty.class))) // CLASS MEDIA TYPE (EXAMPLE AND NO SCHEMA) + @ApiResponse(responseCode = "210", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), array = @ArraySchema(schema = @Schema(implementation = CustomUser.class)))) // CLASS MEDIA TYPE (CUSTOM USER ARRAY SCHEMA AND EXAMPLE) + @ApiResponse(responseCode = "211", description = "Ok", content = @Content(mediaType = "application/xml", examples = @ExampleObject(name = "example1", value="test"))) // XML MEDIA TYPE (EXAMPLE AND DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "212", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema())) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "213", description = "Ok", content = @Content(array = @ArraySchema())) // CLASS MEDIA TYPE (DEFAULT ARRAY SCHEMA) + @ApiResponse(responseCode = "214", description = "Ok", content = @Content(examples = @ExampleObject(name = "example1", value="test"), array = @ArraySchema())) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT ARRAY SCHEMA) + public List getUsers() { + return null; + } + + @GET + @Path("/multipleContents") + @Operation(summary = "Summary", description = "Desc", operationId = "multiContent") + @ApiResponse(responseCode = "201", description = "Ok", content = { @Content(), @Content() }) // 1 CLASS MEDIA TYPE AND DEFAULT SCHEMA + @ApiResponse(responseCode = "202", description = "Ok", content = { @Content(schema = @Schema()), @Content(mediaType="application/xml", schema = @Schema()) }) // CLASS MEDIA TYPE (DEFAULT SCHEMA), XML MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "203", description = "Ok", content = { @Content(mediaType = "application/xml"), @Content(mediaType = "application/json") }) // TWO MEDIA TYPES (DEFAULT SCHEMA) + @ApiResponse(responseCode = "204", description = "Ok", content = { @Content(schema = @Schema(implementation = Empty.class)), @Content(mediaType = "application/xml") }) // ONE XML MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "205", description = "Ok", content = { @Content(mediaType = "application/json"), @Content(mediaType = "application/xml", schema = @Schema(implementation = Empty.class)) }) // ONE JSON MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "206", description = "Ok", content = { @Content(schema = @Schema(implementation = CustomUser.class)), @Content(mediaType = "application/xml", schema = @Schema(implementation = CustomUser.class))}) // CLASS MEDIA TYPE (CUSTOM USER SCHEMA), XML MEDIA TYPE (CUSTOM USER SCHEMA) + @ApiResponse(responseCode = "207", description = "Ok", content = { @Content(examples = @ExampleObject(name = "example1", value="test")), @Content(mediaType = "application/xml", examples = @ExampleObject(name = "example2", value="test"))}) // CLASS MEDIA TYPE (DEFAULT SCHEMA AND EXAMPLE), XML MEDIA TYPE (DEFAULT SCHEMA AND EXAMPLE), + @ApiResponse(responseCode = "208", description = "Ok", content = { @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema(implementation = Empty.class)), @Content(mediaType = "application/xml")}) // CLASS MEDIA TYPE (EXAMPLE AND NO CONTENT), XML MEDIA TYPE (DEFAULT SCHEMA) + @ApiResponse(responseCode = "209", description = "Ok", content = { @Content(examples = @ExampleObject(name = "example1", value="test"), schema = @Schema()), @Content(mediaType = "application/xml", examples = @ExampleObject(name = "example1", value="test"), schema = @Schema())}) // CLASS MEDIA TYPE (EXAMPLE AND DEFAULT SCHEMA), XML MEDIA TYPE (EXAMPLE AND DEFAULT SCHEMA) + public User getUserMultipleContent() { + return null; + } + + @Operation(summary = "Summary", responses = { + @ApiResponse(description = "ok", responseCode = "200", content = @Content(schema = @Schema(oneOf = { + User.class, CustomUser.class }))) }) + @GET + @Path("/oneOf") + public User oneOf() { + return null; + } + + @Operation(summary = "Summary", responses = { + @ApiResponse(description = "ok", responseCode = "200", content = @Content(schema = @Schema(anyOf = { + User.class, CustomUser.class }))) }) + @GET + @Path("/anyOf") + public User anyOf() { + return null; + } + + @Operation(summary = "Summary", responses = { + @ApiResponse(description = "ok", responseCode = "200", content = @Content(schema = @Schema(allOf = { + User.class, CustomUser.class }))) }) + @GET + @Path("/allOf") + public User allOf() { + return null; + } + + class User { + public String foo; + } + + class CustomUser extends User { + public String foo2; + } + +} diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/FullPetResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/FullPetResource.yaml index dae5c87847..02d06ef344 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/FullPetResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/FullPetResource.yaml @@ -226,6 +226,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: @@ -259,6 +263,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: @@ -282,6 +290,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback: http://$requests.query.url: {} @@ -307,6 +319,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: @@ -1200,6 +1216,10 @@ paths: responses: "400": description: test description + content: + '*/*': + schema: + $ref: '#/components/schemas/User' links: user: operationId: getUser @@ -1207,6 +1227,10 @@ paths: userId: $request.query.userId "200": description: 200 description + content: + '*/*': + schema: + $ref: '#/components/schemas/User' links: pet: operationId: getUser diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/ComplexCallbackResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/ComplexCallbackResource.yaml index d8a53bf360..43bc9d0ada 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/ComplexCallbackResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/ComplexCallbackResource.yaml @@ -13,6 +13,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/MultipleCallbacksTestWithOperationResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/MultipleCallbacksTestWithOperationResource.yaml index 6bdb5cd369..093ffbe081 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/MultipleCallbacksTestWithOperationResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/MultipleCallbacksTestWithOperationResource.yaml @@ -7,6 +7,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/RepeatableCallbackResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/RepeatableCallbackResource.yaml index bed776dee4..a88ad08e7d 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/RepeatableCallbackResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/RepeatableCallbackResource.yaml @@ -7,6 +7,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback: http://$requests.query.url: {} diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/SimpleCallbackWithOperationResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/SimpleCallbackWithOperationResource.yaml index 1a1be9ea79..51d2cb078d 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/SimpleCallbackWithOperationResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/callbacks/SimpleCallbackWithOperationResource.yaml @@ -7,6 +7,10 @@ paths: responses: "200": description: voila! + content: + '*/*': + schema: + type: string callbacks: testCallback1: http://www.url.com: diff --git a/modules/swagger-jaxrs2/src/test/resources/petstore/responses/NoImplementationResponseResource.yaml b/modules/swagger-jaxrs2/src/test/resources/petstore/responses/NoImplementationResponseResource.yaml index e0becf7ddc..f236741ca2 100644 --- a/modules/swagger-jaxrs2/src/test/resources/petstore/responses/NoImplementationResponseResource.yaml +++ b/modules/swagger-jaxrs2/src/test/resources/petstore/responses/NoImplementationResponseResource.yaml @@ -11,6 +11,10 @@ paths: responses: "400": description: test description + content: + '*/*': + schema: + $ref: '#/components/schemas/User' links: user: operationId: getUser @@ -18,6 +22,10 @@ paths: userId: $request.query.userId "200": description: 200 description + content: + '*/*': + schema: + $ref: '#/components/schemas/User' links: pet: operationId: getUser diff --git a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/ComposedSchema.java b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/ComposedSchema.java index 530a7700d3..798923288d 100644 --- a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/ComposedSchema.java +++ b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/ComposedSchema.java @@ -141,4 +141,13 @@ public String toString() { sb.append("}"); return sb.toString(); } + + @Override + public boolean isEmpty() { + return (allOf == null || allOf.isEmpty()) && + (anyOf == null || anyOf.isEmpty()) && + (oneOf == null || oneOf.isEmpty()) && + super.isEmpty(); + } + } diff --git a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/MediaType.java b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/MediaType.java index f3995bc23a..f5d4d9b117 100644 --- a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/MediaType.java +++ b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/MediaType.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnore; + /** * MediaType * @@ -195,5 +197,13 @@ private String toIndentedString(java.lang.Object o) { return o.toString().replace("\n", "\n "); } + @JsonIgnore + public boolean isEmpty() { + return (schema == null || schema.isEmpty()) && + examples == null && + example == null && + encoding == null && + extensions == null; + } } diff --git a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java index e3d9097578..7dbd54a354 100644 --- a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java +++ b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java @@ -72,6 +72,8 @@ public class Schema { private Discriminator discriminator = null; private boolean exampleSetFlag; + + private boolean noContentFlag = false; public Schema() { } @@ -894,5 +896,53 @@ protected String toIndentedString(java.lang.Object o) { return o.toString().replace("\n", "\n "); } + @JsonIgnore + public boolean isEmpty() { + return name == null && + title == null && + multipleOf == null && + maximum == null && + exclusiveMaximum == null && + minimum == null && + exclusiveMinimum == null && + maxLength == null && + minLength == null && + pattern == null && + maxItems == null && + minItems == null && + uniqueItems == null && + maxProperties == null && + minProperties == null && + required == null && + type == null && + not == null && + properties == null && + additionalProperties == null && + description == null && + format == null && + $ref == null && + nullable == null && + readOnly == null && + writeOnly == null && + example == null && + externalDocs == null && + deprecated == null && + xml == null && + extensions == null && + _enum == null && + discriminator == null && + exampleSetFlag == false && + noContentFlag == false; + } + + @JsonIgnore + public boolean isNoContent() { + return this.noContentFlag; + } + + public Schema noContent(boolean noContentFlag) { + this.noContentFlag = noContentFlag; + return this; + } }