Skip to content
Merged
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 @@ -2974,12 +2974,6 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
}

protected void updateModelForAnyType(CodegenModel m, Schema schema) {
// The 'null' value is allowed when the OAS schema is 'any type'.
// See https://github.com/OAI/OpenAPI-Specification/issues/1389
if (Boolean.FALSE.equals(schema.getNullable())) {
LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", m.name);
}
// m.isNullable = true;
if (ModelUtils.isMapSchema(schema)) {
// an object or anyType composed schema that has additionalProperties set
addAdditionPropertiesToCodeGenModel(m, schema);
Expand Down Expand Up @@ -3714,12 +3708,6 @@ protected void updatePropertyForObject(CodegenProperty property, Schema p) {
}

protected void updatePropertyForAnyType(CodegenProperty property, Schema p) {
// The 'null' value is allowed when the OAS schema is 'any type'.
// See https://github.com/OAI/OpenAPI-Specification/issues/1389
if (Boolean.FALSE.equals(p.getNullable())) {
LOGGER.warn("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName());
}

property.isNullable = property.isNullable ||
!(ModelUtils.isComposedSchema(p)) ||
p.getAllOf() == null ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2182,13 +2182,22 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchema
normalizeExclusiveMinMax31(schema);

if (schema instanceof JsonSchema &&
schema.get$schema() == null &&
schema.getTypes() == null && schema.getType() == null) {
schema.get$schema() == null && schema.getTypes() == null && schema.getType() == null) {
// convert any type in v3.1 to empty schema (any type in v3.0 spec), any type example:
// components:
// schemas:
// any_type: {}
return new Schema();
Schema sc = new Schema<>();

// copy description, title, etc
ModelUtils.copyMetadata(schema, sc);

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: Schemas using examples are normalized with those values in the singular example field, so generated examples and downstream consumers can interpret the metadata incorrectly. The copy should preserve examples via setExamples (and leave example sourced only from getExample).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java, line 2193:

<comment>Schemas using `examples` are normalized with those values in the singular `example` field, so generated examples and downstream consumers can interpret the metadata incorrectly. The copy should preserve `examples` via `setExamples` (and leave `example` sourced only from `getExample`).</comment>

<file context>
@@ -2182,13 +2182,22 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchema
+            Schema sc = new Schema<>();
+
+            // copy description, title, etc
+            ModelUtils.copyMetadata(schema, sc);
+
+            // additional properties set?
</file context>


// additional properties set?
if (schema.getAdditionalProperties() != null) {

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: Any-type schemas that only declare additionalProperties still bypass this new preservation logic: normalizeSchema classifies them as null schemas and returns the original before processNormalize31Spec runs. This leaves the reported OAS 3.1 case unhandled unless the schema also has a description or another field that prevents the early return; the null-schema guard should exclude schemas with additionalProperties or the handling should occur before that return.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java, line 2193:

<comment>Any-type schemas that only declare `additionalProperties` still bypass this new preservation logic: `normalizeSchema` classifies them as null schemas and returns the original before `processNormalize31Spec` runs. This leaves the reported OAS 3.1 case unhandled unless the schema also has a description or another field that prevents the early return; the null-schema guard should exclude schemas with `additionalProperties` or the handling should occur before that return.</comment>

<file context>
@@ -2182,13 +2182,19 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchema
+            Schema sc = new Schema<>();
+
+            // additional properties set?
+            if (schema.getAdditionalProperties() != null) {
+                sc.setAdditionalProperties(schema.getAdditionalProperties());
+            }
</file context>

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: When the normalizer converts a type-less 3.1 schema that has additionalProperties (e.g. a free-form map with a description, title, default or example), it returns a brand-new empty Schema and copies only additionalProperties, silently dropping all other sibling metadata such as description, title, default, example, and extensions. For a map schema like { description: 'a map', additionalProperties: { type: string } } this means the description no longer reaches generated code. Since this branch is being extended specifically to preserve additionalProperties, it would be more consistent to carry over the remaining metadata too (for example, reusing an existing metadata-copy helper).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java, line 2193:

<comment>When the normalizer converts a type-less 3.1 schema that has `additionalProperties` (e.g. a free-form map with a `description`, `title`, `default` or `example`), it returns a brand-new empty `Schema` and copies only `additionalProperties`, silently dropping all other sibling metadata such as description, title, default, example, and extensions. For a map schema like `{ description: 'a map', additionalProperties: { type: string } }` this means the description no longer reaches generated code. Since this branch is being extended specifically to preserve `additionalProperties`, it would be more consistent to carry over the remaining metadata too (for example, reusing an existing metadata-copy helper).</comment>

<file context>
@@ -2182,13 +2182,19 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchema
+            Schema sc = new Schema<>();
+
+            // additional properties set?
+            if (schema.getAdditionalProperties() != null) {
+                sc.setAdditionalProperties(schema.getAdditionalProperties());
+            }
</file context>

sc.setAdditionalProperties(schema.getAdditionalProperties());
}

return sc;
}

// return schema if nothing in 3.1 spec types to normalize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2620,8 +2620,9 @@ public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
return false;
}

// schema with properties
if (schema.getProperties() != null) {
// schema with properties or additional properties
if (schema.getProperties() != null ||
(schema.getAdditionalProperties() != null && !Boolean.FALSE.equals(schema.getBooleanSchemaValue()))) {
return false;
}

Expand Down Expand Up @@ -2726,7 +2727,7 @@ public static void copyMetadata(Schema from, Schema to) {
to.setExample(from.getExample());
}
if (from.getExamples() != null) {
to.setExample(from.getExamples());
to.setExamples(from.getExamples());
}
if (from.getReadOnly() != null) {
to.setReadOnly(from.getReadOnly());
Expand Down
Loading