Support relative URLs in OpenAPI servers[].url β Java (#159)#160
Merged
Conversation
Java Coverage (api / shared / jvm / android)
Files
|
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/2.0.0 #160 +/- ##
===================================================
+ Coverage 66.17% 66.66% +0.49%
- Complexity 477 480 +3
===================================================
Files 29 29
Lines 2093 2097 +4
Branches 417 415 -2
===================================================
+ Hits 1385 1398 +13
+ Misses 515 507 -8
+ Partials 193 192 -1
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. π New features to boost your workflow:
|
fklebert
added a commit
that referenced
this pull request
May 18, 2026
codecov/patch on PR #160 flagged 36.36% patch coverage on OpenApiClient.java because the previous test class verified java.net.URI.resolve() in isolation β the production method's branches (file:// fallback, URISyntaxException paths, etc.) weren't hit by any test. Refactor: * Extract resolveBaseUrl(specLocation, serverUrl) as a static package-private helper. The instance method delegates to it. * OpenApiClientBaseUrlTest now calls the static helper directly, exercising every branch including the file:// + relative warning, the malformed-URI path, and the file URI + document-relative case. * Keep one end-to-end test that constructs a real OpenApiClient from a temp-file spec so the wiring stays verified. Tests in this class: 9 -> 13. All 236 Java tests still passing.
The OpenAPI Options Interoperability section showed servers as a single βοΈ row with an example using only the historically-supported form (absolute URL with path prefix). Expand to show all three forms from OpenAPI 3.0+ (clarified in 3.2.0 Β§4.5.2.1) with concrete examples, and split the matrix row to make clear which forms are supported per client. The 'document-relative' row is marked n/a for OAServer and zswag.gen since neither consumes servers[].url at runtime β OAServer routes based on operation paths, zswag.gen emits whatever the user supplies.
Rewrites OpenApiClient.resolveBaseUrl to use java.net.URI.resolve,
which natively implements RFC 3986 Β§5.3 reference resolution.
Previous implementation handled only:
- Empty server URL (used spec origin)
- URL starting with '/' (path-only, combined with spec origin)
- Absolute URL (returned as-is)
It silently broke for document-relative forms ('.', './v2', '../v2',
bare 'v2') β the else-branch returned them unchanged, producing
nonsense like "." concatenated with the operation path at request time.
The new implementation:
* Converts spec location to java.net.URI (http(s)://, file://, or local
path -> file URI)
* Converts server URL to java.net.URI as a reference
* Returns specBase.resolve(serverRef)
Works for all three URL forms against both HTTP and local-file spec
locations. The earlier "absolute server URL with local-file spec"
behaviour is preserved via an explicit check (avoids producing a
file:// base URL when the server URL is absolute).
OpenApiClientBaseUrlTest covers each reference form via direct URI
resolution (decoupling the test from the spec-fetch path) plus two
end-to-end tests against a real OpenApiClient using a temp-file spec.
Closes #159 (Java side; C++/Python handled in the preceding commit).
codecov/patch on PR #160 flagged 36.36% patch coverage on OpenApiClient.java because the previous test class verified java.net.URI.resolve() in isolation β the production method's branches (file:// fallback, URISyntaxException paths, etc.) weren't hit by any test. Refactor: * Extract resolveBaseUrl(specLocation, serverUrl) as a static package-private helper. The instance method delegates to it. * OpenApiClientBaseUrlTest now calls the static helper directly, exercising every branch including the file:// + relative warning, the malformed-URI path, and the file URI + document-relative case. * Keep one end-to-end test that constructs a real OpenApiClient from a temp-file spec so the wiring stays verified. Tests in this class: 9 -> 13. All 236 Java tests still passing.
44d7a53 to
1688891
Compare
β¦ver-urls # Conflicts: # README.md
Minimum allowed line rate is |
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.
Changes
Java-side implementation of #159 β support relative URLs in OpenAPI
servers[].url.OpenAPI 3.0+ (clarified in OpenAPI 3.2.0 Β§4.5.2.1) permits three URL forms in
servers[].url:https://api.example.com/v1/v1scheme://host+/v1.,./v2,../v2,v2Implementation
Java β
java.net.URI.resolvedoes the workOpenApiClient.resolveBaseUrlis rewritten to usespecUri.resolve(serverRef). The JDK already implements RFC 3986 Β§5.3.servers[serverIndex].url, defaulting to"/"for an absent/emptyserversarray per Β§4.7.5) and a package-private static resolver so tests can exercise each branch directly.serverIndexmulti-server selection from Support Multiple servers Β #113 β the rebase onto currentjzswagresolves the overlap inresolveBaseUrland merges both features' README sections.file://spec locations.Tests
OpenApiClientBaseUrlTest(13 tests) covering all three URL forms plus edge cases.Merge order
#162 β
main(release for #159) β mergemainintojzswagβ this PR. The README feature matrix added here claims document-relative support for C++/Python, which holds oncejzswagcontains the #162 changes.