Skip to content

typegen Invalid URL error #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chrber04 opened this issue Jan 16, 2023 · 10 comments
Closed

typegen Invalid URL error #145

chrber04 opened this issue Jan 16, 2023 · 10 comments

Comments

@chrber04
Copy link

Hi, I've been trying to get typegen to work for a while now but I constantly get this error:

DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
node:internal/errors:491
    ErrorCaptureStackTrace(err);
    ^
TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:400:5)
    at URL.onParseError (node:internal/url:565:9)
    at new URL (node:internal/url:645:5)
... more

I installed typegen by running npm

install -g openapi-client-axios-typegen

And I've tried multiple variations of running typegen, with a local file and the remote URL in the README.md documentation. So:

typegen ./openapi.yml
typegen ./openapi.yml > client.d.ts
typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml > client.d.ts

They all give me the same exact "[ERR_INVALID_URL]" error. Am I doing something wrong?

Thanks!

@anttiviljami
Copy link
Member

Hi @chrber04 these commands all work fine for me with the latest version of typegen.

$ typegen --version
6.1.4
$ typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
# ...
export type Client = OpenAPIClient<OperationMethods, PathsDictionary>

Are you on Windows?

Can you try with npx:

npx openapi-client-axios-typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

Or with specific version

npx [email protected] https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

@adrien-powder
Copy link

adrien-powder commented Jan 19, 2023

Hello, same here. Tested on node v18 & v16.

$ npx [email protected] https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createTypeAliasDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createModuleDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
node:internal/errors:478
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:387:5)
    at URL.onParseError (node:internal/url:565:9)
    at new URL (node:internal/url:641:5)
    at Object.resolve (<private>\node_modules\@anttiviljami\json-schema-ref-parser\lib\util\url.js:36:21)
    at $RefParser.parse (<private>\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:103:19)
    at $RefParser.resolve (<private>\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:184:16)
    at $RefParser.dereference (<private>\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:268:16)
    at Function.dereference (<private>\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:250:31)
    at OpenAPIClientAxios.<anonymous> (<private>\node_modules\openapi-client-axios-typegen\node_modules\openapi-client-axios\client.js:163:79)
    at step (<private>\node_modules\openapi-client-axios-typegen\node_modules\openapi-client-axios\client.js:44:23) {
  input: '',
  code: 'ERR_INVALID_URL'
}

Also, I'm on Windows :)

@adrien-powder
Copy link

Fixed the problem on a fork. adrien-powder/json-schema-ref-parser@494bb14

@BoldizsarP
Copy link

The problem still persists for me.

@anttiviljami
Copy link
Member

I've replaced SwaggerParser with a much simpler implementation of dereference-json-schema

openapi-client-axios@>=7.0.0 should be much simpler to build for React Native and browser without the need for polyfills. 🙌

@BoldizsarP @chrber04 @adrien-powder

@conradkirschner
Copy link

I am facing the same problem, was it fixed?

@JoshuaTheMiller
Copy link

Hey @anttiviljami! This problem seems to still be occurring, or perhaps it is simply operator error on my part 🤔 Either way it looks like a few folks would appreciate some solution around this still!

Details

Property Value
Operating System Windows 11
Node Version 18.15.0
openapi-client-axios-typegen version 7.1.3

Test

Running the following two commands results in an error (shown below):

  1. npm install [email protected] -g -y
  2. typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
PS F:\Cloud Storage\SourceControl\sync-bot-ts> typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createTypeAliasDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createModuleDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:399:5)
    at URL.onParseError (node:internal/url:566:9)
    at new URL (node:internal/url:646:5)
    at Object.resolve (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\@anttiviljami\json-schema-ref-parser\lib\util\url.js:36:21)
    at $RefParser.parse (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:103:19)
    at $RefParser.resolve (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:184:16)
    at $RefParser.dereference (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:268:16)
    at Function.dereference (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\@anttiviljami\json-schema-ref-parser\lib\index.js:250:31)
    at OpenAPIClientAxios.<anonymous> (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\openapi-client-axios\client.js:163:79)
    at step (C:\ProgramData\nvm\v18.15.0\node_modules\openapi-client-axios-typegen\node_modules\openapi-client-axios\client.js:44:23) {
  input: '',
  code: 'ERR_INVALID_URL'
}

Node.js v18.15.0

@JoshuaTheMiller
Copy link

JoshuaTheMiller commented Mar 13, 2023

Ah. this actually seems to be a problem with the underlying URL class from Node itself... Perhaps not an issue, but rather a misuse of it (I'm still digging into this myself)?

For example, simply running the following snippet on Windows fails:

const to = "./openapi.yaml";
const fromPath = "C:\\";
let resolvedUrl = new URL(to, new URL(fromPath, "resolve://"));  
console.log(resolvedUrl)

@JoshuaTheMiller
Copy link

JoshuaTheMiller commented Mar 13, 2023

Wrapping the following block of code (which I believe is from this library) "fixed" the problem:

image

This Issue could be related: APIDevTools/json-schema-ref-parser#311

@paulwer
Copy link

paulwer commented Apr 4, 2023

problem still exists. any updates?

adrien-powder/json-schema-ref-parser@494bb14
-> worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants