Q42 / openapi-typescript-validator

Generate typescript with ajv validation based on openapi schemas
26 stars 14 forks source link

Using Reference in OpenAPI-Spec to file in the same directory does not work as expected #20

Open LoeFe opened 1 year ago

LoeFe commented 1 year ago

The openapi-typescript-validator works very well for single-file openapi-specs. Thanks for the cool tool! 👍

But: When I split the openapi-spec into multiple files as described in the openapi 3.0 spec with "$ref: my2ndFile.yaml" I receive an ENOENT error. This is becasue the generator is searching in the cwd of the node-process, which is "project_root/validator" and not relatively to the interface-file, that I hand over to generate-function of the openapi-typescript-validator.

As far as I understood the code, the root cause is, "DEFAULT_OPTIONS.cwd" of json-schema-to-typescript package is pointing to process.cwd(). It could have been overwritten when calling compile, but options are not set.

https://github.com/Q42/openapi-typescript-validator/blob/571cd8caffba08a0f84d7f8a220602b4a9a20497/src/generate/generate-models.ts#L14

The file structure in my project is as follows:

├── project_root │ ├── validator │ │ ├── generator.js │ ├── openApiSpec │ │ ├── interface.yaml │ │ ├── my2ndFile.yaml

LoeFe commented 1 year ago

This issue seems to be closely related to #11