@loopback/cli 4.0.0-alpha.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yo-rc.json +1697 -0
- package/{generators/project/templates/LICENSE → LICENSE} +2 -1
- package/README.md +44 -43
- package/bin/cli-main.js +61 -0
- package/generators/app/index.js +109 -15
- package/generators/app/templates/.dockerignore +5 -0
- package/generators/app/templates/Dockerfile +28 -0
- package/generators/app/templates/README.md.ejs +130 -0
- package/generators/app/templates/public/index.html.ejs +88 -0
- package/generators/app/templates/{test → src/__tests__}/README.md +0 -1
- package/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs +31 -0
- package/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs +21 -0
- package/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs +32 -0
- package/generators/app/templates/src/application.ts.ejs +70 -0
- package/generators/app/templates/src/controllers/README.md +6 -0
- package/generators/app/templates/src/controllers/index.ts.ejs +1 -0
- package/generators/app/templates/src/controllers/ping.controller.ts.ejs +55 -0
- package/generators/app/templates/src/datasources/README.md +3 -0
- package/generators/app/templates/src/index.ts.ejs +39 -0
- package/generators/app/templates/src/migrate.ts.ejs +20 -0
- package/generators/app/templates/src/models/README.md +3 -0
- package/generators/app/templates/src/openapi-spec.ts.ejs +23 -0
- package/generators/app/templates/src/sequence.ts.ejs +3 -0
- package/generators/controller/index.js +240 -23
- package/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs +150 -0
- package/generators/controller/templates/src/controllers/{controller-template.ts → controller-template.ts.ejs} +2 -2
- package/generators/copyright/fs.js +46 -0
- package/generators/copyright/git.js +78 -0
- package/generators/copyright/header.js +306 -0
- package/generators/copyright/index.js +230 -0
- package/generators/copyright/license.js +105 -0
- package/generators/datasource/index.js +341 -0
- package/generators/datasource/templates/datasource.ts.ejs +22 -0
- package/generators/discover/import-discovered-model.js +70 -0
- package/generators/discover/index.js +349 -0
- package/generators/example/downloader.js +16 -0
- package/generators/example/index.js +176 -0
- package/generators/extension/index.js +34 -5
- package/generators/extension/templates/README.md.ejs +32 -0
- package/generators/extension/templates/{test → src/__tests__}/acceptance/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/integration/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/unit/README.md +0 -0
- package/generators/extension/templates/src/component.ts.ejs +22 -0
- package/generators/extension/templates/src/controllers/README.md +3 -2
- package/generators/extension/templates/src/decorators/README.md +10 -4
- package/generators/extension/templates/src/index.ts.ejs +3 -0
- package/generators/extension/templates/src/keys.ts.ejs +11 -0
- package/generators/extension/templates/src/mixins/README.md +77 -21
- package/generators/extension/templates/src/providers/README.md +51 -25
- package/generators/extension/templates/src/repositories/README.md +1 -1
- package/generators/extension/templates/src/types.ts.ejs +15 -0
- package/generators/import-lb3-models/index.js +197 -0
- package/generators/import-lb3-models/lb3app-loader.js +31 -0
- package/generators/import-lb3-models/migrate-model.js +249 -0
- package/generators/import-lb3-models/model-names.js +32 -0
- package/generators/interceptor/index.js +178 -0
- package/generators/interceptor/templates/interceptor-template.ts.ejs +62 -0
- package/generators/model/index.js +536 -0
- package/generators/model/property-definition.js +85 -0
- package/generators/model/templates/model.ts.ejs +42 -0
- package/generators/observer/index.js +132 -0
- package/generators/observer/templates/observer-template.ts.ejs +40 -0
- package/generators/openapi/README.md +211 -0
- package/generators/openapi/index.js +535 -0
- package/generators/openapi/schema-helper.js +447 -0
- package/generators/openapi/spec-helper.js +484 -0
- package/generators/openapi/spec-loader.js +75 -0
- package/generators/openapi/templates/src/controllers/controller-template.ts.ejs +43 -0
- package/generators/openapi/templates/src/datasources/datasource.ts.ejs +42 -0
- package/generators/openapi/templates/src/models/model-template.ts.ejs +71 -0
- package/generators/openapi/templates/src/models/type-template.ts.ejs +13 -0
- package/generators/openapi/templates/src/services/service-proxy-template.ts.ejs +55 -0
- package/generators/openapi/utils.js +322 -0
- package/generators/project/templates/.eslintignore +4 -0
- package/generators/project/templates/.eslintrc.js.ejs +3 -0
- package/generators/project/templates/.mocharc.json +5 -0
- package/generators/project/templates/.prettierignore +0 -2
- package/generators/project/templates/.prettierrc +2 -1
- package/generators/project/templates/.vscode/launch.json +38 -0
- package/generators/project/templates/.vscode/settings.json +32 -0
- package/generators/project/templates/.vscode/tasks.json +29 -0
- package/generators/project/templates/DEVELOPING.md +36 -0
- package/generators/project/templates/_.gitignore +3 -5
- package/generators/project/templates/package.json.ejs +175 -0
- package/generators/project/templates/package.plain.json.ejs +176 -0
- package/generators/project/templates/tsconfig.json.ejs +39 -0
- package/generators/relation/base-relation.generator.js +220 -0
- package/generators/relation/belongs-to-relation.generator.js +196 -0
- package/generators/relation/has-many-relation.generator.js +200 -0
- package/generators/relation/has-many-through-relation.generator.js +331 -0
- package/generators/relation/has-one-relation.generator.js +200 -0
- package/generators/relation/index.js +795 -0
- package/generators/relation/references-many-relation.generator.js +142 -0
- package/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs +38 -0
- package/generators/relation/templates/controller-relation-template-has-many-through.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-many.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-one.ts.ejs +110 -0
- package/generators/relation/utils.generator.js +260 -0
- package/generators/repository/index.js +576 -0
- package/generators/repository/templates/src/repositories/repository-crud-default-template.ts.ejs +21 -0
- package/generators/repository/templates/src/repositories/repository-kv-template.ts.ejs +19 -0
- package/generators/rest-crud/crud-rest-component.js +63 -0
- package/generators/rest-crud/index.js +401 -0
- package/generators/rest-crud/templates/src/model-endpoints/model.rest-config-template.ts.ejs +10 -0
- package/generators/service/index.js +351 -0
- package/generators/service/templates/local-service-class-template.ts.ejs +10 -0
- package/generators/service/templates/local-service-provider-template.ts.ejs +19 -0
- package/generators/service/templates/remote-service-proxy-template.ts.ejs +21 -0
- package/generators/update/index.js +55 -0
- package/intl/cs/messages.json +204 -0
- package/intl/de/messages.json +204 -0
- package/intl/en/messages.json +204 -0
- package/intl/es/messages.json +204 -0
- package/intl/fr/messages.json +204 -0
- package/intl/it/messages.json +204 -0
- package/intl/ja/messages.json +204 -0
- package/intl/ko/messages.json +204 -0
- package/intl/nl/messages.json +204 -0
- package/intl/pl/messages.json +204 -0
- package/intl/pt/messages.json +204 -0
- package/intl/ru/messages.json +204 -0
- package/intl/tr/messages.json +204 -0
- package/intl/zh-Hans/messages.json +204 -0
- package/intl/zh-Hant/messages.json +204 -0
- package/lib/artifact-generator.js +138 -39
- package/lib/ast-helper.js +214 -0
- package/lib/base-generator.js +509 -0
- package/lib/cli.js +233 -0
- package/lib/connectors.json +894 -0
- package/lib/debug.js +16 -0
- package/lib/globalize.js +12 -0
- package/lib/model-discoverer.js +118 -0
- package/lib/project-generator.js +154 -57
- package/lib/tab-completion.js +127 -0
- package/lib/update-index.js +44 -0
- package/lib/utils.js +689 -20
- package/lib/version-helper.js +299 -0
- package/package.json +183 -39
- package/CHANGELOG.md +0 -86
- package/bin/cli.js +0 -66
- package/generators/app/templates/index.js +0 -14
- package/generators/app/templates/src/application.ts +0 -27
- package/generators/app/templates/src/controllers/ping-controller.ts +0 -25
- package/generators/app/templates/src/index.ts +0 -25
- package/generators/app/templates/test/ping-controller.test.ts +0 -46
- package/generators/extension/templates/index.js +0 -8
- package/generators/extension/templates/src/component.ts +0 -14
- package/generators/extension/templates/src/index.ts +0 -6
- package/generators/project/templates/.npmrc +0 -1
- package/generators/project/templates/.yo-rc.json +0 -1
- package/generators/project/templates/README.md +0 -4
- package/generators/project/templates/index.d.ts +0 -6
- package/generators/project/templates/index.ts +0 -11
- package/generators/project/templates/package.json +0 -79
- package/generators/project/templates/package.plain.json +0 -82
- package/generators/project/templates/test/mocha.opts +0 -1
- package/generators/project/templates/tsconfig.json +0 -29
- package/generators/project/templates/tslint.build.json +0 -17
- package/generators/project/templates/tslint.json +0 -33
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<% if (isModelBaseBuiltin) { -%>
|
|
2
|
+
import {<%= modelBaseClass %>, model, property} from '@loopback/repository';
|
|
3
|
+
<% } else { -%>
|
|
4
|
+
import {model, property} from '@loopback/repository';
|
|
5
|
+
import {<%= modelBaseClass %>} from '.';
|
|
6
|
+
<% } -%>
|
|
7
|
+
|
|
8
|
+
<% if (modelSettings) { -%>
|
|
9
|
+
@model(<%- modelSettings %>)
|
|
10
|
+
<% } else { -%>
|
|
11
|
+
@model()
|
|
12
|
+
<% } -%>
|
|
13
|
+
export class <%= className %> extends <%= modelBaseClass %> {
|
|
14
|
+
<% Object.entries(properties).forEach(([key, val]) => { -%>
|
|
15
|
+
@property({
|
|
16
|
+
<%_ Object.entries(val).forEach(([propKey, propVal]) => { -%>
|
|
17
|
+
<%_ if (!['tsType'].includes(propKey)) { -%>
|
|
18
|
+
<%= propKey %>: <%- propVal %>,
|
|
19
|
+
<%_ } -%>
|
|
20
|
+
<%_ }) -%>
|
|
21
|
+
})
|
|
22
|
+
<%= key %><%if (!val.required) {%>?<% } %>: <%= val.tsType %>;
|
|
23
|
+
|
|
24
|
+
<% }) -%>
|
|
25
|
+
<% if(allowAdditionalProperties) { -%>
|
|
26
|
+
// Define well-known properties here
|
|
27
|
+
|
|
28
|
+
// Indexer property to allow additional data
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
[prop: string]: any;
|
|
31
|
+
<% } -%>
|
|
32
|
+
|
|
33
|
+
constructor(data?: Partial<<%= className %>>) {
|
|
34
|
+
super(data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface <%= className %>Relations {
|
|
39
|
+
// describe navigational properties here
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type <%= className %>WithRelations = <%= className %> & <%= className %>Relations;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/cli
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
const ArtifactGenerator = require('../../lib/artifact-generator');
|
|
8
|
+
const debug = require('../../lib/debug')('observer-generator');
|
|
9
|
+
const inspect = require('util').inspect;
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const utils = require('../../lib/utils');
|
|
12
|
+
|
|
13
|
+
const SCRIPT_TEMPLATE = 'observer-template.ts.ejs';
|
|
14
|
+
const g = require('../../lib/globalize');
|
|
15
|
+
|
|
16
|
+
module.exports = class ObserverGenerator extends ArtifactGenerator {
|
|
17
|
+
// Note: arguments and options should be defined in the constructor.
|
|
18
|
+
constructor(args, opts) {
|
|
19
|
+
super(args, opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_setupGenerator() {
|
|
23
|
+
this.option('group', {
|
|
24
|
+
description: g.f('Name of the observer group for ordering'),
|
|
25
|
+
required: false,
|
|
26
|
+
type: String,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
this.artifactInfo = {
|
|
30
|
+
type: 'observer',
|
|
31
|
+
rootDir: utils.sourceRootDir,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.artifactInfo.outDir = path.resolve(
|
|
35
|
+
this.artifactInfo.rootDir,
|
|
36
|
+
utils.observersDir,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
this.artifactInfo.defaultTemplate = SCRIPT_TEMPLATE;
|
|
40
|
+
|
|
41
|
+
return super._setupGenerator();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setOptions() {
|
|
45
|
+
return super.setOptions();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
checkLoopBackProject() {
|
|
49
|
+
if (this.shouldExit()) return;
|
|
50
|
+
return super.checkLoopBackProject();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Ask for Service Name
|
|
55
|
+
*/
|
|
56
|
+
async promptArtifactName() {
|
|
57
|
+
debug('Prompting for observer name');
|
|
58
|
+
if (this.shouldExit()) return;
|
|
59
|
+
|
|
60
|
+
if (this.options.name) {
|
|
61
|
+
Object.assign(this.artifactInfo, {name: this.options.name});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const prompts = [
|
|
65
|
+
{
|
|
66
|
+
type: 'input',
|
|
67
|
+
name: 'name',
|
|
68
|
+
// capitalization
|
|
69
|
+
message: g.f('%s name:', utils.toClassName(this.artifactInfo.type)),
|
|
70
|
+
when: !this.artifactInfo.name,
|
|
71
|
+
validate: utils.validateClassName,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
return this.prompt(prompts).then(props => {
|
|
75
|
+
Object.assign(this.artifactInfo, props);
|
|
76
|
+
return props;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async promptObserverGroup() {
|
|
81
|
+
debug('Prompting for observer group');
|
|
82
|
+
if (this.shouldExit()) return;
|
|
83
|
+
|
|
84
|
+
if (this.options.group) {
|
|
85
|
+
Object.assign(this.artifactInfo, {group: this.options.group});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const prompts = [
|
|
89
|
+
{
|
|
90
|
+
type: 'input',
|
|
91
|
+
name: 'group',
|
|
92
|
+
// capitalization
|
|
93
|
+
message: g.f('%s group:', utils.toClassName(this.artifactInfo.type)),
|
|
94
|
+
default: '',
|
|
95
|
+
when: !this.artifactInfo.group,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
return this.prompt(prompts).then(props => {
|
|
99
|
+
Object.assign(this.artifactInfo, props);
|
|
100
|
+
return props;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
scaffold() {
|
|
105
|
+
if (this.shouldExit()) return false;
|
|
106
|
+
|
|
107
|
+
// Setting up data for templates
|
|
108
|
+
this.artifactInfo.className =
|
|
109
|
+
utils.toClassName(this.artifactInfo.name) + 'Observer';
|
|
110
|
+
this.artifactInfo.fileName = utils.toFileName(this.artifactInfo.name);
|
|
111
|
+
|
|
112
|
+
Object.assign(this.artifactInfo, {
|
|
113
|
+
outFile: utils.getObserverFileName(this.artifactInfo.name),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const source = this.templatePath(this.artifactInfo.defaultTemplate);
|
|
117
|
+
|
|
118
|
+
const dest = this.destinationPath(
|
|
119
|
+
path.join(this.artifactInfo.outDir, this.artifactInfo.outFile),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
|
|
123
|
+
debug(`Copying artifact to: ${dest}`);
|
|
124
|
+
|
|
125
|
+
this.copyTemplatedFiles(source, dest, this.artifactInfo);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async end() {
|
|
130
|
+
await super.end();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
/* inject, Application, CoreBindings, */
|
|
3
|
+
lifeCycleObserver, // The decorator
|
|
4
|
+
LifeCycleObserver, // The interface
|
|
5
|
+
} from '@loopback/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This class will be bound to the application as a `LifeCycleObserver` during
|
|
9
|
+
* `boot`
|
|
10
|
+
*/
|
|
11
|
+
@lifeCycleObserver('<%= group %>')
|
|
12
|
+
export class <%= className %> implements LifeCycleObserver {
|
|
13
|
+
/*
|
|
14
|
+
constructor(
|
|
15
|
+
@inject(CoreBindings.APPLICATION_INSTANCE) private app: Application,
|
|
16
|
+
) {}
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This method will be invoked when the application initializes. It will be
|
|
21
|
+
* called at most once for a given application instance.
|
|
22
|
+
*/
|
|
23
|
+
async init(): Promise<void> {
|
|
24
|
+
// Add your logic for init
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This method will be invoked when the application starts.
|
|
29
|
+
*/
|
|
30
|
+
async start(): Promise<void> {
|
|
31
|
+
// Add your logic for start
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This method will be invoked when the application stops.
|
|
36
|
+
*/
|
|
37
|
+
async stop(): Promise<void> {
|
|
38
|
+
// Add your logic for stop
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# lb4 openapi
|
|
2
|
+
|
|
3
|
+
The `openapi` command generates LoopBack 4 artifacts from an
|
|
4
|
+
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification), including
|
|
5
|
+
version 2.0 and 3.0.
|
|
6
|
+
|
|
7
|
+
## Basic use
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
Usage:
|
|
11
|
+
lb4 openapi [<url>] [options]
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
-h, --help # Print the generator's options and usage
|
|
15
|
+
--url # URL or file path of the OpenAPI spec
|
|
16
|
+
--validate # Validate the OpenAPI spec Default: false
|
|
17
|
+
|
|
18
|
+
Arguments:
|
|
19
|
+
url # URL or file path of the OpenAPI spec Type: String Required: false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For example,
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
lb4 openapi https://api.apis.guru/v2/specs/api2cart.com/1.0.0/swagger.json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Mappings
|
|
29
|
+
|
|
30
|
+
We map OpenAPI operations by tag into `controllers` and schemas into `models` as
|
|
31
|
+
TypeScript classes or types.
|
|
32
|
+
|
|
33
|
+
### Schemas
|
|
34
|
+
|
|
35
|
+
The generator first iterates through the `components.schemas` of the
|
|
36
|
+
specification document and maps them into TypeScript classes or types:
|
|
37
|
+
|
|
38
|
+
- Primitive types --> TypeScript type declaration
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
export type Message = string;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
export type OrderEnum = 'ascending' | 'descending';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- Array types --> TypeScript type declaration
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import {Comment} from './comment.model';
|
|
52
|
+
export type Comments = Comment[];
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- Object type --> TypeScript class definition
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import {model, property} from '@loopback/repository';
|
|
59
|
+
import {CartShippingZone} from './cart-shipping-zone.model';
|
|
60
|
+
import {CartStoreInfo} from './cart-store-info.model';
|
|
61
|
+
import {CartWarehouse} from './cart-warehouse.model';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The model class is generated from OpenAPI schema - Cart
|
|
65
|
+
* Cart
|
|
66
|
+
*/
|
|
67
|
+
@model({name: 'Cart'})
|
|
68
|
+
export class Cart {
|
|
69
|
+
constructor(data?: Partial<Cart>) {
|
|
70
|
+
if (data != null && typeof data === 'object') {
|
|
71
|
+
Object.assign(this, data);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@property({name: 'additional_fields'})
|
|
76
|
+
additional_fields?: {};
|
|
77
|
+
|
|
78
|
+
@property({name: 'custom_fields'})
|
|
79
|
+
custom_fields?: {};
|
|
80
|
+
|
|
81
|
+
@property({name: 'db_prefix'})
|
|
82
|
+
db_prefix?: string;
|
|
83
|
+
|
|
84
|
+
@property({name: 'name'})
|
|
85
|
+
name?: string;
|
|
86
|
+
|
|
87
|
+
@property({name: 'shipping_zones'})
|
|
88
|
+
shipping_zones?: CartShippingZone[];
|
|
89
|
+
|
|
90
|
+
@property({name: 'stores_info'})
|
|
91
|
+
stores_info?: CartStoreInfo[];
|
|
92
|
+
|
|
93
|
+
@property({name: 'url'})
|
|
94
|
+
url?: string;
|
|
95
|
+
|
|
96
|
+
@property({name: 'version'})
|
|
97
|
+
version?: string;
|
|
98
|
+
|
|
99
|
+
@property({name: 'warehouses'})
|
|
100
|
+
warehouses?: CartWarehouse[];
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- Composite type (anyOf|oneOf|allOf) --> TypeScript union/intersection types
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
export type IdType = string | number;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import {NewPet} from './new-pet.model.ts';
|
|
112
|
+
export type Pet = NewPet & {id: number};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Embedded schemas are mapped to TypeScript type literals.
|
|
116
|
+
|
|
117
|
+
### Operations
|
|
118
|
+
|
|
119
|
+
The generator groups operations (`paths.<path>.<verb>`) by tags. If no tag is
|
|
120
|
+
present, it defaults to `OpenApi`. For each tag, a controller class is generated
|
|
121
|
+
to hold all operations with the same tag.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import {operation, param} from '@loopback/rest';
|
|
125
|
+
import {DateTime} from '../models/date-time.model';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The controller class is generated from OpenAPI spec with operations tagged
|
|
129
|
+
* by account
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
export class AccountController {
|
|
133
|
+
constructor() {}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get list of carts.
|
|
137
|
+
*/
|
|
138
|
+
@operation('get', '/account.cart.list.json')
|
|
139
|
+
async accountCartList(
|
|
140
|
+
@param({name: 'params', in: 'query'}) params: string,
|
|
141
|
+
@param({name: 'exclude', in: 'query'}) exclude: string,
|
|
142
|
+
@param({name: 'request_from_date', in: 'query'}) request_from_date: string,
|
|
143
|
+
@param({name: 'request_to_date', in: 'query'}) request_to_date: string,
|
|
144
|
+
): Promise<{
|
|
145
|
+
result?: {
|
|
146
|
+
carts?: {
|
|
147
|
+
cart_id?: string;
|
|
148
|
+
id?: string;
|
|
149
|
+
store_key?: string;
|
|
150
|
+
total_calls?: string;
|
|
151
|
+
url?: string;
|
|
152
|
+
}[];
|
|
153
|
+
carts_count?: number;
|
|
154
|
+
};
|
|
155
|
+
return_code?: number;
|
|
156
|
+
return_message?: string;
|
|
157
|
+
}> {
|
|
158
|
+
throw new Error('Not implemented');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Update configs in the API2Cart database.
|
|
163
|
+
*/
|
|
164
|
+
@operation('put', '/account.config.update.json')
|
|
165
|
+
async accountConfigUpdate(
|
|
166
|
+
@param({name: 'db_tables_prefix', in: 'query'}) db_tables_prefix: string,
|
|
167
|
+
@param({name: 'client_id', in: 'query'}) client_id: string,
|
|
168
|
+
@param({name: 'bridge_url', in: 'query'}) bridge_url: string,
|
|
169
|
+
@param({name: 'store_root', in: 'query'}) store_root: string,
|
|
170
|
+
@param({name: 'shared_secret', in: 'query'}) shared_secret: string,
|
|
171
|
+
): Promise<{
|
|
172
|
+
result?: {
|
|
173
|
+
updated_items?: number;
|
|
174
|
+
};
|
|
175
|
+
return_code?: number;
|
|
176
|
+
return_message?: string;
|
|
177
|
+
}> {
|
|
178
|
+
throw new Error('Not implemented');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* List webhooks that was not delivered to the callback.
|
|
183
|
+
*/
|
|
184
|
+
@operation('get', '/account.failed_webhooks.json')
|
|
185
|
+
async accountFailedWebhooks(
|
|
186
|
+
@param({name: 'count', in: 'query'}) count: number,
|
|
187
|
+
@param({name: 'start', in: 'query'}) start: number,
|
|
188
|
+
@param({name: 'ids', in: 'query'}) ids: string,
|
|
189
|
+
): Promise<{
|
|
190
|
+
result?: {
|
|
191
|
+
all_failed_webhook?: string;
|
|
192
|
+
webhook?: {
|
|
193
|
+
entity_id?: string;
|
|
194
|
+
time?: DateTime;
|
|
195
|
+
webhook_id?: number;
|
|
196
|
+
}[];
|
|
197
|
+
};
|
|
198
|
+
return_code?: number;
|
|
199
|
+
return_message?: string;
|
|
200
|
+
}> {
|
|
201
|
+
throw new Error('Not implemented');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## OpenAPI Examples
|
|
207
|
+
|
|
208
|
+
- https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
|
|
209
|
+
- https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/uspto.yaml
|
|
210
|
+
- https://api.apis.guru/v2/specs/api2cart.com/1.0.0/swagger.json
|
|
211
|
+
- https://api.apis.guru/v2/specs/amazonaws.com/codecommit/2015-04-13/swagger.json
|