Skip to content
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

Behavior change for relative input path in 0.26.0 #1970

Closed
bdbvb opened this issue Jan 8, 2024 · 20 comments
Closed

Behavior change for relative input path in 0.26.0 #1970

bdbvb opened this issue Jan 8, 2024 · 20 comments
Assignees

Comments

@bdbvb
Copy link

bdbvb commented Jan 8, 2024

After updating from 0.25.0 to 0.26.0, a relative path passed to the input parameter is resolved from the "node_modules@apidevtools\json-schema-ref-parser" folder instead of from the project folder where the command is being run.

Example command:

openapi --input ./openapi/swagger-design.json --output ./openapi-gen --name FooBar

It tries to read from

node_modules\@apidevtools\json-schema-ref-parse\openapi\swagger-design.json

and gives an error that it cannot find that file (because the file is actually under my project folder).

{
  stack: 'JSONParserError: Error opening file "C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json" \n' +
    "ENOENT: no such file or directory, open 'C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json'\n" +
    '    at Object.read (C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\lib\\resolvers\\file.js:59:19)',
  code: 'ERESOLVER',
  name: 'ResolverError',
  message: 'Error opening file "C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json" \n' +
    "ENOENT: no such file or directory, open 'C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json'",
  source: 'C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json',
  path: null,
  toJSON: [Function: toJSON],
  ioErrorCode: 'ENOENT',
  footprint: 'null+C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json+ERESOLVER+Error opening file "C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json" \n' +
    "ENOENT: no such file or directory, open 'C:\\Projects\\Foo\\MyProjectFolder\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\openapi\\swagger-design.json'",
  toString: [Function: toString]
}
@Spajker7
Copy link

I am also experiencing this issue

@Delevin888
Copy link

same issue.

@sander-b-postnl
Copy link

sander-b-postnl commented Jan 15, 2024

apidevtools/json-schema-ref-parse#311 the issue seems to be related to this one.

@ferdikoomen
Copy link
Owner

Seems indeed a json-schema-ref-parse issue, checking now

@ferdikoomen
Copy link
Owner

ferdikoomen commented Jan 15, 2024

Easy solution for now, would be to revert json-schema-ref-parse to 10.1.0 until they fix the issue. I will do that and publish a new release.

@ferdikoomen
Copy link
Owner

Created a new release (0.27.0) https://github.com/ferdikoomen/openapi-typescript-codegen/releases/tag/v.027.0 please check if that resolves the issue

@derBinder
Copy link

It doesn't fix the issue.

@kumv-net

This comment was marked as outdated.

@kumv-net
Copy link

json-schema-ref-parser
i use [email protected] [email protected]

@nruffing
Copy link

Looking at the RefParser.parse implementation it looks getOpenApiSpec needs to be passing in a base path for relative paths to be resolved against and the recommended use case is to pass in a full file url.

https://github.com/APIDevTools/json-schema-ref-parser/blob/main/lib/index.ts#L58

@bdbvb
Copy link
Author

bdbvb commented Feb 5, 2024

I should also note that, even if I pass an absolute path to --input, it still tries to append that to node_modules\@apidevtools\json-schema-ref-parser\dist.

The only workaround I can come up with is to use ../../../.. instead of . in front of my relative input path.

Curious how other people are getting this to work without the above hack, as otherwise the library appears to be unusable when using an input file. (Of course, downgrading is also an option, but not a nice one.)

@WillGarman
Copy link

I was on 0.27.0 when I was getting this error. Downgraded to 0.25.0, worked perfect

@mahdibx
Copy link

mahdibx commented Feb 14, 2024

We had to downgrade too, tried the absolute path and overriding to the latest version of json-schema-ref-parser (11.1.0), still it just appends the absolute path to the package folder, really odd way of handling paths, wondering how this works for anyone.

@LEI
Copy link

LEI commented Feb 20, 2024

This problem occured on Windows but not macOS, downgrading the package to 0.25 fixed it.

@StanlyLife
Copy link

StanlyLife commented Feb 26, 2024

Still not working, had to downgrade to 0.25.0

@AnderssonPeter
Copy link

Upgrading to the latest version of @apidevtools/json-schema-ref-parser seems to solve the issue? atleast in one of my test cases.

@mrlubos
Copy link
Collaborator

mrlubos commented Mar 2, 2024

@StanlyLife we've got a different fix for this in @nicolas-chaulet/openapi-typescript-codegen, could you give it a try and let me know if it works for you?

@AnderssonPeter
Copy link

@mrlubos Is there any reason why you are maintaining a fork, is this repo dead?

@mrlubos
Copy link
Collaborator

mrlubos commented Mar 2, 2024

@bdbvb
Copy link
Author

bdbvb commented Mar 21, 2024

This appears to be fixed now in 0.28.0.

@bdbvb bdbvb closed this as completed Mar 21, 2024
mpo-mjolner added a commit to Open-Pectus/Open-Pectus that referenced this issue Apr 23, 2024
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