|
22 | 22 | import io.swagger.parser.OpenAPIParser; |
23 | 23 | import io.swagger.v3.core.util.Json; |
24 | 24 | import io.swagger.v3.core.util.Yaml; |
| 25 | +import io.swagger.v3.oas.models.OpenAPI; |
25 | 26 | import io.swagger.v3.parser.OpenAPIResolver; |
26 | 27 | import io.swagger.v3.parser.OpenAPIV3Parser; |
27 | 28 | import io.swagger.v3.parser.core.models.AuthorizationValue; |
28 | 29 | import io.swagger.v3.parser.core.models.ParseOptions; |
| 30 | +import io.swagger.v3.parser.core.models.SwaggerParseResult; |
29 | 31 | import lombok.Setter; |
30 | 32 | import org.apache.commons.io.FileUtils; |
31 | 33 | import org.apache.commons.io.FilenameUtils; |
@@ -1046,9 +1048,12 @@ private String calculateInputSpecHash(String inputSpec) { |
1046 | 1048 | final URL remoteUrl = inputSpecRemoteUrl(); |
1047 | 1049 | final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth); |
1048 | 1050 |
|
| 1051 | + final SwaggerParseResult parseResult; |
| 1052 | + synchronized (CodegenConfigurator.SPEC_PARSE_LOCK) { |
| 1053 | + parseResult = new OpenAPIParser().readLocation(remoteUrl == null ? inputSpec : remoteUrl.toString(), authorizationValues, parseOptions); |
| 1054 | + } |
1049 | 1055 | return Hashing.sha256().hashBytes( |
1050 | | - new OpenAPIParser().readLocation(remoteUrl == null ? inputSpec : remoteUrl.toString(), authorizationValues, parseOptions) |
1051 | | - .getOpenAPI().toString().getBytes(StandardCharsets.UTF_8) |
| 1056 | + parseResult.getOpenAPI().toString().getBytes(StandardCharsets.UTF_8) |
1052 | 1057 | ).toString(); |
1053 | 1058 | } |
1054 | 1059 |
|
@@ -1137,7 +1142,10 @@ private Path createCollapsedSpec() throws MojoExecutionException { |
1137 | 1142 | parseOptions.setResolve(true); |
1138 | 1143 | final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth); |
1139 | 1144 |
|
1140 | | - final var openApiMerged = new OpenAPIResolver(new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, parseOptions).getOpenAPI()).resolve(); |
| 1145 | + final OpenAPI openApiMerged; |
| 1146 | + synchronized (CodegenConfigurator.SPEC_PARSE_LOCK) { |
| 1147 | + openApiMerged = new OpenAPIResolver(new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, parseOptions).getOpenAPI()).resolve(); |
| 1148 | + } |
1141 | 1149 |
|
1142 | 1150 | // Switch based on JSON or YAML. |
1143 | 1151 | final var extension = inputSpec.toLowerCase(Locale.ROOT).endsWith(".json") ? ".json" : ".yaml"; |
|
0 commit comments