joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
577 stars 99 forks source link

Incorrect parsing of URL containing variables #234

Closed Dragollla closed 1 year ago

Dragollla commented 1 year ago

As I mentioned in https://github.com/joolfe/postman-to-openapi/issues/136#issuecomment-1281939719, Appending 'http://' before variable results in hostname being incorrectly parsed. It leads to servers section containing invalid URL http://

> url.parse('http://{{baseUrl}}api/path')
Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: '',
  port: null,
  hostname: '',
  hash: null,
  search: null,
  query: null,
  pathname: '%7B%7BbaseUrl%7D%7Dapi/path',
  path: '%7B%7BbaseUrl%7D%7Dapi/path',
  href: 'http:///%7B%7BbaseUrl%7D%7Dapi/path'
}

I suggest using whatwg-url parser:

> new URL('http://{{baseUrl}}api/path')
URL {
  href: 'http://{{baseurl}}api/path',
  origin: 'http://{{baseurl}}api',
  protocol: 'http:',
  username: '',
  password: '',
  host: '{{baseurl}}api',
  hostname: '{{baseurl}}api',
  port: '',
  pathname: '/path',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

It happens on 2.7.1.

Dragollla commented 1 year ago

Sorry, my teammate has patched and broke library, and I didn't realize it till now