Skip to content

Support external file $ref resolution#59

Merged
cubahno merged 5 commits intodoordash-oss:mainfrom
joncanning-rvu:feature/external-ref-resolution
Mar 23, 2026
Merged

Support external file $ref resolution#59
cubahno merged 5 commits intodoordash-oss:mainfrom
joncanning-rvu:feature/external-ref-resolution

Conversation

@joncanning-rvu
Copy link
Copy Markdown
Contributor

Summary

  • Set BasePath on libopenapi's DocumentConfiguration to enable resolution of relative file $ref references (e.g. $ref: './common.yaml#/components/schemas/Address')
  • The CLI auto-detects BasePath from the spec file's parent directory; library consumers can set it via the new Configuration.BasePath field (base-path in YAML config)
  • Added tests verifying external ref resolution and end-to-end code generation with multi-file specs

Test plan

  • New test TestExternalFileRefResolution with 3 subtests: fails without BasePath, succeeds with BasePath, end-to-end code generation
  • All existing tests pass (go test ./...)
  • Manual verification with a real multi-file spec using $ref to external files

Closes #58

Set BasePath on libopenapi's DocumentConfiguration to enable resolution
of relative file references (e.g. './common.yaml#/components/schemas/Address').

The CLI auto-detects BasePath from the spec file's directory. Library
consumers can set it via the new Configuration.BasePath field.

Closes doordash-oss#58
Copy link
Copy Markdown
Collaborator

@cubahno cubahno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update documentation and json-schema file as well.

Comment thread pkg/codegen/openapi_provider.go Outdated
Comment thread pkg/codegen/external_ref_test.go Outdated
- Make LoadDocumentFromContents backwards-compatible with variadic basePath
- Validate and normalize BasePath to absolute path
- Error out (not silently ignore) if filepath.Abs fails in CLI
- Improve test assertions: check error message content, add OverwriteWith tests
- Revert unnecessary changes to existing test call sites
- Move TestExternalFileRefResolution to codegen_test.go
- Move TestBasePathOverwriteWith to configuration_test.go
- Remove standalone external_ref_test.go
- Add base-path property to configuration-schema.json
- Document base-path in docs/configuration.md with usage example
- Mention external file $ref support in README.md features list
@joncanning-rvu
Copy link
Copy Markdown
Contributor Author

Done — latest commit adds:

  • base-path property to configuration-schema.json
  • Documentation section in docs/configuration.md with usage example
  • Feature mention in README.md

@joncanning-rvu joncanning-rvu requested a review from cubahno March 23, 2026 13:12
Comment thread oapi-codegen Outdated
@cubahno
Copy link
Copy Markdown
Collaborator

cubahno commented Mar 23, 2026

Manual verification with a real multi-file spec using $ref to external files

you can try to checkout this repo, then run
make test-integration SPEC=<path-to>/with-external-refs/smartum/openapi.yml

maybe integration test has to be adjusted.
but this can be address separately i think.

thats what i see:

   1. ...ojects/specs/stash/with-external-refs/smartum/openapi.yml
      Stage: build
      Error:
        go build failed:
        # command-line-arguments
        ./generated.go:4981:8: undefined: BeneficiaryTransactionYaml
        ./generated.go:5382:8: undefined: VenueYaml
        ./generated.go:5489:8: undefined: PaymentStatusYaml
        ./generated.go:7292:71: undefined: AuthorizationCodeRequestYaml
        ./generated.go:7297:80: undefined: AuthorizationCodeRequestYaml
        ./generated.go:7311:74: undefined: AuthorizationCodeRequestYaml
        ./generated.go:7322:66: undefined: RefreshTokenRequestYaml
        ./generated.go:7327:75: undefined: RefreshTokenRequestYaml
        ./generated.go:7560:17: undefined: CheckoutRequestWithoutStripeYaml
        ./generated.go:7560:51: undefined: CheckoutRequestWithStripeYaml
        ./generated.go:7327:75: too many errors

@cubahno cubahno merged commit 5466c6c into doordash-oss:main Mar 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support external file $ref resolution

2 participants