Skip to content

Commit f1d3db2

Browse files
authored
Merge branch 'master' into issue1086
2 parents 4edce60 + 100c912 commit f1d3db2

File tree

24 files changed

+462
-80
lines changed

24 files changed

+462
-80
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
103103
</dependency>
104104
```
105105

106+
## Security contact
107+
108+
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker.
106109

107110
License
108111
-------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private List<Server> convert(List<Scheme> schemes, String host, String basePath)
420420
servers.add(server);
421421
}
422422
} else {
423-
if (!"/".equals(baseUrl)) {
423+
if (!StringUtils.startsWith(baseUrl, "/") && !"/".equals(baseUrl)) {
424424
baseUrl = "//" + baseUrl;
425425
}
426426
Server server = new Server();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class V2ConverterTest {
9090
private static final String ISSUE_768_JSON = "issue-786.json";
9191
private static final String ISSUE_820_YAML = "issue-820.yaml";
9292
private static final String ISSUE_1032_YAML = "issue-1032.yaml";
93+
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
9394

9495
private static final String API_BATCH_PATH = "/api/batch/";
9596
private static final String PETS_PATH = "/pets";
@@ -779,6 +780,16 @@ public void testIssue1032() throws Exception {
779780
assertEquals(INTEGER_TYPE, integerSchema.getType());
780781
assertEquals(INT64_FORMAT, integerSchema.getFormat());
781782
}
783+
784+
@Test(description = "OpenAPI v2 converter - converts URL correctly when it begins with forward slash")
785+
public void testIssue1113() throws Exception {
786+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1113_YAML);
787+
assertNotNull(oas);
788+
assertNotNull(oas.getServers());
789+
assertFalse(oas.getServers().isEmpty());
790+
assertNotNull(oas.getServers().get(0));
791+
assertEquals(oas.getServers().get(0).getUrl(), "/test");
792+
}
782793

783794
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
784795
SwaggerConverter converter = new SwaggerConverter();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test for Issue 1113
4+
version: 1.0.0
5+
basePath: /test
6+
paths:
7+
/ping:
8+
get:
9+
summary: test
10+
description: 'test'
11+
operationId: pingOp
12+
responses:
13+
'200':
14+
description: OK

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ComponentsProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ public void processSchemas(Set<String> schemaKeys, Map<String, Schema> schemas)
221221

222222
schemaProcessor.processSchema(model);
223223

224-
//if we process a RefModel here, in the #/definitions table, we want to overwrite it with the referenced value
224+
//if we process a RefModel here, in the #/components/schemas table, we want to overwrite it with the referenced value
225225
if (model.get$ref() != null) {
226226
final String renamedRef = cache.getRenamedRef(originalRef);
227227

228228
if (renamedRef != null) {
229-
//we definitely resolved the referenced and shoved it in the definitions map
230-
// because the referenced model may be in the definitions map, we need to remove old instances
229+
//we definitely resolved the referenced and shoved it in the components map
230+
// because the referenced model may be in the components map, we need to remove old instances
231231
final Schema resolvedModel = schemas.get(renamedRef);
232232

233233
// ensure the reference isn't still in use

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
182182
return newRef;
183183
}
184184

185-
private void processProperty(Schema property, String file) {
185+
private void processSchema(Schema property, String file) {
186186
if (property != null) {
187187
if (StringUtils.isNotBlank(property.get$ref())) {
188188
processRefSchema(property, file);
@@ -191,10 +191,10 @@ private void processProperty(Schema property, String file) {
191191
processProperties(property.getProperties(), file);
192192
}
193193
if (property instanceof ArraySchema) {
194-
processProperty(((ArraySchema) property).getItems(), file);
194+
processSchema(((ArraySchema) property).getItems(), file);
195195
}
196196
if (property.getAdditionalProperties() instanceof Schema) {
197-
processProperty(((Schema) property.getAdditionalProperties()), file);
197+
processSchema(((Schema) property.getAdditionalProperties()), file);
198198
}
199199
if (property instanceof ComposedSchema) {
200200
ComposedSchema composed = (ComposedSchema) property;
@@ -208,7 +208,7 @@ private void processProperty(Schema property, String file) {
208208
private void processProperties(Collection<Schema> properties, String file) {
209209
if (properties != null) {
210210
for (Schema property : properties) {
211-
processProperty(property, file);
211+
processSchema(property, file);
212212
}
213213
}
214214
}
@@ -269,6 +269,8 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
269269
} else {
270270
processRefToExternalSchema(file + schema.get$ref(), RefFormat.RELATIVE);
271271
}
272+
}else{
273+
processSchema(schema,file);
272274
}
273275
}
274276
}

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import io.swagger.v3.oas.models.examples.Example;
5+
import io.swagger.v3.oas.models.media.Content;
56
import io.swagger.v3.oas.models.media.MediaType;
67
import io.swagger.v3.oas.models.media.Schema;
78
import io.swagger.v3.oas.models.parameters.Parameter;
@@ -142,6 +143,23 @@ public List<Parameter> processParameters(List<Parameter> parameters) {
142143
Schema schema = parameter.getSchema();
143144
if(schema != null){
144145
schemaProcessor.processSchema(schema);
146+
}else if(parameter.getContent() != null){
147+
Map<String,MediaType> content = parameter.getContent();
148+
for( String mediaName : content.keySet()) {
149+
MediaType mediaType = content.get(mediaName);
150+
if(mediaType.getSchema()!= null) {
151+
schema = mediaType.getSchema();
152+
if (schema != null) {
153+
schemaProcessor.processSchema(schema);
154+
}
155+
}
156+
if(mediaType.getExamples() != null) {
157+
for(Example ex: mediaType.getExamples().values()){
158+
exampleProcessor.processExample(ex);
159+
}
160+
}
161+
}
162+
145163
}
146164
}
147165

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void processPaths() {
7575
final List<Parameter> processedPathParameters = parameterProcessor.processParameters(pathItem.getParameters());
7676
pathItem.setParameters(processedPathParameters);
7777

78-
//addParametersToEachOperation(pathItem);
7978

8079
final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap();
8180

@@ -162,6 +161,11 @@ protected void updateLocalRefs(PathItem path, String pathRef) {
162161
}
163162

164163
protected void updateLocalRefs(ApiResponse response, String pathRef) {
164+
if (response.get$ref() != null){
165+
if(isLocalRef(response.get$ref())) {
166+
response.set$ref(computeLocalRef(response.get$ref(), pathRef));
167+
}
168+
}
165169
if(response.getContent() != null) {
166170
Map<String, MediaType> content = response.getContent();
167171
for (String key: content.keySet()) {
@@ -188,6 +192,11 @@ protected void updateLocalRefs(Example example, String pathRef) {
188192
}
189193

190194
protected void updateLocalRefs(Parameter param, String pathRef) {
195+
if (param.get$ref() != null){
196+
if(isLocalRef(param.get$ref())) {
197+
param.set$ref(computeLocalRef(param.get$ref(), pathRef));
198+
}
199+
}
191200
if(param.getSchema() != null) {
192201
updateLocalRefs(param.getSchema(), pathRef);
193202
}
@@ -204,6 +213,11 @@ protected void updateLocalRefs(Parameter param, String pathRef) {
204213
}
205214

206215
protected void updateLocalRefs(RequestBody body, String pathRef) {
216+
if (body.get$ref() != null){
217+
if(isLocalRef(body.get$ref())) {
218+
body.set$ref(computeLocalRef(body.get$ref(), pathRef));
219+
}
220+
}
207221
if(body.getContent() != null) {
208222
Map<String, MediaType> content = body.getContent();
209223
for (String key: content.keySet()) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import io.swagger.v3.core.util.Yaml;
55
import io.swagger.v3.core.util.Json;
6+
import org.yaml.snakeyaml.constructor.SafeConstructor;
67

78
import java.io.IOException;
89

@@ -57,12 +58,12 @@ private static boolean isJson(String contents) {
5758
}
5859

5960
public static JsonNode readYamlTree(String contents) {
60-
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
61+
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
6162
return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
6263
}
6364

6465
public static <T> T readYamlValue(String contents, Class<T> expectedType) {
65-
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
66+
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
6667
return Json.mapper().convertValue(yaml.load(contents), expectedType);
6768
}
6869
}

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
15681568
parameter.setExample(example);
15691569
}
15701570

1571+
Boolean allowReserved = getBoolean("allowReserved", obj, false, location, result);
1572+
if (allowReserved != null) {
1573+
parameter.setAllowReserved(allowReserved);
1574+
}
1575+
15711576
ObjectNode contentNode = getObject("content",obj,false,location,result);
15721577
if(contentNode!= null) {
15731578
parameter.setContent(getContent(contentNode, String.format("%s.%s", location, "content"), result));
@@ -2032,9 +2037,6 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
20322037
ArrayNode allOfArray = getArray("allOf", node, false, location, result);
20332038
ArrayNode anyOfArray = getArray("anyOf", node, false, location, result);
20342039
ObjectNode itemsNode = getObject("items", node, false, location, result);
2035-
ObjectNode additionalPropertiesNode = getObject("additionalProperties", node, false, location, result);
2036-
Boolean additionalPropertiesBoolean = getBoolean("additionalProperties", node, false, location, result);
2037-
20382040

20392041
if((allOfArray != null )||(anyOfArray != null)|| (oneOfArray != null)) {
20402042
ComposedSchema composedSchema = new ComposedSchema();
@@ -2085,31 +2087,25 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
20852087
schema = items;
20862088
}
20872089

2088-
if(additionalPropertiesNode != null) {
2089-
MapSchema mapSchema = new MapSchema();
2090-
if (additionalPropertiesNode.getNodeType().equals(JsonNodeType.OBJECT)) {
2091-
ObjectNode additionalPropertiesObj = getObject("additionalProperties", node, false, location, result);
2092-
if (additionalPropertiesObj != null) {
2093-
Schema additionalProperties = getSchema(additionalPropertiesObj, location, result);
2094-
if (additionalProperties != null) {
2095-
mapSchema.setAdditionalProperties(additionalProperties);
2096-
schema = mapSchema;
2097-
}
2098-
}
2099-
}
2100-
} else if(additionalPropertiesBoolean != null){
2101-
MapSchema mapSchema = new MapSchema();
2102-
if (additionalPropertiesBoolean) {
2103-
mapSchema.setAdditionalProperties(additionalPropertiesBoolean);
2104-
schema = mapSchema;
2105-
}else{
2106-
ObjectSchema objectSchema = new ObjectSchema();
2107-
objectSchema.setAdditionalProperties(additionalPropertiesBoolean);
2108-
schema = objectSchema;
2109-
}
2110-
}
2090+
Boolean additionalPropertiesBoolean = getBoolean("additionalProperties", node, false, location, result);
21112091

2092+
ObjectNode additionalPropertiesObject =
2093+
additionalPropertiesBoolean == null
2094+
? getObject("additionalProperties", node, false, location, result)
2095+
: null;
21122096

2097+
Object additionalProperties =
2098+
additionalPropertiesObject != null
2099+
? getSchema(additionalPropertiesObject, location, result)
2100+
: additionalPropertiesBoolean;
2101+
2102+
if(additionalProperties != null) {
2103+
schema =
2104+
additionalProperties.equals( Boolean.FALSE)
2105+
? new ObjectSchema()
2106+
: new MapSchema();
2107+
schema.setAdditionalProperties( additionalProperties);
2108+
}
21132109

21142110
if (schema == null){
21152111
schema = SchemaTypeUtil.createSchemaByType(node);
@@ -2271,6 +2267,9 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
22712267
schema.setType(type);
22722268
}
22732269
}
2270+
if("array".equals( schema.getType()) && !(schema instanceof ArraySchema && ((ArraySchema) schema).getItems() != null)) {
2271+
result.missing(location, "items");
2272+
}
22742273
}
22752274

22762275
ObjectNode notObj = getObject("not", node, false, location, result);

0 commit comments

Comments
 (0)