Skip to content

Comments

fix: resolve $ref in x-amazon-apigateway-integration (fixes #6045)#8648

Open
dcabib wants to merge 1 commit intoaws:developfrom
dcabib:fix/issue-6045-ref-resolution
Open

fix: resolve $ref in x-amazon-apigateway-integration (fixes #6045)#8648
dcabib wants to merge 1 commit intoaws:developfrom
dcabib:fix/issue-6045-ref-resolution

Conversation

@dcabib
Copy link
Contributor

@dcabib dcabib commented Feb 12, 2026

Which issue(s) does this change fix?

#6045

Why is this change necessary?

When using $ref in x-amazon-apigateway-integration (which is valid per OpenAPI 3.0 spec), sam local start-api crashes with AttributeError: '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 because get("type") returns None.

How does it address the issue?

Added JSON Reference ($ref) resolution to SwaggerParser in samcli/commands/local/lib/swagger/parser.py. Before checking for type, the code now resolves the reference to get the actual integration config.

The implementation handles:

  • Local JSON Pointer refs (#/path/to/object)
  • Nested refs (a ref pointing to another ref)
  • Circular ref detection (logs warning and skips)
  • 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 added $ref resolution 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 $ref are 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

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.
@dcabib dcabib requested a review from a team as a code owner February 12, 2026 12:32
@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant