fix: resolve $ref in x-amazon-apigateway-integration (fixes #6045)#8648
Open
dcabib wants to merge 1 commit intoaws:developfrom
Open
fix: resolve $ref in x-amazon-apigateway-integration (fixes #6045)#8648dcabib wants to merge 1 commit intoaws:developfrom
dcabib wants to merge 1 commit intoaws:developfrom
Conversation
Add JSON Reference ($ref) resolution support to SwaggerParser to handle OpenAPI 3.0 documents that use $ref in x-amazon-apigateway-integration. The implementation handles: - Local JSON Pointer refs (#/path/to/object) - Nested refs (a ref pointing to another ref) - Circular ref detection with warning - Depth limiting (max 10 levels) - External refs (URLs/files) - logged as warning, not supported in local mode - JSON Pointer escaping (~0 for ~, ~1 for /) per RFC 6901 Also resolves $ref in paths, method configs, and security schemes/authorizers. Includes 37 new unit tests covering all edge cases.
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.
Which issue(s) does this change fix?
#6045
Why is this change necessary?
When using
$refinx-amazon-apigateway-integration(which is valid per OpenAPI 3.0 spec),sam local start-apicrashes withAttributeError: 'NoneType' object has no attribute 'lower'.The parser receives
{"$ref": "#/components/..."}instead of the actual integration config, and when it tries to call.get("type").lower(), it fails becauseget("type")returnsNone.How does it address the issue?
Added JSON Reference (
$ref) resolution toSwaggerParserinsamcli/commands/local/lib/swagger/parser.py. Before checking fortype, the code now resolves the reference to get the actual integration config.The implementation handles:
#/path/to/object)~0for~,~1for/) per RFC 6901Also added
$refresolution for paths, method configs, and security schemes/authorizers.What side effects does this change have?
None. The fix only affects documents that use
$ref- documents without$refare unaffected. External refs (URLs or file paths) are gracefully skipped with a warning since they're not supported in local mode.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changed - N/ABy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.