Skip to content

new URL(path, baseUrl) incorrectly resolves paths when spec uses a relative server URL with a path prefix #1

Description

@byrnereese

Version: 0.3.0

Description:
When an OpenAPI spec defines a relative server URL with a path (e.g. servers: [{url: "/api/v1"}]) and --base-url is set to the full host (e.g. https://example.com/api/v1), buildUrl() in request-builder.js uses new URL(path, baseUrl). Because spec paths begin with / (e.g. /initiatives), JavaScript's URL constructor treats them as absolute paths and discards the base URL's path, producing https://example.com/initiatives instead of https://example.com/api/v1/initiatives.

Fix:
In request-builder.js, replace:
jsconst url = new URL(path, baseUrl);
with:
jsconst url = new URL(baseUrl.replace(/\/$/, "") + path);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions