Skip to content

Commit 09747b5

Browse files
committed
Merge pull request #36 from swagger-api/develop
prepare for release
2 parents 9bbfe7f + 6e1d5ec commit 09747b5

File tree

8 files changed

+195
-99
lines changed

8 files changed

+195
-99
lines changed

modules/swagger-compat-spec-parser/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>1.0.4</version>
6+
<version>1.0.5</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>io.swagger</groupId>
1111
<artifactId>swagger-compat-spec-parser</artifactId>
12-
<version>1.0.4</version>
12+
<version>1.0.5</version>
1313
<packaging>jar</packaging>
1414
<name>swagger-compat-spec-parser</name>
1515
<dependencies>

modules/swagger-compat-spec-parser/src/main/java/io/swagger/parser/SwaggerCompatConverter.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,8 @@ else if(items.getRef() != null) {
319319
else {
320320
if(obj.getRef() != null)
321321
output = new RefProperty(obj.getRef());
322-
else if(type != null)
322+
else if(type != null && !type.equals("void"))
323323
output = new RefProperty(type);
324-
else
325-
output = new RefProperty("void");
326324
}
327325
}
328326

modules/swagger-parser/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>1.0.4</version>
6+
<version>1.0.5</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>io.swagger</groupId>
1111
<artifactId>swagger-parser</artifactId>
12-
<version>1.0.4</version>
12+
<version>1.0.5</version>
1313
<packaging>jar</packaging>
1414
<name>swagger-parser</name>
1515
<dependencies>

modules/swagger-parser/src/main/java/io/swagger/parser/SwaggerResolver.java

+129-78
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class SwaggerResolver {
2121
Logger LOGGER = LoggerFactory.getLogger(SwaggerResolver.class);
2222
protected Swagger swagger;
23-
protected Map<String, ResolutionContext> resolutionMap = new HashMap<String, ResolutionContext>();
23+
protected Map<String, List<ResolutionContext>> resolutionMap = new HashMap<String, List<ResolutionContext>>();
2424

2525
protected ResolverOptions opts;
2626
public SwaggerResolver(){}
@@ -57,70 +57,71 @@ public void applyResolutions(List<AuthorizationValue> auths) {
5757
objectList = new ArrayList<Object>();
5858
hostToObjectMap.put(host, objectList);
5959
}
60-
ResolutionContext ctx = resolutionMap.get(path);
61-
62-
Object mapping = ctx.object;
63-
Object target = ctx.parent;
64-
try {
65-
String contents = null;
66-
if(host.startsWith("http"))
67-
contents = new RemoteUrl().urlToString(host, auths);
68-
else
69-
contents = Json.mapper().writeValueAsString(swagger);
70-
JsonNode location = null;
71-
String locationName = null;
72-
if(contents != null) {
73-
location = Json.mapper().readTree(contents);
74-
String[] objectPath = definitionPath.split("/");
75-
for(String objectPathPart : objectPath) {
76-
LOGGER.debug("getting part " + objectPathPart);
77-
if(objectPathPart.length() > 0 && location != null) {
78-
location = location.get(objectPathPart);
79-
locationName = objectPathPart;
80-
}
81-
}
82-
}
83-
if(location != null) {
84-
// convert the node to the proper type
85-
if(mapping instanceof Property) {
86-
Model model = Json.mapper().convertValue(location, Model.class);
87-
if(mapping instanceof RefProperty) {
88-
RefProperty ref = (RefProperty) mapping;
89-
ref.set$ref(locationName);
90-
swagger.addDefinition(locationName, model);
60+
List<ResolutionContext> contexts = resolutionMap.get(path);
61+
for(ResolutionContext ctx : contexts) {
62+
Object mapping = ctx.object;
63+
Object target = ctx.parent;
64+
try {
65+
String contents = null;
66+
if(host.startsWith("http"))
67+
contents = new RemoteUrl().urlToString(host, auths);
68+
else
69+
contents = Json.mapper().writeValueAsString(swagger);
70+
JsonNode location = null;
71+
String locationName = null;
72+
if(contents != null) {
73+
location = Json.mapper().readTree(contents);
74+
String[] objectPath = definitionPath.split("/");
75+
for(String objectPathPart : objectPath) {
76+
LOGGER.debug("getting part " + objectPathPart);
77+
if(objectPathPart.length() > 0 && location != null) {
78+
location = location.get(objectPathPart);
79+
locationName = objectPathPart;
80+
}
9181
}
9282
}
93-
else if(target instanceof Parameter) {
94-
if(mapping instanceof RefModel) {
83+
if(location != null) {
84+
// convert the node to the proper type
85+
if(mapping instanceof Property) {
9586
Model model = Json.mapper().convertValue(location, Model.class);
96-
RefModel ref = (RefModel) mapping;
97-
ref.set$ref(locationName);
98-
swagger.addDefinition(locationName, model);
87+
if(mapping instanceof RefProperty) {
88+
RefProperty ref = (RefProperty) mapping;
89+
ref.set$ref(locationName);
90+
swagger.addDefinition(locationName, model);
91+
}
9992
}
100-
}
101-
else if(target instanceof Operation) {
102-
103-
// get the operation position
104-
Operation operation = (Operation) target;
105-
int position = 0;
106-
for(Parameter param : operation.getParameters()) {
107-
108-
if(param instanceof RefParameter) {
109-
RefParameter ref = (RefParameter) param;
110-
if(ref.getSimpleRef().equals(locationName)) {
111-
// found a match!
112-
Parameter remoteParam = Json.mapper().convertValue(location, Parameter.class);
113-
operation.getParameters().set(position, remoteParam);
93+
else if(target instanceof Parameter) {
94+
if(mapping instanceof RefModel) {
95+
Model model = Json.mapper().convertValue(location, Model.class);
96+
RefModel ref = (RefModel) mapping;
97+
ref.set$ref(locationName);
98+
swagger.addDefinition(locationName, model);
99+
}
100+
}
101+
else if(target instanceof Operation) {
102+
103+
// get the operation position
104+
Operation operation = (Operation) target;
105+
int position = 0;
106+
for(Parameter param : operation.getParameters()) {
107+
108+
if(param instanceof RefParameter) {
109+
RefParameter ref = (RefParameter) param;
110+
if(ref.getSimpleRef().equals(locationName)) {
111+
// found a match!
112+
Parameter remoteParam = Json.mapper().convertValue(location, Parameter.class);
113+
operation.getParameters().set(position, remoteParam);
114+
}
114115
}
116+
position += 1;
115117
}
116-
position += 1;
117118
}
118119
}
119120
}
120-
}
121-
catch(Exception e) {
122-
// failed to get it
123-
e.printStackTrace();
121+
catch(Exception e) {
122+
// failed to get it
123+
e.printStackTrace();
124+
}
124125
}
125126
}
126127
}
@@ -140,16 +141,29 @@ public void detectOperationRefs() {
140141
BodyParameter bp = (BodyParameter) parameter;
141142
if(bp.getSchema() != null && bp.getSchema() instanceof RefModel) {
142143
RefModel ref = (RefModel)bp.getSchema();
143-
if(ref.get$ref().startsWith("http")) {
144-
LOGGER.debug("added reference to " + ref.get$ref());
145-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, bp, "ref"));
144+
String key = ref.get$ref();
145+
if(key.startsWith("http")) {
146+
LOGGER.debug("added reference to " + key);
147+
List<ResolutionContext> m = resolutionMap.get(key);
148+
if(m == null) {
149+
m = new ArrayList<ResolutionContext>();
150+
}
151+
m.add(new ResolutionContext(ref, bp, "ref"));
152+
resolutionMap.put(key, m);
146153
}
147154
}
148155
}
149156
else if(parameter instanceof RefParameter) {
150157
RefParameter ref = (RefParameter) parameter;
151-
LOGGER.debug("added reference to " + ref.get$ref());
152-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, operation, "inline"));
158+
String key = ref.get$ref();
159+
LOGGER.debug("added reference to " + ref);
160+
161+
List<ResolutionContext> m = resolutionMap.get(key);
162+
if(m == null) {
163+
m = new ArrayList<ResolutionContext>();
164+
}
165+
m.add(new ResolutionContext(ref, operation, "inline"));
166+
resolutionMap.put(key, m);
153167
}
154168
}
155169
}
@@ -160,8 +174,15 @@ else if(parameter instanceof RefParameter) {
160174
Property schema = response.getSchema();
161175
if(schema instanceof RefProperty) {
162176
RefProperty ref = (RefProperty) schema;
163-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
164-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, response, "ref"));
177+
String key = ref.get$ref();
178+
179+
if(key != null && key.startsWith("http")) {
180+
List<ResolutionContext> m = resolutionMap.get(key);
181+
if(m == null) {
182+
m = new ArrayList<ResolutionContext>();
183+
}
184+
m.add(new ResolutionContext(ref, response, "ref"));
185+
resolutionMap.put(key, m);
165186
}
166187
}
167188
}
@@ -179,18 +200,30 @@ public void detectModelRefs() {
179200
Model model = models.get(modelName);
180201
if(model instanceof RefModel) {
181202
RefModel ref = (RefModel) model;
182-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
183-
LOGGER.debug("added reference to " + ref.get$ref());
184-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, swagger.getDefinitions(), "ref"));
203+
String key = ref.get$ref();
204+
if(key != null && key.startsWith("http")) {
205+
LOGGER.debug("added reference to " + key);
206+
List<ResolutionContext> m = resolutionMap.get(key);
207+
if(m == null) {
208+
m = new ArrayList<ResolutionContext>();
209+
}
210+
m.add(new ResolutionContext(ref, swagger.getDefinitions(), "ref"));
211+
resolutionMap.put(key, m);
185212
}
186213
}
187214
else if(model instanceof ArrayModel) {
188215
ArrayModel arrayModel = (ArrayModel) model;
189216
if(arrayModel.getItems() != null && arrayModel.getItems() instanceof RefProperty) {
190217
RefProperty ref = (RefProperty)arrayModel.getItems();
191-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
192-
LOGGER.debug("added reference to " + ref.get$ref());
193-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, swagger.getDefinitions(), "ref"));
218+
String key = ref.get$ref();
219+
if(key != null && key.startsWith("http")) {
220+
LOGGER.debug("added reference to " + key);
221+
List<ResolutionContext> m = resolutionMap.get(key);
222+
if(m == null) {
223+
m = new ArrayList<ResolutionContext>();
224+
}
225+
m.add(new ResolutionContext(ref, swagger.getDefinitions(), "ref"));
226+
resolutionMap.put(key, m);
194227
}
195228
}
196229
}
@@ -202,28 +235,46 @@ else if(model instanceof ModelImpl) {
202235
Property property = properties.get(propertyName);
203236
if(property instanceof RefProperty) {
204237
RefProperty ref = (RefProperty)property;
205-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
206-
LOGGER.debug("added reference to " + ref.get$ref());
207-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, impl, "ref"));
238+
String key = ref.get$ref();
239+
if(key != null && key.startsWith("http")) {
240+
LOGGER.debug("added reference to " + key);
241+
List<ResolutionContext> m = resolutionMap.get(key);
242+
if(m == null) {
243+
m = new ArrayList<ResolutionContext>();
244+
}
245+
m.add(new ResolutionContext(ref, impl, "ref"));
246+
resolutionMap.put(key, m);
208247
}
209248
}
210249
else if(property instanceof ArrayProperty) {
211250
ArrayProperty arrayProperty = (ArrayProperty) property;
212251
if(arrayProperty.getItems() != null && arrayProperty.getItems() instanceof RefProperty) {
213252
RefProperty ref = (RefProperty)arrayProperty.getItems();
214-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
215-
LOGGER.debug("added reference to " + ref.get$ref());
216-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, arrayProperty, "ref"));
253+
String key = ref.get$ref();
254+
if(key != null && key.startsWith("http")) {
255+
LOGGER.debug("added reference to " + key);
256+
List<ResolutionContext> m = resolutionMap.get(key);
257+
if(m == null) {
258+
m = new ArrayList<ResolutionContext>();
259+
}
260+
m.add(new ResolutionContext(ref, arrayProperty, "ref"));
261+
resolutionMap.put(key, m);
217262
}
218263
}
219264
}
220265
else if(property instanceof MapProperty) {
221266
MapProperty mp = (MapProperty) property;
222267
if(mp.getAdditionalProperties() != null && mp.getAdditionalProperties() instanceof RefProperty) {
223268
RefProperty ref = (RefProperty)mp.getAdditionalProperties();
224-
if(ref.get$ref() != null && ref.get$ref().startsWith("http")) {
225-
LOGGER.debug("added reference to " + ref.get$ref());
226-
resolutionMap.put(ref.get$ref(), new ResolutionContext(ref, mp, "ref"));
269+
String key = ref.get$ref();
270+
if(key != null && key.startsWith("http")) {
271+
LOGGER.debug("added reference to " + key);
272+
List<ResolutionContext> m = resolutionMap.get(key);
273+
if(m == null) {
274+
m = new ArrayList<ResolutionContext>();
275+
}
276+
m.add(new ResolutionContext(ref, mp, "ref"));
277+
resolutionMap.put(key, m);
227278
}
228279
}
229280
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
swagger: "2.0"
2+
info:
3+
version: 0.0.0
4+
title: Simple API
5+
paths:
6+
/:
7+
get:
8+
responses:
9+
"200":
10+
description: OK
11+
schema:
12+
$ref: "#/definitions/InternshipResultModel"
13+
definitions:
14+
InternshipResultModel:
15+
properties:
16+
Review:
17+
$ref: "#/definitions/ReviewModel"
18+
ReviewModel:
19+
properties:
20+
Rating:
21+
type: integer

modules/swagger-parser/src/test/scala/SwaggerReaderTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class SwaggerReaderTest extends FlatSpec with Matchers {
3131
it should "read the issue 16 resource" in {
3232
val parser = new SwaggerParser()
3333
val swagger = parser.read("./src/test/resources/issue_16.yaml")
34-
Json.prettyPrint(swagger)
34+
// Json.prettyPrint(swagger)
3535
}
3636
}

0 commit comments

Comments
 (0)