Skip to content

Commit 3ef39f3

Browse files
committed
refs #1303 - compatibility and minor
1 parent 81e9e4d commit 3ef39f3

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import java.nio.file.Path;
2323
import java.nio.file.Paths;
2424
import java.util.ArrayList;
25-
import java.util.Arrays;
2625
import java.util.Collections;
27-
import java.util.Iterator;
2826
import java.util.List;
2927
import java.util.Objects;
3028
import java.util.ServiceLoader;
@@ -97,7 +95,7 @@ public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auth
9795

9896
@Override
9997
public SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth,
100-
ParseOptions options) {
98+
ParseOptions options) {
10199
return readContents(swaggerAsString, auth, options, null);
102100
}
103101

@@ -127,6 +125,11 @@ public OpenAPI read(String location, List<AuthorizationValue> auths, ParseOption
127125
return null;
128126
}
129127

128+
@Deprecated
129+
public SwaggerParseResult readWithInfo(String path, JsonNode node) {
130+
return parseJsonNode(path, node);
131+
}
132+
130133
public SwaggerParseResult parseJsonNode(String path, JsonNode node) {
131134
return new OpenAPIDeserializer().deserialize(node, path);
132135
}
@@ -138,30 +141,35 @@ public SwaggerParseResult readContents(String yaml) {
138141
}
139142

140143
private SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth, ParseOptions options,
141-
String parentFileLocation) {
144+
String location) {
142145
if (swaggerAsString == null || swaggerAsString.trim().isEmpty()) {
143-
return SwaggerParseResult.ofError("No swagger supplied");
146+
return SwaggerParseResult.ofError("Null or empty definition");
144147
}
145148

146149
try {
147150
final ObjectMapper mapper = getRightMapper(swaggerAsString);
148151
final JsonNode rootNode = mapper.readTree(swaggerAsString);
149-
final SwaggerParseResult result = parseJsonNode(parentFileLocation, rootNode);
150-
return resolve(result, auth, options, parentFileLocation);
152+
final SwaggerParseResult result = parseJsonNode(location, rootNode);
153+
return resolve(result, auth, options, location);
151154
} catch (JsonProcessingException e) {
152155
LOGGER.warn("Exception while parsing:", e);
153-
final String message = getParseErrorMessage(e.getOriginalMessage(), parentFileLocation);
156+
final String message = getParseErrorMessage(e.getOriginalMessage(), location);
154157
return SwaggerParseResult.ofError(message);
155158
}
156159
}
157160

161+
@Deprecated
162+
public SwaggerParseResult readWithInfo(String location, List<AuthorizationValue> auths) {
163+
return readContents(readContentFromLocation(location, auths), auths, null);
164+
}
165+
158166
private SwaggerParseResult resolve(SwaggerParseResult result, List<AuthorizationValue> auth, ParseOptions options,
159-
String parentFileLocation) {
167+
String location) {
160168
try {
161169
if (options != null) {
162170
if (options.isResolve() || options.isResolveFully()) {
163171
result.setOpenAPI(new OpenAPIResolver(result.getOpenAPI(), emptyListIfNull(auth),
164-
parentFileLocation).resolve());
172+
location).resolve());
165173
if (options.isResolveFully()) {
166174
new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
167175
}
@@ -180,12 +188,12 @@ private SwaggerParseResult resolve(SwaggerParseResult result, List<Authorization
180188
return result;
181189
}
182190

183-
private String getParseErrorMessage(String originalMessage, String parentFileLocation) {
191+
private String getParseErrorMessage(String originalMessage, String location) {
184192
if (Objects.isNull(originalMessage)) {
185-
return String.format("Unable to parse `%s`", parentFileLocation);
193+
return String.format("Unable to parse `%s`", location);
186194
}
187195
if (originalMessage.startsWith("Duplicate field")) {
188-
return String.format(originalMessage + " in `%s`", parentFileLocation);
196+
return String.format(originalMessage + " in `%s`", location);
189197
}
190198
return originalMessage;
191199
}
@@ -225,4 +233,35 @@ private String readContentFromLocation(String location, List<AuthorizationValue>
225233
throw new ReadContentException(String.format("Unable to read location `%s`", adjustedLocation), e);
226234
}
227235
}
236+
237+
/**
238+
* Transform the swagger-model version of AuthorizationValue into a parser-specific one, to avoid
239+
* dependencies across extensions
240+
*
241+
* @param input
242+
* @return
243+
*/
244+
@Deprecated
245+
protected List<AuthorizationValue> transform(List<AuthorizationValue> input) {
246+
if(input == null) {
247+
return null;
248+
}
249+
250+
List<AuthorizationValue> output = new ArrayList<>();
251+
252+
for(AuthorizationValue value : input) {
253+
AuthorizationValue v = new AuthorizationValue();
254+
255+
v.setKeyName(value.getKeyName());
256+
v.setValue(value.getValue());
257+
v.setType(value.getType());
258+
v.setUrlMatcher(value.getUrlMatcher());
259+
260+
output.add(v);
261+
}
262+
263+
return output;
264+
}
265+
266+
228267
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public class InlineModelResolver {
3333

3434
private final boolean flattenComposedSchemas;
3535
private final boolean camelCaseFlattenNaming;
36-
private final boolean skipMatches;
36+
private boolean skipMatches;
3737

3838
public InlineModelResolver(){this(false, false, false);}
3939

40+
public InlineModelResolver(boolean flattenComposedSchemas, boolean camelCaseFlattenNaming) {
41+
this(flattenComposedSchemas, camelCaseFlattenNaming, false);
42+
}
43+
4044
public InlineModelResolver(boolean flattenComposedSchemas, boolean camelCaseFlattenNaming, boolean skipMatches) {
4145
this.flattenComposedSchemas = flattenComposedSchemas;
4246
this.camelCaseFlattenNaming = camelCaseFlattenNaming;
@@ -591,4 +595,12 @@ private boolean isObjectSchema(Schema schema) {
591595
|| "object".equalsIgnoreCase(schema.getType())
592596
|| (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
593597
}
598+
599+
public boolean isSkipMatches() {
600+
return skipMatches;
601+
}
602+
603+
public void setSkipMatches(boolean skipMatches) {
604+
this.skipMatches = skipMatches;
605+
}
594606
}

0 commit comments

Comments
 (0)