mswjs / source

Generate MSW request handlers from various sources (HAR files, OpenAPI documents, etc).
https://source.mswjs.io
134 stars 5 forks source link

Subdirectory on a Server Object’s url field is getting cut off #58

Closed jimmymcpeter closed 1 month ago

jimmymcpeter commented 1 month ago

Description

The subdirectory on a Server Object’s url field is getting cut off.

from-open-api.ts#L55-L57

const requestUrl = isAbsoluteUrl(baseUrl)
                    ? new URL(path, baseUrl).href
                    : joinPaths(path, baseUrl);

Reproduction steps

api-schema.json

"servers": [
    {
      "url": "https://example.com/web"
    }
  ],
  "paths": {
    "/api/v1/whoAmI": {
      "get": {
        "summary": "Who am I",
        "description": "",
        "operationId": "whoAmI",
        "responses": {
          "200": {
            ...
          }
        }
      }
    }
  },

The requestUrl const = https://example.com/api/v1/whoAmI

Expected behavior

The requestUrl const should = https://example.com/web/api/v1/whoAmI

Initial assessment

The path should be appended to the Server Object’s url field in order to construct the full URL. Calling new URL() is how it's getting cut off.

Screenshots

image

weyert commented 1 month ago

Ah interesting. We always the full path in the operations instead in servers :)

Do you fancy raising a pull request for this?

kettanaito commented 1 month ago

Thanks for reporting this, @jimmymcpeter! I've reviewed your PR, I think we're almost there.

kettanaito commented 1 month ago

Released: v0.2.1 🎉

This has been released in v0.2.1!

Make sure to always update to the latest version (npm i @mswjs/source@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.