Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

package org.openapitools.codegen.plugin;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Json31;
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.SpecVersion;
import io.swagger.v3.parser.OpenAPIResolver;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.AuthorizationValue;
Expand Down Expand Up @@ -1155,10 +1160,22 @@ private String calculateInputSpecHash(String inputSpec) {
final URL remoteUrl = inputSpecRemoteUrl();
final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);

return Hashing.sha256().hashBytes(
new OpenAPIParser().readLocation(remoteUrl == null ? inputSpec : remoteUrl.toString(), authorizationValues, parseOptions)
.getOpenAPI().toString().getBytes(StandardCharsets.UTF_8)
).toString();
final OpenAPI spec = new OpenAPIParser()
.readLocation(remoteUrl == null ? inputSpec : remoteUrl.toString(), authorizationValues, parseOptions)
.getOpenAPI();

// If the specification is not parsable, a unique string is returned so the subsequent steps are not skipped.
// It is up to them to parse it again and deal with the error.
if (spec == null)
return "INVALID-HASH-" + System.currentTimeMillis();

final ObjectMapper mapper = spec.getSpecVersion() == SpecVersion.V30 ? Json.mapper() : Json31.mapper();
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.

try {
return Hashing.sha256().hashBytes(mapper.writeValueAsBytes(spec)).toString();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring-web-version>7.0.8</spring-web-version>
<spring-web-version>7.0.5</spring-web-version>
<jackson-version>3.1.5</jackson-version>
<jakarta-annotation-version>3.0.0</jakarta-annotation-version>

Expand Down
Loading