Skip to content

lb4 openapi generator returns ResolverError when main spec contains schemas in subfolders #6963

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

Open
manchuwook opened this issue Dec 29, 2020 · 7 comments
Assignees
Labels
bug CLI developer-experience Issues affecting ease of use and overall experience of LB users OpenAPI

Comments

@manchuwook
Copy link

Steps to reproduce

Created a default template OpenAPI spec using subfolders via Stoplight Studio

Current Behavior

command in models folder:
lb4 openapi --path ./models/openapi-spec.v1.json

Returns error:
Generation is aborted: ResolverError: Error opening file "c:\path\to\spec\models\subfolder-model.schema.v1.json"
ENOENT: no such file or directory, open 'c:\path\to\spec\models\subfolder-model.schema.v1.json'

Expected Behavior

I expect it to properly resolve relative links to the spec (not the src/root folder)

Link to reproduction sandbox

https://github.com/manchuwook/loopback-bug-subfolder for OpenAPI spec

@manchuwook manchuwook added the bug label Dec 29, 2020
@achrinza achrinza added CLI OpenAPI developer-experience Issues affecting ease of use and overall experience of LB users labels Dec 29, 2020
@dhmlau
Copy link
Member

dhmlau commented Jan 7, 2021

@manchuwook, i believe you need to run it at the root of the LoopBack application.
When I run it inside the src folder, I got the same error as you. However, if I go back to the root folder and use lb4 openapi --url ./src/models/myopenapi.json, it works fine. Hope it helps.

@dhmlau dhmlau self-assigned this Jan 7, 2021
@manchuwook
Copy link
Author

I have been running it from the root of the loopback app. I first started by trying to refer to the schema by absolute path, then relative to the project, then copied the schema into a folder called "model"

None of these worked as intended.

@dhmlau
Copy link
Member

dhmlau commented Jan 8, 2021

What's your node.js version and the @loopback/cli version?

@manchuwook
Copy link
Author

manchuwook commented Jan 8, 2021

Sure!

lb4 --version

  - @loopback/authentication: ^7.0.5
  - @loopback/boot: ^3.1.2
  - @loopback/build: ^6.2.8
  - @loopback/context: ^3.13.2
  - @loopback/core: ^2.13.1
  - @loopback/metadata: ^3.0.5
  - @loopback/openapi-spec-builder: ^3.0.3   
  - @loopback/openapi-v3: ^5.1.2
  - @loopback/repository-json-schema: ^3.2.0 
  - @loopback/repository: ^3.3.0
  - @loopback/rest: ^9.1.1
  - @loopback/testlab: ^3.2.10
  - @loopback/docs: ^3.20.0
  - @loopback/example-hello-world: ^2.1.15   
  - @loopback/example-log-extension: ^2.1.15 
  - @loopback/example-rpc-server: ^2.1.15    
  - @loopback/example-todo: ^3.9.2
  - @loopback/example-soap-calculator: ^2.4.8
  - @loopback/service-proxy: ^3.0.5
  - @loopback/http-caching-proxy: ^2.1.19    
  - @loopback/http-server: ^2.3.3
  - @loopback/example-todo-list: ^3.7.0      
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^3.0.5
  - @loopback/eslint-config: ^10.0.4
  - @loopback/example-express-composition: ^2.5.3
  - @loopback/example-greeter-extension: ^2.1.15
  - @loopback/booter-lb3app: ^2.2.15
  - @loopback/example-lb3-application: ^2.5.3
  - @loopback/example-greeting-app: ^2.2.13
  - @loopback/example-context: ^2.1.15
  - @loopback/repository-tests: ^0.15.0
  - @loopback/health: ^0.6.2
  - @loopback/authorization: ^0.7.5
  - @loopback/rest-crud: ^0.8.19
  - @loopback/security: ^0.3.5
  - @loopback/authentication-passport: ^3.0.5
  - @loopback/example-metrics-prometheus: ^0.4.5
  - @loopback/metrics: ^0.5.2
  - @loopback/model-api-builder: ^2.1.19
  - @loopback/logging: ^0.4.5
  - @loopback/example-access-control-migration: ^2.3.3
  - @loopback/example-file-transfer: ^1.5.8
  - @loopback/example-rest-crud: ^1.7.3
  - @loopback/apiconnect: ^0.5.5
  - @loopback/example-validation-app: ^1.8.3
  - @loopback/cron: ^0.3.5
  - @loopback/example-multi-tenancy: ^0.7.3
  - @loopback/example-passport-login: ^1.9.0
  - @loopback/authentication-jwt: ^0.7.5
  - @loopback/context-explorer: ^0.2.5
  - @loopback/express: ^3.1.1
  - @loopback/example-todo-jwt: ^1.4.3
  - @loopback/mock-oauth2-provider: ^0.1.13
  - @loopback/pooling: ^0.3.5
  - @loopback/typeorm: ^0.2.5
  - @loopback/example-graphql: ^0.1.5
  - @loopback/graphql: ^0.2.3
  - @loopback/filter: ^1.3.0
  - @loopback/rest-msgpack: ^0.2.4
  - @loopback/example-binding-resolution: ^0.1.3
  - @loopback/example-webpack: ^0.2.2
  - @loopback/example-socketio: ^0.1.2
  - @loopback/socketio: ^0.1.2
  - @loopback/monorepo: ^0.1.2

node --version

v12.12.0

npm view @loopback/cli

@loopback/[email protected] | MIT | deps: 40 | versions: 198
Yeoman generator for LoopBack 4
https://github.com/strongloop/loopback-next/tree/master/packages/cli

@manchuwook
Copy link
Author

manchuwook commented Feb 11, 2021

Tested this with 2.19.0 - still have the same issue:

? Enter the OpenAPI spec url or file path: S:\dev\project\api-design\project.player.v1.json
Loading S:\dev\project\api-design\project.player.v1.json...
Generation is aborted: ResolverError: Error opening file "S:\dev\project\api-design\lb\lb\models\character.schema.v1.json" 
ENOENT: no such file or directory, open 'S:\dev\project\api-design\lb\lb\models\character.schema.v1.json'

The file is present as S:\dev\project\api-design\models\character.schema.v1.json

Note that I can get around this by bundling my API, but it creates a bunch of unnecessary/duplicated classes and muddies everything.

@manchuwook
Copy link
Author

I'm ending up building a yaml or json file using openapi-generator-cli and then generating controllers/models from that intermediary file instead.

@stale
Copy link

stale bot commented Aug 30, 2021

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Aug 30, 2021
@achrinza achrinza removed the stale label Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CLI developer-experience Issues affecting ease of use and overall experience of LB users OpenAPI
Projects
None yet
Development

No branches or pull requests

3 participants