diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java index e4f325052e..d2aec84e16 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java @@ -416,6 +416,24 @@ public Schema resolveSchema(Schema schema) { combinedModel.setXml(schema.getXml()); } + if (schema.getDescription() != null) { + combinedModel.setDescription(schema.getDescription()); + } + + if (schema.getExtensions() != null) { + Map extensions = schema.getExtensions(); + for (String key : extensions.keySet()) { + combinedModel.addExtension(key, extensions.get(key)); + } + } + + if (schema.getProperties() != null) { + if (combinedModel.getProperties() == null) { + combinedModel.setProperties(new HashMap<>()); + } + combinedModel.getProperties().putAll(schema.getProperties()); + } + result = combinedModel; } else { @@ -546,6 +564,72 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ targetSchema.addExtension(key, sourceSchema.getExtensions().get(key)); } } + if (resolved.getMaximum() != null) { + targetSchema.setMaximum(resolved.getMaximum()); + } + if (resolved.getExclusiveMaximum() != null) { + targetSchema.setExclusiveMaximum(resolved.getExclusiveMaximum()); + } + if (resolved.getMinimum() != null) { + targetSchema.setMinimum(resolved.getMinimum()); + } + if (resolved.getExclusiveMinimum() != null) { + targetSchema.setExclusiveMinimum(resolved.getExclusiveMinimum()); + } + if (resolved.getMaxLength() != null) { + targetSchema.setMaxLength(resolved.getMaxLength()); + } + if (resolved.getMinLength() != null) { + targetSchema.setMinLength(resolved.getMinLength()); + } + if (resolved.getPattern() != null) { + targetSchema.setPattern(resolved.getPattern()); + } + if (resolved.getMaxItems() != null) { + targetSchema.setMaxItems(resolved.getMaxItems()); + } + if (resolved.getMinItems() != null) { + targetSchema.setMinItems(resolved.getMinItems()); + } + if (resolved.getUniqueItems() != null) { + targetSchema.setUniqueItems(resolved.getUniqueItems()); + } + if (resolved.getMaxProperties() != null) { + targetSchema.setMaxProperties(resolved.getMaxProperties()); + } + if (resolved.getMinProperties() != null) { + targetSchema.setMinProperties(resolved.getMinProperties()); + } + if (resolved.getType() != null) { + targetSchema.setType(resolved.getType()); + } + if (resolved.getDescription() != null) { + targetSchema.setDescription(resolved.getDescription()); + } + if (resolved.getFormat() != null) { + targetSchema.setFormat(resolved.getFormat()); + } + if (resolved.getNullable() != null) { + targetSchema.setNullable(resolved.getNullable()); + } + if (resolved.getReadOnly() != null) { + targetSchema.setReadOnly(resolved.getReadOnly()); + } + if (resolved.getWriteOnly() != null) { + targetSchema.setWriteOnly(resolved.getWriteOnly()); + } + if (resolved.getExclusiveMaximumValue() != null) { + targetSchema.setExclusiveMaximumValue(resolved.getExclusiveMaximumValue()); + } + if (resolved.getExclusiveMinimumValue() != null) { + targetSchema.setExclusiveMinimumValue(resolved.getExclusiveMinimumValue()); + } + if (resolved.getMaxContains() != null) { + targetSchema.setMaxContains(resolved.getMaxContains()); + } + if (resolved.getMinContains() != null) { + targetSchema.setMinContains(resolved.getMinContains()); + } } if (requiredProperties.size() > 0) { diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index 82029bd98a..5bb8fc8182 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -86,6 +86,35 @@ public class OpenAPIV3ParserTest { protected int serverPort = getDynamicPort(); protected WireMockServer wireMockServer; + @Test + public void testIssue1777() { + OpenAPIV3Parser openApiParser = new OpenAPIV3Parser(); + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult parseResult = openApiParser.readLocation("issue-1777/issue1777.yaml", null, options); + OpenAPI openAPI = parseResult.getOpenAPI(); + Schema id = ((Schema)openAPI.getComponents().getSchemas().get("customer").getProperties().get("id")); + assertEquals(id.getType(), "string"); + assertEquals(id.getFormat(), "uuid"); + assertEquals(id.getDescription(), "The id of the customer"); + assertNotNull(id.getExtensions().get("x-apigen-mapping")); + assertEquals(id.getMinLength(), (Integer) 36); + assertEquals(id.getMaxLength(), (Integer) 36); + assertNotNull(id.getPattern()); + } + + @Test + public void testIssue1802() { + OpenAPIV3Parser openApiParser = new OpenAPIV3Parser(); + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult parseResult = openApiParser.readLocation("issue-1802/issue1802.yaml", null, options); + OpenAPI openAPI = parseResult.getOpenAPI(); + Map props = openAPI.getComponents().getSchemas().get("standard_response_res_one").getProperties(); + assertNotNull(props.get("data")); + assertNotNull(props.get("result")); + } + @Test public void testIssue1780() { ParseOptions options = new ParseOptions(); diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml index e65304e351..b434030cc4 100644 --- a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml +++ b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml @@ -15,6 +15,7 @@ paths: schema: required: - data + type: object properties: data: type: string @@ -32,6 +33,7 @@ paths: schema: required: - data + type: object properties: data: type: string diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1777/issue1777.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1777/issue1777.yaml new file mode 100644 index 0000000000..344f933cb8 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-1777/issue1777.yaml @@ -0,0 +1,56 @@ +openapi: "3.0.0" +info: + title: API-Template + description: | + Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/) + version: v1 + +tags: + - name: Customers + description: "Operations and resources related to customers" + +paths: + /customers/{customerId}: + parameters: + - $ref: '#/components/parameters/customerIdPathParam' + get: + summary: Retrieve customer information + description: Description for operation that allows retrieve customer information + operationId: retrieveCustomerInfo + tags: + - Customers + responses: + '200': + description: Customer response + content: + application/json: + schema: + $ref: '#/components/schemas/customer' + +components: + parameters: + customerIdPathParam: + name: customerId + in: path + required: true + description: The id of the customer + schema: + $ref: '#/components/schemas/uuid' + + schemas: + uuid: + type: string + format: uuid + minLength: 36 + maxLength: 36 + pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' + + customer: + type: object + properties: + id: + description: The id of the customer + allOf: + - $ref: '#/components/schemas/uuid' + x-apigen-mapping: + field: id \ No newline at end of file diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1802/issue1802.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1802/issue1802.yaml new file mode 100644 index 0000000000..22c57a2fd5 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-1802/issue1802.yaml @@ -0,0 +1,67 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: 0001_allOffProps + +paths: + /sample_resource: + post: + operationId: createResOne + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/create_res_one" + responses: + '201': + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/standard_response_res_one" +components: + schemas: + standard_response_result: + properties: + result: + type: object + properties: + status: + type: boolean + http_code: + type: integer + errors: + type: array + items: + $ref: '#/components/schemas/standard_error' + info: + type: string + trace_id: + type: string + num_elements: + type: integer + required: + - status + - http_code + - trace_id + standard_error: + type: object + properties: + code: + type: integer + message: + type: string + standard_response_res_one: + type: object + allOf: + - $ref: '#/components/schemas/standard_response_result' + properties: + data: + properties: + name: + type: string + create_res_one: + type: object + properties: + name: + type: string \ No newline at end of file