Skip to content

Commit 19f7529

Browse files
authored
Merge pull request #1823 from devdevx/issues-1777-1802
Extend resolve fully and solve issues #1777 and #1802
2 parents c0c434b + ec8f4e9 commit 19f7529

File tree

5 files changed

+238
-0
lines changed

5 files changed

+238
-0
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java

+84
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,24 @@ public Schema resolveSchema(Schema schema) {
416416
combinedModel.setXml(schema.getXml());
417417
}
418418

419+
if (schema.getDescription() != null) {
420+
combinedModel.setDescription(schema.getDescription());
421+
}
422+
423+
if (schema.getExtensions() != null) {
424+
Map<String, Object> extensions = schema.getExtensions();
425+
for (String key : extensions.keySet()) {
426+
combinedModel.addExtension(key, extensions.get(key));
427+
}
428+
}
429+
430+
if (schema.getProperties() != null) {
431+
if (combinedModel.getProperties() == null) {
432+
combinedModel.setProperties(new HashMap<>());
433+
}
434+
combinedModel.getProperties().putAll(schema.getProperties());
435+
}
436+
419437
result = combinedModel;
420438

421439
} else {
@@ -546,6 +564,72 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
546564
targetSchema.addExtension(key, sourceSchema.getExtensions().get(key));
547565
}
548566
}
567+
if (resolved.getMaximum() != null) {
568+
targetSchema.setMaximum(resolved.getMaximum());
569+
}
570+
if (resolved.getExclusiveMaximum() != null) {
571+
targetSchema.setExclusiveMaximum(resolved.getExclusiveMaximum());
572+
}
573+
if (resolved.getMinimum() != null) {
574+
targetSchema.setMinimum(resolved.getMinimum());
575+
}
576+
if (resolved.getExclusiveMinimum() != null) {
577+
targetSchema.setExclusiveMinimum(resolved.getExclusiveMinimum());
578+
}
579+
if (resolved.getMaxLength() != null) {
580+
targetSchema.setMaxLength(resolved.getMaxLength());
581+
}
582+
if (resolved.getMinLength() != null) {
583+
targetSchema.setMinLength(resolved.getMinLength());
584+
}
585+
if (resolved.getPattern() != null) {
586+
targetSchema.setPattern(resolved.getPattern());
587+
}
588+
if (resolved.getMaxItems() != null) {
589+
targetSchema.setMaxItems(resolved.getMaxItems());
590+
}
591+
if (resolved.getMinItems() != null) {
592+
targetSchema.setMinItems(resolved.getMinItems());
593+
}
594+
if (resolved.getUniqueItems() != null) {
595+
targetSchema.setUniqueItems(resolved.getUniqueItems());
596+
}
597+
if (resolved.getMaxProperties() != null) {
598+
targetSchema.setMaxProperties(resolved.getMaxProperties());
599+
}
600+
if (resolved.getMinProperties() != null) {
601+
targetSchema.setMinProperties(resolved.getMinProperties());
602+
}
603+
if (resolved.getType() != null) {
604+
targetSchema.setType(resolved.getType());
605+
}
606+
if (resolved.getDescription() != null) {
607+
targetSchema.setDescription(resolved.getDescription());
608+
}
609+
if (resolved.getFormat() != null) {
610+
targetSchema.setFormat(resolved.getFormat());
611+
}
612+
if (resolved.getNullable() != null) {
613+
targetSchema.setNullable(resolved.getNullable());
614+
}
615+
if (resolved.getReadOnly() != null) {
616+
targetSchema.setReadOnly(resolved.getReadOnly());
617+
}
618+
if (resolved.getWriteOnly() != null) {
619+
targetSchema.setWriteOnly(resolved.getWriteOnly());
620+
}
621+
if (resolved.getExclusiveMaximumValue() != null) {
622+
targetSchema.setExclusiveMaximumValue(resolved.getExclusiveMaximumValue());
623+
}
624+
if (resolved.getExclusiveMinimumValue() != null) {
625+
targetSchema.setExclusiveMinimumValue(resolved.getExclusiveMinimumValue());
626+
}
627+
if (resolved.getMaxContains() != null) {
628+
targetSchema.setMaxContains(resolved.getMaxContains());
629+
}
630+
if (resolved.getMinContains() != null) {
631+
targetSchema.setMinContains(resolved.getMinContains());
632+
}
549633
}
550634

551635
if (requiredProperties.size() > 0) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ public class OpenAPIV3ParserTest {
8686
protected int serverPort = getDynamicPort();
8787
protected WireMockServer wireMockServer;
8888

89+
@Test
90+
public void testIssue1777() {
91+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
92+
ParseOptions options = new ParseOptions();
93+
options.setResolveFully(true);
94+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1777/issue1777.yaml", null, options);
95+
OpenAPI openAPI = parseResult.getOpenAPI();
96+
Schema id = ((Schema)openAPI.getComponents().getSchemas().get("customer").getProperties().get("id"));
97+
assertEquals(id.getType(), "string");
98+
assertEquals(id.getFormat(), "uuid");
99+
assertEquals(id.getDescription(), "The id of the customer");
100+
assertNotNull(id.getExtensions().get("x-apigen-mapping"));
101+
assertEquals(id.getMinLength(), (Integer) 36);
102+
assertEquals(id.getMaxLength(), (Integer) 36);
103+
assertNotNull(id.getPattern());
104+
}
105+
106+
@Test
107+
public void testIssue1802() {
108+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
109+
ParseOptions options = new ParseOptions();
110+
options.setResolveFully(true);
111+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1802/issue1802.yaml", null, options);
112+
OpenAPI openAPI = parseResult.getOpenAPI();
113+
Map<String, Schema> props = openAPI.getComponents().getSchemas().get("standard_response_res_one").getProperties();
114+
assertNotNull(props.get("data"));
115+
assertNotNull(props.get("result"));
116+
}
117+
89118
@Test
90119
public void testIssue1780() {
91120
ParseOptions options = new ParseOptions();

modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ paths:
1515
schema:
1616
required:
1717
- data
18+
type: object
1819
properties:
1920
data:
2021
type: string
@@ -32,6 +33,7 @@ paths:
3233
schema:
3334
required:
3435
- data
36+
type: object
3537
properties:
3638
data:
3739
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: API-Template
4+
description: |
5+
Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/)
6+
version: v1
7+
8+
tags:
9+
- name: Customers
10+
description: "Operations and resources related to customers"
11+
12+
paths:
13+
/customers/{customerId}:
14+
parameters:
15+
- $ref: '#/components/parameters/customerIdPathParam'
16+
get:
17+
summary: Retrieve customer information
18+
description: Description for operation that allows retrieve customer information
19+
operationId: retrieveCustomerInfo
20+
tags:
21+
- Customers
22+
responses:
23+
'200':
24+
description: Customer response
25+
content:
26+
application/json:
27+
schema:
28+
$ref: '#/components/schemas/customer'
29+
30+
components:
31+
parameters:
32+
customerIdPathParam:
33+
name: customerId
34+
in: path
35+
required: true
36+
description: The id of the customer
37+
schema:
38+
$ref: '#/components/schemas/uuid'
39+
40+
schemas:
41+
uuid:
42+
type: string
43+
format: uuid
44+
minLength: 36
45+
maxLength: 36
46+
pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
47+
48+
customer:
49+
type: object
50+
properties:
51+
id:
52+
description: The id of the customer
53+
allOf:
54+
- $ref: '#/components/schemas/uuid'
55+
x-apigen-mapping:
56+
field: id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: 0001_allOffProps
5+
6+
paths:
7+
/sample_resource:
8+
post:
9+
operationId: createResOne
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
$ref: "#/components/schemas/create_res_one"
15+
responses:
16+
'201':
17+
description: Ok
18+
content:
19+
application/json:
20+
schema:
21+
$ref: "#/components/schemas/standard_response_res_one"
22+
components:
23+
schemas:
24+
standard_response_result:
25+
properties:
26+
result:
27+
type: object
28+
properties:
29+
status:
30+
type: boolean
31+
http_code:
32+
type: integer
33+
errors:
34+
type: array
35+
items:
36+
$ref: '#/components/schemas/standard_error'
37+
info:
38+
type: string
39+
trace_id:
40+
type: string
41+
num_elements:
42+
type: integer
43+
required:
44+
- status
45+
- http_code
46+
- trace_id
47+
standard_error:
48+
type: object
49+
properties:
50+
code:
51+
type: integer
52+
message:
53+
type: string
54+
standard_response_res_one:
55+
type: object
56+
allOf:
57+
- $ref: '#/components/schemas/standard_response_result'
58+
properties:
59+
data:
60+
properties:
61+
name:
62+
type: string
63+
create_res_one:
64+
type: object
65+
properties:
66+
name:
67+
type: string

0 commit comments

Comments
 (0)