Skip to content

Commit 137a209

Browse files
authored
Merge pull request #1231 from r-sreesaran/issue-1228
Issue 1228
2 parents f60d9c3 + af7ee43 commit 137a209

File tree

6 files changed

+65
-202
lines changed

6 files changed

+65
-202
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,9 @@ 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+
10921095
schema = a;
10931096
} else {
10941097
schema = SchemaTypeUtil.createSchema(sp.getType(), sp.getFormat());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ 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+
9799

98100
private static final String API_BATCH_PATH = "/api/batch/";
99101
private static final String PETS_PATH = "/pets";
@@ -840,4 +842,15 @@ private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException,
840842
assertNotNull(result);
841843
return result.getOpenAPI();
842844
}
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+
}
843856
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"swagger":"2.0",
3+
"info":{
4+
5+
},
6+
"host":"localhost:51552",
7+
"basePath":"/",
8+
"tags":[
9+
{
10+
"name":"foo-controller",
11+
"description":"Foo Controller"
12+
}
13+
],
14+
"paths":{
15+
"/foobar":{
16+
"get":{
17+
"tags":[
18+
"foo-controller"
19+
],
20+
"summary":"foo",
21+
"operationId":"fooUsingGET",
22+
"produces":[
23+
"*/*"
24+
],
25+
"parameters":[
26+
{
27+
"name":"bars",
28+
"in":"query",
29+
"required":true,
30+
"type":"array",
31+
"items":{
32+
"type":"integer",
33+
"format":"int32"
34+
},
35+
"collectionFormat":"multi",
36+
"maximum":2.0,
37+
"minimum":1.0
38+
}
39+
],
40+
"responses":{
41+
"200":{
42+
"description":"OK"
43+
}
44+
},
45+
"deprecated":false
46+
}
47+
}
48+
}
49+
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,12 +2375,6 @@ 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-
23842378
ObjectNode xmlNode = getObject("xml", node, false, location, result);
23852379
if (xmlNode != null) {
23862380
XML xml = getXml(xmlNode, location, result);

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,22 +2192,4 @@ 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-
}
22132195
}

modules/swagger-parser-v3/src/test/resources/issue-1211.json

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

0 commit comments

Comments
 (0)