-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Normalize map schema (3.1 spec) #24558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ebcb444
6859592
9d43ba0
de40ccf
671ad55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -998,8 +998,8 @@ public Schema normalizeSchema(Schema schema, Set<Schema> visitedSchemas) { | |||||||||||||||||||
| } | ||||||||||||||||||||
| normalizeProperties(schema, visitedSchemas); | ||||||||||||||||||||
| } else if (schema.getAdditionalProperties() instanceof Schema) { // map | ||||||||||||||||||||
| normalizeMapSchema(schema); | ||||||||||||||||||||
| Schema additionalProperties = (Schema) schema.getAdditionalProperties(); | ||||||||||||||||||||
| Schema result = normalizeMapSchema(schema); | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A type-less OAS 3.1 map schema (declared only via Prompt for AI agents |
||||||||||||||||||||
| Schema additionalProperties = (Schema) result.getAdditionalProperties(); | ||||||||||||||||||||
| if (getRule(NORMALIZE_31SPEC) && ModelUtils.isNullTypeSchema(openAPI, additionalProperties)) { | ||||||||||||||||||||
| // OAS 3.1 allows a map value schema of `type: "null"` (e.g. | ||||||||||||||||||||
| // `additionalProperties: { type: "null" }`). There's no OAS 3.0 equivalent type, | ||||||||||||||||||||
|
|
@@ -1008,15 +1008,17 @@ public Schema normalizeSchema(Schema schema, Set<Schema> visitedSchemas) { | |||||||||||||||||||
| // generated as a normal (nullable) object instead. | ||||||||||||||||||||
| Schema anyTypeNullable = new Schema(); | ||||||||||||||||||||
| anyTypeNullable.setNullable(true); | ||||||||||||||||||||
| schema.setAdditionalProperties(anyTypeNullable); | ||||||||||||||||||||
| result.setAdditionalProperties(anyTypeNullable); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| Schema normalized = normalizeSchema(additionalProperties, visitedSchemas); | ||||||||||||||||||||
| if (getRule(NORMALIZE_31SPEC)) { | ||||||||||||||||||||
| // capture the normalized value schema (e.g. an OAS 3.1 `type: [array, "null"]` | ||||||||||||||||||||
| // value is rewritten to a proper array schema), which would otherwise be lost. | ||||||||||||||||||||
| schema.setAdditionalProperties(normalized); | ||||||||||||||||||||
| result.setAdditionalProperties(normalized); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return result; | ||||||||||||||||||||
| } else if (schema instanceof BooleanSchema) { | ||||||||||||||||||||
| normalizeBooleanSchema(schema, visitedSchemas); | ||||||||||||||||||||
| } else if (schema instanceof IntegerSchema) { | ||||||||||||||||||||
|
|
@@ -1105,7 +1107,8 @@ protected Schema normalizeArraySchema(Schema schema) { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| protected Schema normalizeMapSchema(Schema schema) { | ||||||||||||||||||||
| return processSetMapToNullable(schema); | ||||||||||||||||||||
| Schema result = processNormalize31Spec(schema, new HashSet<>()); | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: normalizeMapSchema now returns a possibly-replaced schema from processNormalize31Spec, but the map branch at normalizeSchema() discards that return value ( Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: normalizeMapSchema now wraps processNormalize31Spec, which can return a brand-new Schema instance (the empty-JsonSchema branch returns Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Maps whose parent omits Prompt for AI agents
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Schemas that omit an explicit Prompt for AI agents
Suggested change
|
||||||||||||||||||||
| return processSetMapToNullable(result); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| protected Schema normalizeSimpleSchema(Schema schema, Set<Schema> visitedSchemas) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Removing the
getTypes().contains("null")check fromModelUtils.isNullablesilently changes behavior for OAS 3.1type: [X, "null"]unions that have not gone through normalization: they are no longer detected as nullable (only the oneOf composed path still is). This also makes the implementation inconsistent with the method's own Javadoc, which still describes thenulltype as the 3.1 way to mark a schema nullable. The addedModelUtils.isNullable(...)usages in DefaultCodegen now depend on this behavior, so callers operating on raw/un-normalized 3.1 schemas may no longer mark such properties/parameters as nullable. Consider updating the Javadoc and confirming that every relevant path is normalized before relying on the reduced detection.Prompt for AI agents