From 54bb3824302ff8c619b09da84fcb107c98be1309 Mon Sep 17 00:00:00 2001 From: Simon Bullik Date: Wed, 12 Aug 2020 23:10:39 +0200 Subject: [PATCH] Properly decode $ref fixes #5720 --- .../codegen/utils/ModelUtils.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 4c3e9fe01180..e72e8812fe87 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -43,6 +43,7 @@ import java.math.BigDecimal; import java.net.URI; +import java.net.URLDecoder; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -71,7 +72,7 @@ public class ModelUtils { JSON_MAPPER = ObjectMapperFactory.createJson(); YAML_MAPPER = ObjectMapperFactory.createYaml(); } - + public static void setDisallowAdditionalPropertiesIfNotPresent(boolean value) { GlobalSettings.setProperty(disallowAdditionalPropertiesIfNotPresent, Boolean.toString(value)); } @@ -386,7 +387,7 @@ public static String getSimpleRef(String ref) { } - return ref; + return URLDecoder.decode(ref); } /** @@ -1077,7 +1078,7 @@ public static Schema unaliasSchema(OpenAPI openAPI, /** * Returns the additionalProperties Schema for the specified input schema. - * + * * The additionalProperties keyword is used to control the handling of additional, undeclared * properties, that is, properties whose names are not listed in the properties keyword. * The additionalProperties keyword may be either a boolean or an object. @@ -1085,7 +1086,7 @@ public static Schema unaliasSchema(OpenAPI openAPI, * By default when the additionalProperties keyword is not specified in the input schema, * any additional properties are allowed. This is equivalent to setting additionalProperties * to the boolean value True or setting additionalProperties: {} - * + * * @param openAPI the object that encapsulates the OAS document. * @param schema the input schema that may or may not have the additionalProperties keyword. * @return the Schema of the additionalProperties. The null value is returned if no additional @@ -1141,7 +1142,7 @@ public static Schema getAdditionalProperties(OpenAPI openAPI, Schema schema) { } return null; } - + public static Header getReferencedHeader(OpenAPI openAPI, Header header) { if (header != null && StringUtils.isNotEmpty(header.get$ref())) { String name = getSimpleRef(header.get$ref()); @@ -1478,12 +1479,12 @@ private static ObjectMapper getRightMapper(String data) { /** * Parse and return a JsonNode representation of the input OAS document. - * + * * @param location the URL of the OAS document. * @param auths the list of authorization values to access the remote URL. - * + * * @throws java.lang.Exception if an error occurs while retrieving the OpenAPI document. - * + * * @return A JsonNode representation of the input OAS document. */ public static JsonNode readWithInfo(String location, List auths) throws Exception { @@ -1511,14 +1512,14 @@ public static JsonNode readWithInfo(String location, List au /** * Parse the OAS document at the specified location, get the swagger or openapi version * as specified in the source document, and return the version. - * + * * For OAS 2.0 documents, return the value of the 'swagger' attribute. * For OAS 3.x documents, return the value of the 'openapi' attribute. - * + * * @param openAPI the object that encapsulates the OAS document. * @param location the URL of the OAS document. * @param auths the list of authorization values to access the remote URL. - * + * * @return the version of the OpenAPI document. */ public static SemVer getOpenApiVersion(OpenAPI openAPI, String location, List auths) {