Repository navigation
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 3 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3924,9 +3924,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo | |||||||||||||||||
| if (p.getWriteOnly() != null) { | ||||||||||||||||||
| property.isWriteOnly = p.getWriteOnly(); | ||||||||||||||||||
| } | ||||||||||||||||||
| if (ModelUtils.isNullable(p)) { | ||||||||||||||||||
| property.isNullable = true; | ||||||||||||||||||
| } else if (p.getNullable() != null) { | ||||||||||||||||||
| if (p.getNullable() != null) { | ||||||||||||||||||
|
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: OAS 3.1 properties written as Prompt for AI agents |
||||||||||||||||||
| property.isNullable = p.getNullable(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
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: OAS 2/3 properties using Prompt for AI agents
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -3978,9 +3976,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // set isNullable using nullable or x-nullable in the schema | ||||||||||||||||||
| if (ModelUtils.isNullable(referencedSchema)) { | ||||||||||||||||||
| property.isNullable = true; | ||||||||||||||||||
| } else if (referencedSchema.getNullable() != null) { | ||||||||||||||||||
| if (referencedSchema.getNullable() != null) { | ||||||||||||||||||
|
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 Prompt for AI agents |
||||||||||||||||||
| property.isNullable = referencedSchema.getNullable(); | ||||||||||||||||||
| } else if (referencedSchema.getExtensions() != null && | ||||||||||||||||||
| referencedSchema.getExtensions().containsKey(X_NULLABLE)) { | ||||||||||||||||||
|
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 Prompt for AI agents |
||||||||||||||||||
|
|
@@ -4083,9 +4079,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo | |||||||||||||||||
| if (original != null) { | ||||||||||||||||||
| p = original; | ||||||||||||||||||
| // evaluate common attributes if defined in the top level | ||||||||||||||||||
| if (ModelUtils.isNullable(p)) { | ||||||||||||||||||
| property.isNullable = true; | ||||||||||||||||||
| } else if (p.getNullable() != null) { | ||||||||||||||||||
| if (p.getNullable() != null) { | ||||||||||||||||||
| property.isNullable = p.getNullable(); | ||||||||||||||||||
| } else if (p.getExtensions() != null && p.getExtensions().containsKey(X_NULLABLE)) { | ||||||||||||||||||
| property.isNullable = (Boolean) p.getExtensions().get(X_NULLABLE); | ||||||||||||||||||
|
|
||||||||||||||||||
| 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 ModelUtils.isNullable checks from fromProperty means a property declared with OAS 3.1
type: [string, null](oroneOfcontainingtype: 'null') will no longer be marked nullable unlessnullable/x-nullableis set on the schema. Thetype: [..., null]inference was also removed from ModelUtils.isNullable, so those properties are now generated as non-nullable whenever the spec is not run through the opt-inNORMALIZE_31SPECnormalizer (and that normalizer does not handle composed oneOf-null schemas at all). For users with a 3.1 spec who don't enable the normalizer, this is a behavior regression — nullable fields that were previously generated as nullable will now lose the nullable marker. Consider preserving a fallback that sets isNullable from the schema type union / composed oneOf-null, or gating this change on the normalizer being active, so codegen doesn't silently drop nullability for un-normalized specs.Prompt for AI agents