Repository navigation
[normalizer] Preserve AnyType for typeless OAS 3.0 schemas in referenced files - #25414
Open
josephaxisa wants to merge 3 commits into
Open
josephaxisa wants to merge 3 commits into
josephaxisa wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Author
|
cc @wing328, I updated to ensure Swagger 2.0 converted specs and existing generator samples remain untouched |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25412
Summary
When an OpenAPI 3.0 specification references an external file (such as a
PathItem,ApiResponse,Parameter,RequestBody, or a whole-file schema$refsuch as sailpoint-oss/api-specs),swagger-parser'sResolverCache.loadRefdeserializes the external node via Jackson (ModelDeserializer). BecauseModelDeserializer.useArbitrarySchemadefaults tofalse,ModelDeserializer.deserializeArbitraryOrObjectSchemainstantiates typeless schemas (description: ...with notype,properties, oradditionalProperties) asObjectSchema(type: "object"), while storing the raw parsed JSON/YAML map inschema.getJsonSchema()(where!schema.getJsonSchema().containsKey("type")).By contrast, the same typeless schema in the root OpenAPI 3.0 document is parsed by
OpenAPIDeserializerviaSchemaTypeUtil.createSchemaByType(node)into a baseSchemainstance (type == null), which OpenAPI Generator maps toAnyType.Changes
OpenAPINormalizer.java:normalizeSimpleSchema(Schema schema, Set<Schema> visitedSchemas)(reached only after confirming the schema is not an array, not aComposedSchema, has noproperties, and has noSchemaadditionalProperties), check whether anObjectSchemahas a rawjsonSchemamap without"type"or"properties"keys and no object-specific constraints (schema instanceof ObjectSchema && schema.getJsonSchema() != null && !schema.getJsonSchema().containsKey("type") && !schema.getJsonSchema().containsKey("properties") && schema.getProperties() == null && schema.getAdditionalProperties() == null && schema.getRequired() == null && schema.getMinProperties() == null && schema.getMaxProperties() == null && schema.getPatternProperties() == null && schema.getDiscriminator() == null && schema.getEnum() == null) and convert it to a basenew Schema<>()(type == null) with metadata and validation fields copied viaModelUtils.copyMetadata(schema, sc)(pluspattern,format,multipleOf,uniqueItems,exclusiveMinimum,exclusiveMaximum,exclusiveMinimumValue,exclusiveMaximumValue,not,xml,externalDocs, andjsonSchema), matching the OAS 3.1AnyTypehandling inprocessNormalize31Spec.normalizeSchema's array and map branches, assignresult.setItems(normalizeSchema(result.getItems(), visitedSchemas))andresult.setAdditionalProperties(normalized)so normalized arrayitemsand mapadditionalPropertiesschemas are not discarded.OpenAPINormalizerTest.java:type: object.testTypelessSchemaInReferencedFileRemainsAnyTypeverifying that typeless schemas in referenced files (via aPathItemresponse, a whole-file schema$ref, and an arrayitems$ref) normalize toAnyType(type == null,isObjectSchema == false,isFreeFormObject == false) while explicittype: objectandrequired: [id]schemas in referenced files preserve their object semantics and constraints.cc @OpenAPITools/generator-core-team
PR checklist