As you want to create multiple Datasource with OpenAPI connector, the Validator seems mixed them up.
Steps to regenerate this issue Multiple OpenAPI Usage.
Steps to Reproduce
-
git clone https://github.com/vhidvz/loopback-next.git
-
cd loopback-next/examples/mutiple-openapis-usage
-
MongoDB database (if you need):
docker run --name some-mongo -p 27017:27017 -d mongo:4.2
-
node deployOtherServices.js
-
npm install && npm run test
Current Behavior
It does looking for #/components/schemas/Session $ref in the User OpenApi.json file. But, it does never defined at this endpoint. Issue
Additional Information
OS:
$ lsb_release -a
LSB Version: n/a
Distributor ID: ManjaroLinux
Description: Manjaro Linux
Release: 18.1.5
Codename: Juhraya
NODE:
LB4:
$ lb4 --version
@loopback/cli version: 1.29.0
@loopback/* dependencies:
- @loopback/authentication: ^3.3.1
- @loopback/boot: ^1.7.2
- @loopback/build: ^3.1.0
- @loopback/context: ^2.0.0
- @loopback/core: ^1.12.2
- @loopback/metadata: ^1.4.0
- @loopback/openapi-spec-builder: ^1.3.0
- @loopback/openapi-v3: ^1.12.0
- @loopback/repository-json-schema: ^1.12.0
- @loopback/repository: ^1.18.0
- @loopback/rest: ^1.26.0
- @loopback/testlab: ^1.10.2
- @loopback/docs: ^2.9.0
- @loopback/example-hello-world: ^1.2.23
- @loopback/example-log-extension: ^1.2.23
- @loopback/example-rpc-server: ^1.2.23
- @loopback/example-todo: ^1.9.5
- @loopback/example-soap-calculator: ^1.7.5
- @loopback/service-proxy: ^1.3.15
- @loopback/http-caching-proxy: ^1.2.5
- @loopback/http-server: ^1.5.2
- @loopback/example-todo-list: ^1.12.5
- @loopback/dist-util: ^0.4.0
- @loopback/rest-explorer: ^1.4.8
- @loopback/eslint-config: ^5.0.2
- @loopback/example-express-composition: ^1.10.2
- @loopback/example-greeter-extension: ^1.3.23
- @loopback/booter-lb3app: ^1.3.10
- @loopback/example-lb3-application: ^1.1.24
- @loopback/example-greeting-app: ^1.2.10
- @loopback/example-context: ^1.3.0
- @loopback/repository-tests: ^0.9.1
- @loopback/extension-health: ^0.2.15
- @loopback/authorization: ^0.4.8
- @loopback/rest-crud: ^0.6.4
- @loopback/security: ^0.1.11
- @loopback/authentication-passport: ^1.1.1
- @loopback/example-metrics-prometheus: ^0.1.5
- @loopback/extension-metrics: ^0.1.4
- @loopback/model-api-builder: ^1.1.2
Seems, It does looking for #/components/schemas/Session in the User OpenApi.json file. But, it does never defined at this endpoint.
> mutiple-openapis-usage@1.0.0 prestart /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
> npm run build
> mutiple-openapis-usage@1.0.0 build /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
> lb-tsc
> mutiple-openapis-usage@1.0.0 start /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
> node -r source-map-support/register .
Server is running at http://[::1]:3000
Try http://[::1]:3000/ping
Connection fails: SyntaxError: Error resolving $ref pointer "http://[::1]:3010/openapi.json#/components/schemas/Session".
Token "Session" does not exist.
It will be retried for the next request.
/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/pointer.js:87
throw ono.syntax('Error resolving $ref pointer "%s". \nToken "%s" does not exist.', this.originalPath, token);
^
SyntaxError: Error resolving $ref pointer "http://[::1]:3010/openapi.json#/components/schemas/Session".
Token "Session" does not exist.
at Pointer.resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/pointer.js:87:17)
at $Ref.resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/ref.js:83:18)
at $Refs._resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/refs.js:155:15)
at dereference$Ref (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:99:23)
at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:58:26
at Array.forEach (<anonymous>)
at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24)
at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28
at Array.forEach (<anonymous>)
at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24)
at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28
at Array.forEach (<anonymous>)
at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24)
at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28
at Array.forEach (<anonymous>)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mutiple-openapis-usage@1.0.0 start: `node -r source-map-support/register .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mutiple-openapis-usage@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vahid/.npm/_logs/2020-01-28T08_13_01_223Z-debug.log
Debug File Context: vahid/.npm/_logs/2020-01-28T08_13_01_223Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@6.13.6
3 info using node@v13.7.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle mutiple-openapis-usage@1.0.0~prestart: mutiple-openapis-usage@1.0.0
6 verbose lifecycle mutiple-openapis-usage@1.0.0~prestart: unsafe-perm in lifecycle true
7 verbose lifecycle mutiple-openapis-usage@1.0.0~prestart: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/.bin:/home/vahid/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
8 verbose lifecycle mutiple-openapis-usage@1.0.0~prestart: CWD: /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
9 silly lifecycle mutiple-openapis-usage@1.0.0~prestart: Args: [ '-c', 'npm run build' ]
10 silly lifecycle mutiple-openapis-usage@1.0.0~prestart: Returned: code: 0 signal: null
11 info lifecycle mutiple-openapis-usage@1.0.0~start: mutiple-openapis-usage@1.0.0
12 verbose lifecycle mutiple-openapis-usage@1.0.0~start: unsafe-perm in lifecycle true
13 verbose lifecycle mutiple-openapis-usage@1.0.0~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/.bin:/home/vahid/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
14 verbose lifecycle mutiple-openapis-usage@1.0.0~start: CWD: /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
15 silly lifecycle mutiple-openapis-usage@1.0.0~start: Args: [ '-c', 'node -r source-map-support/register .' ]
16 silly lifecycle mutiple-openapis-usage@1.0.0~start: Returned: code: 1 signal: null
17 info lifecycle mutiple-openapis-usage@1.0.0~start: Failed to exec start script
18 verbose stack Error: mutiple-openapis-usage@1.0.0 start: `node -r source-map-support/register .`
18 verbose stack Exit status 1
18 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
18 verbose stack at EventEmitter.emit (events.js:321:20)
18 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
18 verbose stack at ChildProcess.emit (events.js:321:20)
18 verbose stack at maybeClose (internal/child_process.js:1026:16)
18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
19 verbose pkgid mutiple-openapis-usage@1.0.0
20 verbose cwd /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage
21 verbose Linux 5.4.14-2-MANJARO
22 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
23 verbose node v13.7.0
24 verbose npm v6.13.6
25 error code ELIFECYCLE
26 error errno 1
27 error mutiple-openapis-usage@1.0.0 start: `node -r source-map-support/register .`
27 error Exit status 1
28 error Failed at the mutiple-openapis-usage@1.0.0 start script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]
All steps are going done with @loopback/cli version: 1.29.0.
Under examples/multiple-openapis-usage directory. (PORT: 3000)
Other API Services:
Step 1\4. lb4 app
? Project name: mutiple-openapis-usage
? Project description: mutiple openapis usage
? Project root directory: mutiple-openapis-usage
? Application class name: MutipleOpenapisUsageApplication
? Select features to enable in the project (Press <space> to select, <a> to togg
le all, <i> to invert selection)Enable eslint, Enable prettier, Enable mocha, En
able loopbackBuild, Enable vscode, Enable docker, Enable repositories, Enable se
rvices
Step 2\4. lb4 model login
? Please select the model base class Model (A business domain object)
? Allow additional (free-form) properties? No
Model Login will be created in src/models/login.model.ts
Let's add a property to Login
Enter an empty property name when done
? Enter the property name: username
? Property type: string
? Is username the ID property? No
? Is it required?: Yes
? Default value [leave blank for none]:
Let's add another property to Login
Enter an empty property name when done
? Enter the property name: password
? Property type: string
? Is password the ID property? No
? Is it required?: Yes
? Default value [leave blank for none]:
Let's add another property to Login
Enter an empty property name when done
? Enter the property name:
create src/models/login.model.ts
update src/models/index.ts
Model Login was created in src/models/
Step 3\4. lb4 datasource users
? Select the connector for users: OpenAPI (supported by StrongLoop)
? HTTP URL/path to Swagger spec file (file name extension .yaml/.yml or .json):
http://[::1]:3010/openapi.json
? Validate spec against Swagger spec 2.0?: No
? Security config for making authenticated requests to API:
? Use positional parameters instead of named parameters?: No
create src/datasources/users.datasource.config.json
create src/datasources/users.datasource.ts
Step 4\4. lb4 datasource sessions
? Select the connector for sessions: OpenAPI (supported by StrongLoop)
? HTTP URL/path to Swagger spec file (file name extension .yaml/.yml or .json):
http://[::1]:3020/openapi.json
? Validate spec against Swagger spec 2.0?: No
? Security config for making authenticated requests to API:
? Use positional parameters instead of named parameters?: No
create src/datasources/sessions.datasource.config.json
create src/datasources/sessions.datasource.ts
update src/datasources/index.ts
Datasource Sessions was created in src/datasources/
Final Step.
export PORT=3000 && npm start
Under examples/multiple-openapis-usage/loopback-openapis directory. (PORT: 3010)
Step 1\5. lb4 app user-api
? Project description: user-api
? Project root directory: user-api
? Application class name: UserApiApplication
? Select features to enable in the project (Press <space> to select, <a> to togg
le all, <i> to invert selection)Enable eslint, Enable prettier, Enable mocha, En
able loopbackBuild, Enable vscode, Enable docker, Enable repositories, Enable se
rvices
Step 2\5. lb4 model User
? Please select the model base class Entity (A persisted model with an ID)
? Allow additional (free-form) properties? No
Model User will be created in src/models/user.model.ts
Let's add a property to User
Enter an empty property name when done
? Enter the property name: id
? Property type: string
? Is id the ID property? Yes
? Is id generated automatically? Yes
Let's add another property to User
Enter an empty property name when done
? Enter the property name: username
? Property type: string
? Is it required?: Yes
? Default value [leave blank for none]:
Let's add another property to User
Enter an empty property name when done
? Enter the property name: password
? Property type: string
? Is it required?: Yes
? Default value [leave blank for none]:
Let's add another property to User
Enter an empty property name when done
? Enter the property name:
create src/models/user.model.ts
update src/models/index.ts
Model User was created in src/models/
Step 3\5. lb4 datasource db
? Select the connector for db: MongoDB (supported by StrongLoop)
? Connection String url to override other settings (eg: mongodb://username:passw
ord@hostname:port/database): mongodb://localhost:27017/users
? host: localhost
? port: 27017
? user:
? password: [hidden]
? database: users
? Feature supported by MongoDB v3.1.0 and above: Yes
create src/datasources/db.datasource.config.json
create src/datasources/db.datasource.ts
Step 4\5. lb4 repository
? Please select the datasource DbDatasource
? Select the model(s) you want to generate a repository User
? Please select the repository base class DefaultCrudRepository (Legacy juggler
bridge)
create src/repositories/user.repository.ts
update src/repositories/index.ts
Repository UserRepository was created in src/repositories/
Step 5\5. lb4 controller
? Controller class name: User
Controller User will be created in src/controllers/user.controller.ts
? What kind of controller would you like to generate? REST Controller with CRUD
functions
? What is the name of the model to use with this CRUD repository? User
? What is the name of your CRUD repository? UserRepository
? What is the name of ID property? id
? What is the type of your ID? string
? Is the id omitted when creating a new instance? No
? What is the base HTTP path name of the CRUD operations? /users
create src/controllers/user.controller.ts
update src/controllers/index.ts
Controller User was created in src/controllers/
Final Step.
export PORT=3010 && npm start
Under examples/multiple-openapis-usage/loopback-openapis directory. (PORT: 3020)
Step 1\5. lb4 app session-api
? Project description: session-api
? Project root directory: session-api
? Application class name: SessionApiApplication
? Select features to enable in the project (Press <space> to select, <a> to togg
le all, <i> to invert selection)Enable eslint, Enable prettier, Enable mocha, En
able loopbackBuild, Enable vscode, Enable docker, Enable repositories, Enable se
rvices
Step 2\5. lb4 model Session
? Please select the model base class Entity (A persisted model with an ID)
? Allow additional (free-form) properties? Yes
Model Session will be created in src/models/session.model.ts
Let's add a property to Session
Enter an empty property name when done
? Enter the property name: id
? Property type: string
? Is id the ID property? Yes
? Is id generated automatically? Yes
Let's add another property to Session
Enter an empty property name when done
? Enter the property name:
create src/models/session.model.ts
update src/models/index.ts
Model Session was created in src/models/
Step 3\5. lb4 datasource db
? Select the connector for db: MongoDB (supported by StrongLoop)
? Connection String url to override other settings (eg: mongodb://username:passw
ord@hostname:port/database): mongodb://localhost:27017/sessions
? host: localhost
? port: 27017
? user:
? password: [hidden]
? database: sessions
? Feature supported by MongoDB v3.1.0 and above: Yes
create src/datasources/db.datasource.config.json
create src/datasources/db.datasource.ts
Step 4\5. lb4 repository
? Please select the datasource DbDatasource
? Select the model(s) you want to generate a repository Session
? Please select the repository base class DefaultCrudRepository (Legacy juggler
bridge)
create src/repositories/session.repository.ts
update src/repositories/index.ts
Repository SessionRepository was created in src/repositories/
Step 5\5. lb4 controller
? Controller class name: Session
Controller Session will be created in src/controllers/session.controller.ts
? What kind of controller would you like to generate? REST Controller with CRUD
functions
? What is the name of the model to use with this CRUD repository? Session
? What is the name of your CRUD repository? SessionRepository
? What is the name of ID property? id
? What is the type of your ID? string
? Is the id omitted when creating a new instance? No
? What is the base HTTP path name of the CRUD operations? /sessions
create src/controllers/session.controller.ts
update src/controllers/index.ts
Controller Session was created in src/controllers/
Final Step.
export PORT=3020 && npm start
As you want to create multiple Datasource with OpenAPI connector, the Validator seems mixed them up.
Steps to regenerate this issue Multiple OpenAPI Usage.
Steps to Reproduce
git clone https://github.com/vhidvz/loopback-next.gitcd loopback-next/examples/mutiple-openapis-usageMongoDB database (if you need):
docker run --name some-mongo -p 27017:27017 -d mongo:4.2node deployOtherServices.jsnpm install && npm run testCurrent Behavior
It does looking for #/components/schemas/Session $ref in the User OpenApi.json file. But, it does never defined at this endpoint. Issue
Additional Information
OS:
NODE:
LB4:
Issue
Seems, It does looking for #/components/schemas/Session in the User OpenApi.json file. But, it does never defined at this endpoint.
> mutiple-openapis-usage@1.0.0 prestart /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage > npm run build > mutiple-openapis-usage@1.0.0 build /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage > lb-tsc > mutiple-openapis-usage@1.0.0 start /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage > node -r source-map-support/register . Server is running at http://[::1]:3000 Try http://[::1]:3000/ping Connection fails: SyntaxError: Error resolving $ref pointer "http://[::1]:3010/openapi.json#/components/schemas/Session". Token "Session" does not exist. It will be retried for the next request. /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/pointer.js:87 throw ono.syntax('Error resolving $ref pointer "%s". \nToken "%s" does not exist.', this.originalPath, token); ^ SyntaxError: Error resolving $ref pointer "http://[::1]:3010/openapi.json#/components/schemas/Session". Token "Session" does not exist. at Pointer.resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/pointer.js:87:17) at $Ref.resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/ref.js:83:18) at $Refs._resolve (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/refs.js:155:15) at dereference$Ref (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:99:23) at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:58:26 at Array.forEach (<anonymous>) at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24) at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28 at Array.forEach (<anonymous>) at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24) at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28 at Array.forEach (<anonymous>) at crawl (/home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:51:24) at /home/vahid/WorkSpace/loopback-next/examples/mutiple-openapis-usage/node_modules/json-schema-ref-parser/lib/dereference.js:64:28 at Array.forEach (<anonymous>) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! mutiple-openapis-usage@1.0.0 start: `node -r source-map-support/register .` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the mutiple-openapis-usage@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/vahid/.npm/_logs/2020-01-28T08_13_01_223Z-debug.logDebug File Context:
vahid/.npm/_logs/2020-01-28T08_13_01_223Z-debug.logMultiple OpenAPI Usage
All steps are going done with @loopback/cli version: 1.29.0.
Under examples/multiple-openapis-usage directory. (PORT: 3000)
Other API Services:
Step 1\4.
lb4 appStep 2\4.
lb4 model loginStep 3\4.
lb4 datasource usersStep 4\4.
lb4 datasource sessionsFinal Step.
User Api Configuration
Under examples/multiple-openapis-usage/loopback-openapis directory. (PORT: 3010)
Step 1\5.
lb4 app user-apiStep 2\5.
lb4 model UserStep 3\5.
lb4 datasource dbStep 4\5.
lb4 repositoryStep 5\5.
lb4 controllerFinal Step.
Session Api Configuration
Under examples/multiple-openapis-usage/loopback-openapis directory. (PORT: 3020)
Step 1\5.
lb4 app session-apiStep 2\5.
lb4 model SessionStep 3\5.
lb4 datasource dbStep 4\5.
lb4 repositoryStep 5\5.
lb4 controllerFinal Step.