Skip to content

Commit 4a73b9d

Browse files
authored
Revert "Issue 1228"
1 parent 137a209 commit 4a73b9d

File tree

6 files changed

+202
-65
lines changed

6 files changed

+202
-65
lines changed

modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,9 +1089,6 @@ public Parameter convert(io.swagger.models.parameters.Parameter v2Parameter) {
10891089
a.setUniqueItems(sp.isUniqueItems());
10901090
}
10911091

1092-
a.setMaximum(sp.getMaximum());
1093-
a.setMinimum(sp.getMinimum());
1094-
10951092
schema = a;
10961093
} else {
10971094
schema = SchemaTypeUtil.createSchema(sp.getType(), sp.getFormat());

modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ public class V2ConverterTest {
9494
private static final String ISSUE_1032_YAML = "issue-1032.yaml";
9595
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
9696
private static final String ISSUE_1164_YAML = "issue-1164.yaml";
97-
private static final String ISSUE_1228_YAML = "issue-1228.json";
98-
9997

10098
private static final String API_BATCH_PATH = "/api/batch/";
10199
private static final String PETS_PATH = "/pets";
@@ -842,15 +840,4 @@ private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException,
842840
assertNotNull(result);
843841
return result.getOpenAPI();
844842
}
845-
846-
@Test(description = "OpenAPI v2 converter - uses minimum and maximum fields")
847-
public void testissue1228() throws Exception {
848-
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1228_YAML);
849-
assertNotNull(oas);
850-
assertNotNull(oas.getPaths().get("/foobar").getGet().getParameters().get(0).getSchema().getMinimum());
851-
assertNotNull(oas.getPaths().get("/foobar").getGet().getParameters().get(0).getSchema().getMaximum());
852-
assertTrue(String.valueOf(oas.getPaths().get("/foobar").getGet().getParameters().get(0).getSchema().getMinimum()).equals("1.0"));
853-
assertTrue(String.valueOf(oas.getPaths().get("/foobar").getGet().getParameters().get(0).getSchema().getMaximum()).equals("2.0"));
854-
855-
}
856843
}

modules/swagger-parser-v2-converter/src/test/resources/issue-1228.json

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,12 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
23752375
schema.setWriteOnly(bool);
23762376
}
23772377

2378+
bool = Optional.ofNullable(getBoolean("writeOnly", node, false, location, result)).orElse(false) && Optional.ofNullable(getBoolean("readOnly", node, false, location, result)).orElse(false);
2379+
if(bool == true){
2380+
result.warning(location," writeOnly and readOnly are both present");
2381+
2382+
}
2383+
23782384
ObjectNode xmlNode = getObject("xml", node, false, location, result);
23792385
if (xmlNode != null) {
23802386
XML xml = getXml(xmlNode, location, result);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,4 +2192,22 @@ public void testParseOptionsSkipMatchesTrue() {
21922192
private static int getDynamicPort() {
21932193
return new Random().ints(10000, 20000).findFirst().getAsInt();
21942194
}
2195+
2196+
@Test
2197+
public void testSampleParser() {
2198+
final String location = "src/test/resources/issue-1211.json";
2199+
2200+
final ParseOptions options = new ParseOptions();
2201+
options.setResolve(true);
2202+
2203+
final OpenAPIV3Parser parser = new OpenAPIV3Parser();
2204+
final SwaggerParseResult result = parser.readLocation(location, null, options);
2205+
System.out.println(result.getMessages());
2206+
OpenAPI openAPI = result.getOpenAPI();
2207+
2208+
assertNotNull(result.getOpenAPI());
2209+
assertTrue(result.getMessages().size() > 0);
2210+
assertEquals(result.getMessages().get(0).contains("attribute components.schemas.Pet. writeOnly and readOnly are both present"), true);
2211+
2212+
}
21952213
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "How many items to return at one time (max 100)",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"format": "int32"
32+
}
33+
}
34+
],
35+
"responses": {
36+
"200": {
37+
"description": "A paged array of pets",
38+
"headers": {
39+
"x-next": {
40+
"description": "A link to the next page of responses",
41+
"schema": {
42+
"$ref":"#/components/schemas/Pets"
43+
}
44+
}
45+
},
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"$ref": "#/components/schemas/Pets"
50+
}
51+
}
52+
}
53+
},
54+
"default": {
55+
"description": "unexpected error",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"$ref": "#/components/schemas/Error"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"post": {
67+
"summary": "Create a pet",
68+
"operationId": "createPets",
69+
"tags": [
70+
"pets"
71+
],
72+
"requestBody":{
73+
"content":{
74+
"application/json": {
75+
"schema":{
76+
"type":"string",
77+
"default":1
78+
}
79+
}
80+
}
81+
82+
},
83+
"responses": {
84+
"201": {
85+
"description": "Null response"
86+
}
87+
}
88+
}
89+
},
90+
"/pets/{petId}": {
91+
"get": {
92+
"summary": "Info for a specific pet",
93+
"operationId": "showPetById",
94+
"tags": [
95+
"pets"
96+
],
97+
"parameters": [
98+
{
99+
"name": "petId",
100+
"in": "path",
101+
"required": true,
102+
"description": "The id of the pet to retrieve",
103+
"schema": {
104+
"type": "string"
105+
}
106+
}
107+
],
108+
"responses": {
109+
"200": {
110+
"description": "Expected response to a valid request",
111+
"content": {
112+
"application/json": {
113+
"schema": {
114+
"$ref": "#/components/schemas/Pets"
115+
}
116+
}
117+
}
118+
},
119+
"default": {
120+
"description": "unexpected error",
121+
"content": {
122+
"application/json": {
123+
"schema": {
124+
"$ref": "#/components/schemas/Error"
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
},
133+
"components": {
134+
"schemas": {
135+
"Pet": {
136+
"required": [
137+
"id",
138+
"name"
139+
],
140+
"properties": {
141+
"id": {
142+
"writeOnly":"true",
143+
"readOnly":"true",
144+
"type": "integer",
145+
"format": "int64"
146+
},
147+
"name": {
148+
"type": "string"
149+
},
150+
"tag": {
151+
"type": "string"
152+
}
153+
}
154+
},
155+
"Pets": {
156+
"type": "array",
157+
"items": {
158+
"$ref": "#/components/schemas/Pet"
159+
}
160+
},
161+
"Error": {
162+
"required": [
163+
"code",
164+
"message"
165+
],
166+
"properties": {
167+
"code": {
168+
"type": "integer",
169+
"format": "int32"
170+
},
171+
"message": {
172+
"type": "string"
173+
}
174+
}
175+
}
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)