Skip to content

Commit d1d4719

Browse files
authored
Merge branch 'master' into issue1070
2 parents b1b1c80 + 2d74be9 commit d1d4719

File tree

16 files changed

+363
-74
lines changed

16 files changed

+363
-74
lines changed

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/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);

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ParameterProcessorTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,24 @@ public void testProcessParameters_TypesThatAreNotRefOrBody(@Injectable final Hea
4545
{
4646
headerParameter.getSchema();
4747
result = null;
48+
headerParameter.getContent();
49+
result = null;
4850
queryParameter.getSchema();
4951
result = null;
52+
queryParameter.getContent();
53+
result = null;
5054
cookieParameter.getSchema();
5155
result = null;
56+
cookieParameter.getContent();
57+
result = null;
5258
pathParameter.getSchema();
5359
result = null;
60+
pathParameter.getContent();
61+
result = null;
5462
}
5563
};
5664
final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI)
57-
.processParameters(Arrays.<Parameter>asList(headerParameter,
65+
.processParameters(Arrays.asList(headerParameter,
5866
queryParameter,
5967
cookieParameter,
6068
pathParameter));
@@ -78,8 +86,7 @@ public void testProcessParameters_TypesThatAreNotRefOrBody(@Injectable final Hea
7886
}
7987

8088
@Test
81-
public void testProcessParameters_RefToHeader(
82-
@Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
89+
public void testProcessParameters_RefToHeader(@Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
8390
expectedModelProcessorCreation();
8491

8592
final String ref = "#/components/parameters/foo";
@@ -90,11 +97,12 @@ public void testProcessParameters_RefToHeader(
9097
{
9198
resolvedHeaderParam.getSchema();
9299
result = null;
100+
resolvedHeaderParam.getContent();
101+
result = null;
93102
}
94103
};
95104

96-
final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI)
97-
.processParameters(Arrays.<Parameter>asList(refParameter));
105+
final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI).processParameters(Arrays.asList(refParameter));
98106

99107
new FullVerifications(){{}};
100108

0 commit comments

Comments
 (0)