orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. šŸŗ
https://orval.dev
MIT License
3.07k stars 334 forks source link

localhost:PORT isn't recognized as a valid url #219

Closed davidsonsns closed 3 years ago

davidsonsns commented 3 years ago

What are the steps to reproduce this issue?

  1. swagger spec being delivered at http://localhost:6001/swagger/v1/swagger.json
  2. adds the target like below
  3. try to run orval
...
input: {
      target: 'http://localhost:6001/swagger/v1/swagger.json',
...

What happens?

validator.js doesn't recognize localhost:${PORT} as a valid URL and ORVAL concatenates it with the current path and throws the exception below:

ResolverError: Error opening file "/Users/myusername/myprojectfolder/http:/localhost:6001/swagger/v1/swagger.json"
ENOENT: no such file or directory, open '/Users/myusername/myprojectfolder/http:/localhost:6001/swagger/v1/swagger.json'
error Command failed with exit code 1.

What were you expecting to happen?

recognize localhost as a valid URL

Any other comments?

found a couple of PR opened on validator.js repository regarding this behavior: https://github.com/validatorjs/validator.js/issues?q=isurl+localhost so, my guess is that we could improve it if (isString(path) && !isUrl(path)) { to if (isString(path) && !isUrl(path, { require_tld: false })) {

What versions are you using?

Operating System: macOS Big Sur Version 11.6 Package Version: ^6.1.1 Browser Version: ā€¦

anymaniax commented 3 years ago

@davidsonsns nice investigation. Do you open a pull request for that changes?

davidsonsns commented 3 years ago

@anymaniax I was opening rn šŸ˜… plz let me know ur thots

sdindu commented 1 year ago

@anymaniax I was opening rn šŸ˜… plz let me know ur thots

I am still getting this error today api - Error: ENOENT: no such file or directory, open 'C:\Users\xxx\source\repos\ABC\Sample\src\ABC.Sample.ClientApp\https:\localhost:7108\swagger\v1\swagger.json'

melloware commented 1 year ago

I have updated this again and I think it fixes all scenarios: https://github.com/anymaniax/orval/pull/1032