Skip to content

Commit

Permalink
Merge pull request #1823 from devdevx/issues-1777-1802
Browse files Browse the repository at this point in the history
Extend resolve fully and solve issues #1777 and #1802
  • Loading branch information
gracekarina authored Dec 19, 2022
2 parents c0c434b + ec8f4e9 commit 19f7529
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Schema> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ paths:
schema:
required:
- data
type: object
properties:
data:
type: string
Expand All @@ -32,6 +33,7 @@ paths:
schema:
required:
- data
type: object
properties:
data:
type: string
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 19f7529

Please sign in to comment.