Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit ada75b6

Browse files
authored
Merge pull request swagger-api#1076 from swagger-api/issue-1039
fixed set types to schemas
2 parents 29a7ef6 + 3000c1c commit ada75b6

3 files changed

Lines changed: 166 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
22242224
}
22252225

22262226
value = getString("type",node,false,location,result);
2227-
if (StringUtils.isNotBlank(value)) {
2227+
if (StringUtils.isNotBlank(value) && StringUtils.isBlank(schema.getType())) {
22282228
schema.setType(value);
22292229
}else{
22302230
// may have an enum where type can be inferred

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ public class OpenAPIV3ParserTest {
6565
protected int serverPort = getDynamicPort();
6666
protected WireMockServer wireMockServer;
6767

68+
69+
@Test
70+
public void testIssue1039() {
71+
72+
ParseOptions options = new ParseOptions();
73+
options.setResolve(true);
74+
75+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue_1039.yaml", null, options);
76+
OpenAPI apispec = parseResult.getOpenAPI();
77+
assertNotNull(apispec);
78+
assertEquals(apispec.getPaths().get("/pets").getGet().getParameters().get(0).getSchema().getType(),"array");
79+
80+
}
81+
6882
@Test
6983
public void testIssue1015() {
7084

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
6+
termsOfService: http://swagger.io/terms/
7+
contact:
8+
name: Swagger API Team
9+
email: apiteam@swagger.io
10+
url: http://swagger.io
11+
license:
12+
name: Apache 2.0
13+
url: https://www.apache.org/licenses/LICENSE-2.0.html
14+
servers:
15+
- url: http://petstore.swagger.io/api
16+
paths:
17+
/pets:
18+
get:
19+
description: description
20+
operationId: findPets
21+
parameters:
22+
- name: tags
23+
in: query
24+
description: tags to filter by
25+
required: false
26+
style: form
27+
schema:
28+
type: number
29+
items:
30+
type: string
31+
- name: limit
32+
in: query
33+
description: maximum number of results to return
34+
required: false
35+
schema:
36+
type: integer
37+
format: int32
38+
responses:
39+
'200':
40+
description: pet response
41+
content:
42+
application/json:
43+
schema:
44+
type: array
45+
items:
46+
$ref: '#/components/schemas/Pet'
47+
default:
48+
description: unexpected error
49+
content:
50+
application/json:
51+
schema:
52+
$ref: '#/components/schemas/Error'
53+
post:
54+
description: Creates a new pet in the store. Duplicates are allowed
55+
operationId: addPet
56+
requestBody:
57+
description: Pet to add to the store
58+
required: true
59+
content:
60+
application/json:
61+
schema:
62+
$ref: '#/components/schemas/NewPet'
63+
responses:
64+
'200':
65+
description: pet response
66+
content:
67+
application/json:
68+
schema:
69+
$ref: '#/components/schemas/Pet'
70+
default:
71+
description: unexpected error
72+
content:
73+
application/json:
74+
schema:
75+
$ref: '#/components/schemas/Error'
76+
/pets/{id}:
77+
get:
78+
description: Returns a user based on a single ID, if the user does not have access to the pet
79+
operationId: find pet by id
80+
parameters:
81+
- name: id
82+
in: path
83+
description: ID of pet to fetch
84+
required: true
85+
schema:
86+
type: integer
87+
format: int64
88+
responses:
89+
'200':
90+
description: pet response
91+
content:
92+
application/json:
93+
schema:
94+
$ref: '#/components/schemas/Pet'
95+
default:
96+
description: unexpected error
97+
content:
98+
application/json:
99+
schema:
100+
$ref: '#/components/schemas/Error'
101+
delete:
102+
description: deletes a single pet based on the ID supplied
103+
operationId: deletePet
104+
parameters:
105+
- name: id
106+
in: path
107+
description: ID of pet to delete
108+
required: true
109+
schema:
110+
type: integer
111+
format: int64
112+
responses:
113+
'204':
114+
description: pet deleted
115+
default:
116+
description: unexpected error
117+
content:
118+
application/json:
119+
schema:
120+
$ref: '#/components/schemas/Error'
121+
components:
122+
schemas:
123+
Pet:
124+
allOf:
125+
- $ref: '#/components/schemas/NewPet'
126+
- required:
127+
- id
128+
properties:
129+
id:
130+
type: integer
131+
format: int64
132+
133+
NewPet:
134+
required:
135+
- name
136+
properties:
137+
name:
138+
type: string
139+
tag:
140+
type: string
141+
142+
Error:
143+
required:
144+
- code
145+
- message
146+
properties:
147+
code:
148+
type: integer
149+
format: int32
150+
message:
151+
type: string

0 commit comments

Comments
 (0)