(base-url url server-url json)Returns the API root URL derived from the spec URL, an optional server override, and the parsed JSON spec.
Resolution order for OpenAPI (3.x) specs:
If server-url is provided and non-blank, it is used as-is when
absolute (e.g. "https://example.com"), or resolved against url
when relative (e.g. "/v3" → "http://host/v3").
Otherwise, servers[0].url from the spec is used, applying the
same absolute-vs-relative logic.
If neither is present (no :servers key in the spec), the base is
derived from the directory of url via RFC 3986 resolution:
url → origin only, e.g. "http://localhost:8888"url → parent path, e.g. "/api/spec.json" → "/api"url (e.g. "/spec.json") → "" (empty string),
which is correct because OpenAPI paths begin with "/", so
api-root + path remains a valid relative URL.For Swagger (2.x) specs, the base is always reconstructed as
scheme://host[:port] + basePath from the parsed url.
The return value never has a trailing slash.
Returns the API root URL derived from the spec URL, an optional
server override, and the parsed JSON spec.
Resolution order for OpenAPI (3.x) specs:
1. If `server-url` is provided and non-blank, it is used as-is when
absolute (e.g. "https://example.com"), or resolved against `url`
when relative (e.g. "/v3" → "http://host/v3").
2. Otherwise, `servers[0].url` from the spec is used, applying the
same absolute-vs-relative logic.
3. If neither is present (no `:servers` key in the spec), the base is
derived from the directory of `url` via RFC 3986 resolution:
- absolute `url` → origin only, e.g. "http://localhost:8888"
- relative `url` → parent path, e.g. "/api/spec.json" → "/api"
- top-level relative `url` (e.g. "/spec.json") → "" (empty string),
which is correct because OpenAPI paths begin with "/", so
api-root + path remains a valid relative URL.
For Swagger (2.x) specs, the base is always reconstructed as
scheme://host[:port] + basePath from the parsed `url`.
The return value never has a trailing slash.(openapi->handlers openapi-json content-types)(openapi->handlers openapi-json
{:keys [encodes decodes] :as _content-types}
route-name-sources)cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |