Skip to content

Commit

Permalink
Merge branch 'master' into parser-resolving-duplicated-path
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina authored Nov 13, 2023
2 parents 9a01c6e + c690d8d commit 631c2fc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/swagger-parser-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.1</version>
<executions>
<execution>
<id>process-resources</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void processSchema(Schema schema) {
return;
}
if (openapi31) {
// TODO use as singleton somewhere loaded as static used by both here and deserializer
List<JsonSchemaParserExtension> jsonschemaExtensions = OpenAPIDeserializer.getJsonSchemaParserExtensions();
for (JsonSchemaParserExtension jsonschemaExtension: jsonschemaExtensions) {
if (jsonschemaExtension.resolveSchema(schema, cache, openAPI, openapi31)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ public class OpenAPIDeserializer {
"(\\d{2}):(\\d{2})(\\.\\d+)?((Z)|([+-]\\d{2}:\\d{2}))$");
private static final Pattern RFC3339_DATE_PATTERN = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$");
private static final String REFERENCE_SEPARATOR = "#/";

private static final int MAX_EXTENSION_ENTRIES = 20;

// Holds extensions to a given classloader. Implemented as a least-recently used cache
private static final Map<ClassLoader, List<JsonSchemaParserExtension>> jsonSchemaParserExtensionMap = new LinkedHashMap<ClassLoader, List<JsonSchemaParserExtension>>() {
@Override
protected boolean removeEldestEntry(Map.Entry<ClassLoader, List<JsonSchemaParserExtension>> eldest) {
return size() > MAX_EXTENSION_ENTRIES;
}
};

private Components components;
private JsonNode rootNode;
private Map<String, Object> rootMap;
Expand Down Expand Up @@ -3780,15 +3791,30 @@ public static List<JsonSchemaParserExtension> getJsonSchemaParserExtensions() {
return extensions;
}

protected static List<JsonSchemaParserExtension> getJsonSchemaParserExtensions(ClassLoader cl) {
final List<JsonSchemaParserExtension> extensions = new ArrayList<>();
/**
* Locates the extensions for given {@link ClassLoader} and stores them for performance reason in an in-memory
* (LRU) cache.
*
* @param cl the {@link ClassLoader} for which the extensions are located
* @return
*/
protected static List<JsonSchemaParserExtension> getJsonSchemaParserExtensions(ClassLoader cl) {
if (jsonSchemaParserExtensionMap.containsKey(cl)) {
return jsonSchemaParserExtensionMap.get(cl);
}

final ServiceLoader<JsonSchemaParserExtension> loader = ServiceLoader.load(JsonSchemaParserExtension.class, cl);
for (JsonSchemaParserExtension extension : loader) {
extensions.add(extension);
}
return extensions;
}
final List<JsonSchemaParserExtension> extensions = new ArrayList<>();
final ServiceLoader<JsonSchemaParserExtension> loader = ServiceLoader.load(JsonSchemaParserExtension.class, cl);
for (JsonSchemaParserExtension extension : loader) {
extensions.add(extension);
}

// don't cache null-Value classLoader (e.g. Bootstrap Classloader)
if (cl != null) {
jsonSchemaParserExtensionMap.put(cl, extensions);
}
return extensions;
}

public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult result) {
if (jsonNode == null) {
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.2.1</version>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
Expand Down Expand Up @@ -264,7 +264,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.2.1</version>
<version>3.4.1</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -414,7 +414,7 @@
<maven.compiler.release>8</maven.compiler.release>
<snakeyaml-version>2.2</snakeyaml-version>
<swagger-parser-v2-version>1.0.68</swagger-parser-v2-version>
<commons-io-version>2.14.0</commons-io-version>
<commons-io-version>2.15.0</commons-io-version>
<slf4j-version>2.0.9</slf4j-version>
<swagger-core-version>2.2.17</swagger-core-version>
<swagger-core-v2-version>1.6.12</swagger-core-v2-version>
Expand Down

0 comments on commit 631c2fc

Please sign in to comment.