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 @@ -32,8 +32,8 @@ public class CodegenOperation {
isDeprecated, isCallbackRequest, uniqueItems,
hasErrorResponseObject; // if 4xx, 5xx responses have at least one error object defined
public CodegenProperty returnProperty;
public String path, operationId, returnType, returnFormat, httpMethod, returnBaseType,
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
public String path, unescapedPath, operationId, returnType, returnFormat, httpMethod, returnBaseType,
returnContainer, summary, unescapedSummary, unescapedNotes, notes, baseName, defaultResponse;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
public CodegenDiscriminator discriminator;
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
public List<CodegenServer> servers = new ArrayList<CodegenServer>();
Expand Down Expand Up @@ -423,12 +423,14 @@ public String toString() {
sb.append(", isCallbackRequest=").append(isCallbackRequest);
sb.append(", uniqueItems='").append(uniqueItems);
sb.append(", path='").append(path).append('\'');
sb.append(", unescapedPath='").append(unescapedPath).append('\'');
sb.append(", operationId='").append(operationId).append('\'');
sb.append(", returnType='").append(returnType).append('\'');
sb.append(", httpMethod='").append(httpMethod).append('\'');
sb.append(", returnBaseType='").append(returnBaseType).append('\'');
sb.append(", returnContainer='").append(returnContainer).append('\'');
sb.append(", summary='").append(summary).append('\'');
sb.append(", unescapedSummary='").append(unescapedSummary).append('\'');
sb.append(", unescapedNotes='").append(unescapedNotes).append('\'');
sb.append(", notes='").append(notes).append('\'');
sb.append(", baseName='").append(baseName).append('\'');
Expand Down Expand Up @@ -496,12 +498,14 @@ public boolean equals(Object o) {
Objects.equals(returnProperty, that.returnProperty) &&
Objects.equals(responseHeaders, that.responseHeaders) &&
Objects.equals(path, that.path) &&
Objects.equals(unescapedPath, that.unescapedPath) &&
Objects.equals(operationId, that.operationId) &&
Objects.equals(returnType, that.returnType) &&
Objects.equals(httpMethod, that.httpMethod) &&
Objects.equals(returnBaseType, that.returnBaseType) &&
Objects.equals(returnContainer, that.returnContainer) &&
Objects.equals(summary, that.summary) &&
Objects.equals(unescapedSummary, that.unescapedSummary) &&
Objects.equals(unescapedNotes, that.unescapedNotes) &&
Objects.equals(notes, that.notes) &&
Objects.equals(baseName, that.baseName) &&
Expand Down Expand Up @@ -546,8 +550,8 @@ public int hashCode() {
return Objects.hash(responseHeaders, hasAuthMethods, hasConsumes, hasProduces, hasOptionalParams,
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
isArray, isMultipart, isVoid, isResponseBinary, isResponseFile, isResponseOptional, hasReference,
isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse,
isDeprecated, isCallbackRequest, uniqueItems, path, unescapedPath, operationId, returnType, httpMethod,
returnBaseType, returnContainer, summary, unescapedSummary, unescapedNotes, notes, baseName, defaultResponse,
discriminator, consumes, produces, prioritizedContentTypes, servers, bodyParam, allParams, bodyParams,
pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, returnProperty, optionalParams,
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openapitools.codegen;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.models.examples.Example;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -35,6 +36,10 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
isFormStyle, isSpaceDelimited, isPipeDelimited;
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, contentType,
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumDefaultValue, enumName, style;
/** Typed snapshot of the schema default captured before language conversion. */
public JsonNode rawDefaultValue;
public String rawDefaultValueText;
public boolean hasDefaultValue;

public String nameInLowerCase; // property name in lower case
public String nameInCamelCase; // property name in camel case (e.g. modifiedDate)
Expand Down Expand Up @@ -186,6 +191,9 @@ public CodegenParameter copy() {
output.multipleOf = this.multipleOf;
output.jsonSchema = this.jsonSchema;
output.defaultValue = this.defaultValue;
output.rawDefaultValue = this.rawDefaultValue;
output.rawDefaultValueText = this.rawDefaultValueText;
output.hasDefaultValue = this.hasDefaultValue;
output.enumDefaultValue = this.enumDefaultValue;
output.example = this.example;
output.examples = this.examples;
Expand Down Expand Up @@ -295,7 +303,8 @@ public int hashCode() {
isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName,
paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description,
unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue,
enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples,
rawDefaultValue, rawDefaultValueText, hasDefaultValue, enumDefaultValue, enumName, style,
isDeepObject, isMatrix, isAllowEmptyValue, example, examples,
isFormStyle, isSpaceDelimited, isPipeDelimited,
jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal,
isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword,
Expand Down Expand Up @@ -388,6 +397,9 @@ public boolean equals(Object o) {
Objects.equals(containerType, that.containerType) &&
Objects.equals(containerTypeMapped, that.containerTypeMapped) &&
Objects.equals(defaultValue, that.defaultValue) &&
Objects.equals(rawDefaultValue, that.rawDefaultValue) &&
Objects.equals(rawDefaultValueText, that.rawDefaultValueText) &&
hasDefaultValue == that.hasDefaultValue &&
Objects.equals(enumDefaultValue, that.enumDefaultValue) &&
Objects.equals(enumName, that.enumName) &&
Objects.equals(style, that.style) &&
Expand Down Expand Up @@ -1158,4 +1170,3 @@ public void setIsEnum(boolean isEnum) {
this.isEnum = isEnum;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openapitools.codegen;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -61,6 +62,10 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public String max; // TODO: is this really used?
@Getter @Setter
public String defaultValue;
/** Typed snapshot of the schema default captured before language conversion. */
public JsonNode rawDefaultValue;
public String rawDefaultValueText;
public boolean hasDefaultValue;
@Getter @Setter
public String defaultValueWithParam;
@Setter public String baseType;
Expand Down Expand Up @@ -986,6 +991,9 @@ public String toString() {
sb.append(", min='").append(min).append('\'');
sb.append(", max='").append(max).append('\'');
sb.append(", defaultValue='").append(defaultValue).append('\'');
sb.append(", rawDefaultValue=").append(rawDefaultValue);
sb.append(", rawDefaultValueText='").append(rawDefaultValueText).append('\'');
sb.append(", hasDefaultValue=").append(hasDefaultValue);
sb.append(", defaultValueWithParam='").append(defaultValueWithParam).append('\'');
sb.append(", baseType='").append(baseType).append('\'');
sb.append(", containerType='").append(containerType).append('\'');
Expand Down Expand Up @@ -1173,6 +1181,9 @@ public boolean equals(Object o) {
Objects.equals(min, that.min) &&
Objects.equals(max, that.max) &&
Objects.equals(defaultValue, that.defaultValue) &&
Objects.equals(rawDefaultValue, that.rawDefaultValue) &&
Objects.equals(rawDefaultValueText, that.rawDefaultValueText) &&
hasDefaultValue == that.hasDefaultValue &&
Objects.equals(defaultValueWithParam, that.defaultValueWithParam) &&
Objects.equals(baseType, that.baseType) &&
Objects.equals(containerType, that.containerType) &&
Expand Down Expand Up @@ -1212,7 +1223,8 @@ public int hashCode() {

return Objects.hash(openApiType, baseName, complexType, getter, setter, description,
dataType, datatypeWithEnum, dataFormat, name, min, max, defaultValue,
defaultValueWithParam, baseType, containerType, containerTypeMapped, title, unescapedDescription,
rawDefaultValue, rawDefaultValueText, hasDefaultValue, defaultValueWithParam, baseType,
containerType, containerTypeMapped, title, unescapedDescription,
maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
exclusiveMinimum, exclusiveMaximum, required, deprecated,
isPrimitiveType, isModel, isContainer, isString, isNumeric,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
public boolean is4xx;
public boolean is5xx;
public String message;
/** Original response description before generator escaping. */
public String unescapedMessage;
public List<Map<String, Object>> examples;
public String dataType;
public String baseType;
Expand Down Expand Up @@ -109,7 +111,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {

@Override
public int hashCode() {
return Objects.hash(headers, code, message, examples, dataType, baseType, containerType, containerTypeMapped, hasHeaders,
return Objects.hash(headers, code, message, unescapedMessage, examples, dataType, baseType, containerType, containerTypeMapped, hasHeaders,
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBoolean, isDate,
isDateTime, isUuid, isEmail, isPassword, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
isMap, isOptional, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
Expand Down Expand Up @@ -182,6 +184,7 @@ public boolean equals(Object o) {
Objects.equals(headers, that.headers) &&
Objects.equals(code, that.code) &&
Objects.equals(message, that.message) &&
Objects.equals(unescapedMessage, that.unescapedMessage) &&
Objects.equals(examples, that.examples) &&
Objects.equals(dataType, that.dataType) &&
Objects.equals(baseType, that.baseType) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openapitools.codegen;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Ticker;
Expand Down Expand Up @@ -4151,6 +4152,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo

// unalias schema
p = unaliasSchema(p);
Object referencedDefault = p.getDefault();

property.setSchemaIsFromAdditionalProperties(schemaIsFromAdditionalProperties);
property.required = required;
Expand Down Expand Up @@ -4406,6 +4408,11 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
}
}

Object effectiveDefault = p.getDefault() != null ? p.getDefault() : referencedDefault;
property.hasDefaultValue = effectiveDefault != null;
property.rawDefaultValue = snapshotDefaultValue(effectiveDefault);
property.rawDefaultValueText = rawDefaultValueText(effectiveDefault);

// override defaultValue if it's not set and defaultToEmptyContainer is set
if (p.getDefault() == null && defaultToEmptyContainer) {
updateDefaultToEmptyContainer(property, p);
Expand Down Expand Up @@ -4950,8 +4957,10 @@ public CodegenOperation fromOperation(String path,
op.path = path;
}
// remove backslash from path, e.g. /api/v2/GetPetById\\(\\) => /api/v2/GetPetById()
op.unescapedPath = op.path;
op.path = op.path.replace("\\", "");

op.unescapedSummary = operation.getSummary();
op.summary = escapeText(operation.getSummary());
op.unescapedNotes = operation.getDescription();
op.notes = escapeText(operation.getDescription());
Expand Down Expand Up @@ -5128,6 +5137,7 @@ public CodegenOperation fromOperation(String path,

if (bodyParam != null) {
bodyParam.description = escapeText(requestBody.getDescription());
bodyParam.unescapedDescription = requestBody.getDescription();
postProcessParameter(bodyParam);
bodyParams.add(bodyParam);
if (prependFormOrBodyParameters) {
Expand Down Expand Up @@ -5329,6 +5339,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
responseSchema = ModelUtils.getSchemaFromResponse(openAPI, response);
}
r.schema = responseSchema;
r.unescapedMessage = response.getDescription();
r.message = escapeText(response.getDescription());

// adding examples to API responses
Expand Down Expand Up @@ -5892,11 +5903,38 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)

// set default value
codegenParameter.defaultValue = toDefaultParameterValue(codegenProperty, parameterSchema);

codegenParameter.hasDefaultValue = codegenProperty != null && codegenProperty.hasDefaultValue;
codegenParameter.rawDefaultValue = codegenProperty == null ? null : codegenProperty.rawDefaultValue;
codegenParameter.rawDefaultValueText = codegenProperty == null ? null : codegenProperty.rawDefaultValueText;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Date form parameters can receive an invalid generated default in their @Parameter schema because this path copies the materialized Date text before setting isDate and never applies the date normalization used by fromParameter. Normalize the raw default after date classification, or share the existing date-default handling.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, line 5908:

<comment>Date form parameters can receive an invalid generated default in their `@Parameter` schema because this path copies the materialized `Date` text before setting `isDate` and never applies the date normalization used by `fromParameter`. Normalize the raw default after date classification, or share the existing date-default handling.</comment>

<file context>
@@ -5892,11 +5903,38 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
-
+        codegenParameter.hasDefaultValue = codegenProperty != null && codegenProperty.hasDefaultValue;
+        codegenParameter.rawDefaultValue = codegenProperty == null ? null : codegenProperty.rawDefaultValue;
+        codegenParameter.rawDefaultValueText = codegenProperty == null ? null : codegenProperty.rawDefaultValueText;
+        // swagger-parser materializes date defaults as Date, losing the lexical
+        // OpenAPI value. Preserve the same date form emitted for parameter binding.
</file context>

// swagger-parser materializes date defaults as Date, losing the lexical
// OpenAPI value. Preserve the same date form emitted for parameter binding.
if (codegenParameter.isDate && codegenParameter.rawDefaultValue != null
&& codegenParameter.defaultValue != null) {
codegenParameter.rawDefaultValueText = codegenParameter.defaultValue;
}
finishUpdatingParameter(codegenParameter, parameter);
return codegenParameter;
}

private JsonNode snapshotDefaultValue(Object value) {
if (value == null) {
return null;
}
try {
return Json.mapper().valueToTree(value);
} catch (RuntimeException e) {
return null;
}
}

private String rawDefaultValueText(Object value) {
if (value == null) {
return null;
}
JsonNode node = snapshotDefaultValue(value);
return node != null && node.isTextual() ? node.textValue() : String.valueOf(value);
}

private Schema getReferencedSchemaWhenNotEnum(Schema parameterSchema) {
Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, parameterSchema);
if (isEnumSchema(referencedSchema)) {
Expand Down Expand Up @@ -7256,7 +7294,9 @@ protected List<EnumVarMap> buildEnumVars(List<Object> values, String dataType, L

final String finalEnumName = toEnumVarName(enumName, dataType);

enumVar.enumVar(finalEnumName, toEnumValue(String.valueOf(value), dataType), isDataTypeString(dataType));
String rawEnumValue = String.valueOf(value);
enumVar.enumVar(finalEnumName, toEnumValue(rawEnumValue, dataType), isDataTypeString(dataType));
enumVar.setEnumValueRaw(rawEnumValue);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: valueRaw is populated from the transformed enum value, so callers that sanitize values still expose sanitized text as the raw template value. Set ENUM_VALUE_RAW from rawValues.get(i) while keeping the generated value based on values.get(i).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, line 7299:

<comment>`valueRaw` is populated from the transformed enum value, so callers that sanitize `values` still expose sanitized text as the raw template value. Set `ENUM_VALUE_RAW` from `rawValues.get(i)` while keeping the generated `value` based on `values.get(i)`.</comment>

<file context>
@@ -7256,7 +7294,9 @@ protected List<EnumVarMap> buildEnumVars(List<Object> values, String dataType, L
-            enumVar.enumVar(finalEnumName, toEnumValue(String.valueOf(value), dataType), isDataTypeString(dataType));
+            String rawEnumValue = String.valueOf(value);
+            enumVar.enumVar(finalEnumName, toEnumValue(rawEnumValue, dataType), isDataTypeString(dataType));
+            enumVar.setEnumValueRaw(rawEnumValue);
             enumVar.setEnumRawValue(rawValues.get(i));
             // TODO: add isNumeric
</file context>

enumVar.setEnumRawValue(rawValues.get(i));
// TODO: add isNumeric
enumVars.add(enumVar);
Expand Down Expand Up @@ -7291,6 +7331,7 @@ private void injectEnumUnknownDefaultCase(List<EnumVarMap> enumVars, String data
String.valueOf(11184809);

enumVar.enumVar(toEnumVarName(enumName, dataType), toEnumValue(enumValue, dataType), isDataTypeString(dataType));
enumVar.setEnumValueRaw(enumValue);
enumVar.setEnumRawValue(enumValue);
// TODO: add isNumeric
enumVars.add(enumVar);
Expand Down Expand Up @@ -7645,6 +7686,7 @@ private void setOauth2Info(CodegenSecurity codegenSecurity, OAuthFlow flow) {
Map<String, Object> scope = new HashMap<>();
scope.put("scope", scopeEntry.getKey());
scope.put("description", escapeText(scopeEntry.getValue()));
scope.put("descriptionRaw", scopeEntry.getValue());
scopes.add(scope);
}
codegenSecurity.scopes = scopes;
Expand Down Expand Up @@ -7933,6 +7975,9 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set

// set default value
codegenParameter.defaultValue = toDefaultParameterValue(codegenProperty, propertySchema);
codegenParameter.hasDefaultValue = codegenProperty != null && codegenProperty.hasDefaultValue;
codegenParameter.rawDefaultValue = codegenProperty == null ? null : codegenProperty.rawDefaultValue;
codegenParameter.rawDefaultValueText = codegenProperty == null ? null : codegenProperty.rawDefaultValueText;

if (ModelUtils.isFileSchema(ps) && !ModelUtils.isStringSchema(ps)) {
// swagger v2 only, type file
Expand Down Expand Up @@ -8053,7 +8098,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set

codegenParameter.isFormParam = Boolean.TRUE;
codegenParameter.description = escapeText(codegenProperty.description);
codegenParameter.unescapedDescription = codegenProperty.getDescription();
codegenParameter.unescapedDescription = codegenProperty.unescapedDescription;
codegenParameter.jsonSchema = Json.pretty(propertySchema);
codegenParameter.containerType = codegenProperty.containerType;
codegenParameter.containerTypeMapped = codegenProperty.containerTypeMapped;
Expand Down Expand Up @@ -8083,7 +8128,6 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set

// set nullable
setParameterNullable(codegenParameter, codegenProperty);

return codegenParameter;
}

Expand Down
Loading
Loading