Skip to content

Add Swagger 2.0 support and custom spec URL for api cloud#2040

Merged
jeremybeard merged 1 commit intomainfrom
add-swagger2-and-custom-spec-url
Mar 26, 2026
Merged

Add Swagger 2.0 support and custom spec URL for api cloud#2040
jeremybeard merged 1 commit intomainfrom
add-swagger2-and-custom-spec-url

Conversation

@jeremybeard
Copy link
Copy Markdown
Contributor

@jeremybeard jeremybeard commented Mar 19, 2026

Summary

  • Add Swagger 2.0 (OpenAPI 2.x) parsing support alongside existing OpenAPI 3.x — version is auto-detected
  • Add --spec-url flag on astro api cloud to override the default spec URL, with base URL derived from the spec's servers/basePath
  • Add --spec-token-env-var flag to read an auth token from a named environment variable when fetching specs that require authentication
  • Extract GetServerPath() to pull the API base path from v3 servers[0].url or v2 basePath
  • Fix circular $ref stack overflow in schema conversion

Both new flags are hidden.

Test plan

  • go test ./pkg/openapi/... — all existing + new tests pass
  • go test ./cmd/api/... — all existing + new tests pass
  • go build . compiles cleanly
  • astro api cloud --help does not show hidden flags
  • Manual: astro api cloud --spec-url <url> ls with an OpenAPI 3.0 spec
  • Manual: astro api cloud --spec-url <url> ls with a Swagger 2.0 spec
  • Manual: astro api cloud --spec-url <url> --spec-token-env-var <env> ls with an auth-protected spec

- Add Swagger 2.0 (OpenAPI 2.x) parsing support alongside existing
  OpenAPI 3.x. The spec version is auto-detected and the appropriate
  model is built. Swagger 2.0 body parameters are converted to
  RequestBody and responses are mapped with synthetic content types.
- Add --spec-url flag on `astro api cloud` to override the default
  Cloud API spec URL. The base URL for requests is derived from the
  spec's servers/basePath combined with the current context domain.
- Add --spec-token-env-var flag to provide an env var name containing
  an auth token for fetching specs that require authentication.
- Add GetServerPath() to extract the API base path from either v3
  servers[0].url or v2 basePath.
- Fix circular $ref stack overflow in schema conversion by returning
  ref names without resolving into BuildSchema().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jeremybeard jeremybeard marked this pull request as ready for review March 19, 2026 14:30
@jeremybeard jeremybeard requested a review from a team as a code owner March 19, 2026 14:30
@coveralls-official
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build eb0cffd0-70af-439f-aa8a-c59d3bc28f75

Details

  • 197 of 219 (89.95%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 36.011%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/openapi/endpoints_v2.go 108 109 99.08%
pkg/openapi/endpoints.go 22 24 91.67%
pkg/openapi/cache.go 49 55 89.09%
cmd/api/cloud.go 18 31 58.06%
Totals Coverage Status
Change from base Build 2406df93-245c-4e8a-b50a-85be1f8fb135: 0.1%
Covered Lines: 24401
Relevant Lines: 67760

💛 - Coveralls

@jeremybeard jeremybeard merged commit 2e077d7 into main Mar 26, 2026
7 of 8 checks passed
@jeremybeard jeremybeard deleted the add-swagger2-and-custom-spec-url branch March 26, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants