@ama-sdk/schematics 9.1.0-alpha.9 → 9.2.0-alpha.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/README.md +16 -0
- package/package.json +28 -31
- package/schematics/api-extension/schema.d.ts +2 -2
- package/schematics/api-extension/schema.d.ts.map +1 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.d.ts.map +1 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.js +2 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.d.ts +10 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.d.ts.map +1 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.js +2 -1
- package/schematics/java/client-core/schema.d.ts +3 -3
- package/schematics/java/client-core/schema.d.ts.map +1 -1
- package/schematics/java/client-core/swagger-codegen-java-client/target/javaClient-swagger-codegen-tests.jar +0 -0
- package/schematics/java/client-core/swagger-codegen-java-client/target/javaClient-swagger-codegen.jar +0 -0
- package/schematics/ng-add/schema.d.ts +3 -3
- package/schematics/ng-add/schema.d.ts.map +1 -1
- package/schematics/typescript/core/index.d.ts.map +1 -1
- package/schematics/typescript/core/index.js +7 -6
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator-tests.jar +0 -0
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator.jar +0 -0
- package/schematics/typescript/core/schema.d.ts +13 -5
- package/schematics/typescript/core/schema.d.ts.map +1 -1
- package/schematics/typescript/core/schema.json +5 -3
- package/schematics/typescript/mock/schema.d.ts +2 -2
- package/schematics/typescript/mock/schema.d.ts.map +1 -1
- package/schematics/typescript/shell/index.d.ts.map +1 -1
- package/schematics/typescript/shell/index.js +17 -14
- package/schematics/typescript/shell/schema.d.ts +5 -5
- package/schematics/typescript/shell/schema.d.ts.map +1 -1
- package/schematics/typescript/shell/schema.json +1 -3
- package/schematics/typescript/shell/templates/base/.gitignore.template +2 -6
- package/schematics/typescript/shell/templates/base/.husky/commit-msg +1 -1
- package/schematics/typescript/shell/templates/base/.husky/pre-commit +1 -1
- package/schematics/typescript/shell/templates/base/.renovaterc.json +3 -3
- package/schematics/typescript/shell/templates/base/.vscode/settings.json +3 -1
- package/schematics/typescript/shell/templates/base/jest.config.js +9 -6
- package/schematics/typescript/shell/templates/base/package.json.template +11 -12
- package/schematics/typescript/shell/templates/base/readme.md +88 -3
- package/schematics/typescript/shell/templates/base/src/api/fixtures.jest.ts +2 -0
- package/schematics/typescript/shell/templates/base/src/api/index.ts +1 -0
- package/schematics/typescript/shell/templates/base/src/models/base/enums.ts +2 -0
- package/schematics/typescript/shell/templates/base/src/models/base/index.ts +1 -0
- package/schematics/typescript/shell/templates/base/src/models/base/patterns.ts +2 -0
- package/schematics/typescript/shell/templates/base/src/spec/api-mock.ts +2 -0
- package/schematics/typescript/shell/templates/base/src/spec/operation-adapter.ts +0 -0
package/README.md
CHANGED
|
@@ -75,3 +75,19 @@ yarn schematics @ama-sdk/schematics:java-client-core --spec-path ./swagger-spec.
|
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
[Default swagger config](./schematics/java/client-core/swagger-codegen-java-client/config/swagger-codegen-config.json) will be used if `--swagger-config-path` is not provided.
|
|
78
|
+
|
|
79
|
+
### Debug the typescript generator
|
|
80
|
+
The OpenApi generator extracts an enhanced JSON data model from the specification YAML and uses this data model to feed the templates to generate the code.
|
|
81
|
+
If there is an issue with the files generated with the spec provided, the generator provides debugging features that log this data model.
|
|
82
|
+
|
|
83
|
+
You can use global property options to pass one or both of the following options:
|
|
84
|
+
* debugModel - logs the full JSON structure used to generate models
|
|
85
|
+
* debugOperations - logs the full JSON structure used to generate operations
|
|
86
|
+
|
|
87
|
+
Example:
|
|
88
|
+
```shell
|
|
89
|
+
yarn schematics @ama-sdk/schematics:typescript-core --spec-path ./swagger-spec.yaml --global-property debugModels,debugOperations
|
|
90
|
+
```
|
|
91
|
+
You can also use npx instead of yarn in the command.
|
|
92
|
+
|
|
93
|
+
You can correlate this data model with the [templates](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/schematics/schematics/typescript/core/openapi-codegen-typescript/src/main/resources/typescriptFetch) used by the generator.
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-sdk/schematics",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0-alpha.0",
|
|
4
4
|
"description": "Swagger specification SDK Generator by schematics",
|
|
5
|
+
"typings": "./src/public_api.d.ts",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"nx": "nx",
|
|
7
8
|
"ng": "yarn nx",
|
|
8
9
|
"test": "yarn nx test ama-sdk-schematics",
|
|
9
10
|
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' 'schematics/**/*.jar' dist/schematics && yarn cpy '{package,collection}.json' dist",
|
|
10
11
|
"build": "yarn nx build ama-sdk-schematics",
|
|
11
|
-
"build:builders": "tsc -b tsconfig.builders.json --pretty",
|
|
12
|
+
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
|
|
12
13
|
"install-swagger-cli": "mvn install:install-file -DgroupId=io.swagger -DartifactId=swagger-codegen-cli -Dversion=2.4.0-AMADEUS -Dpackaging=jar -Dfile=./schematics/resources/swagger-codegen-cli.jar",
|
|
13
14
|
"build:swagger": "yarn install-swagger-cli && run-p 'build:swagger-*' 'build:openapi-*'",
|
|
14
15
|
"build:openapi-typescript-gen": "mvn clean package -f ./schematics/typescript/core/openapi-codegen-typescript/pom.xml",
|
|
@@ -27,9 +28,6 @@
|
|
|
27
28
|
"@angular-devkit/schematics-cli": {
|
|
28
29
|
"optional": true
|
|
29
30
|
},
|
|
30
|
-
"@angular/cli": {
|
|
31
|
-
"optional": true
|
|
32
|
-
},
|
|
33
31
|
"@angular/compiler": {
|
|
34
32
|
"optional": true
|
|
35
33
|
},
|
|
@@ -41,18 +39,17 @@
|
|
|
41
39
|
}
|
|
42
40
|
},
|
|
43
41
|
"peerDependencies": {
|
|
44
|
-
"@ama-sdk/core": "^9.
|
|
45
|
-
"@angular-devkit/core": "
|
|
46
|
-
"@angular-devkit/schematics": "
|
|
47
|
-
"@angular-devkit/schematics-cli": "
|
|
48
|
-
"@angular/cli": "~16.0.5",
|
|
42
|
+
"@ama-sdk/core": "^9.2.0-alpha.0",
|
|
43
|
+
"@angular-devkit/core": "^16.0.5",
|
|
44
|
+
"@angular-devkit/schematics": "^16.0.5",
|
|
45
|
+
"@angular-devkit/schematics-cli": "^16.0.5",
|
|
49
46
|
"@openapitools/openapi-generator-cli": "~2.7.0",
|
|
50
|
-
"@schematics/angular": "
|
|
47
|
+
"@schematics/angular": "^16.0.5"
|
|
51
48
|
},
|
|
52
49
|
"dependencies": {
|
|
53
|
-
"@angular-devkit/core": "~16.
|
|
54
|
-
"@angular-devkit/schematics": "~16.
|
|
55
|
-
"@o3r/dev-tools": "^9.
|
|
50
|
+
"@angular-devkit/core": "~16.1.6",
|
|
51
|
+
"@angular-devkit/schematics": "~16.1.6",
|
|
52
|
+
"@o3r/dev-tools": "^9.2.0-alpha.0",
|
|
56
53
|
"js-yaml": "^4.1.0",
|
|
57
54
|
"minimatch": "^9.0.0",
|
|
58
55
|
"rxjs": "^7.8.1",
|
|
@@ -61,16 +58,16 @@
|
|
|
61
58
|
"tslib": "^2.5.3"
|
|
62
59
|
},
|
|
63
60
|
"devDependencies": {
|
|
64
|
-
"@ama-sdk/core": "^9.
|
|
65
|
-
"@angular-devkit/schematics-cli": "~16.
|
|
66
|
-
"@angular-eslint/eslint-plugin": "~16.0
|
|
67
|
-
"@angular/cli": "~16.
|
|
68
|
-
"@nx/jest": "~16.
|
|
69
|
-
"@o3r/build-helpers": "^9.
|
|
70
|
-
"@o3r/eslint-plugin": "^9.
|
|
71
|
-
"@o3r/schematics": "^9.
|
|
61
|
+
"@ama-sdk/core": "^9.2.0-alpha.0",
|
|
62
|
+
"@angular-devkit/schematics-cli": "~16.1.6",
|
|
63
|
+
"@angular-eslint/eslint-plugin": "~16.1.0",
|
|
64
|
+
"@angular/cli": "~16.1.6",
|
|
65
|
+
"@nx/jest": "~16.6.0",
|
|
66
|
+
"@o3r/build-helpers": "^9.2.0-alpha.0",
|
|
67
|
+
"@o3r/eslint-plugin": "^9.2.0-alpha.0",
|
|
68
|
+
"@o3r/schematics": "^9.2.0-alpha.0",
|
|
72
69
|
"@openapitools/openapi-generator-cli": "~2.7.0",
|
|
73
|
-
"@schematics/angular": "~16.
|
|
70
|
+
"@schematics/angular": "~16.1.6",
|
|
74
71
|
"@types/jest": "~29.5.2",
|
|
75
72
|
"@types/js-yaml": "^4.0.5",
|
|
76
73
|
"@types/minimatch": "^5.1.2",
|
|
@@ -83,22 +80,22 @@
|
|
|
83
80
|
"cpy-cli": "^4.2.0",
|
|
84
81
|
"eslint": "^8.42.0",
|
|
85
82
|
"eslint-import-resolver-node": "^0.3.4",
|
|
86
|
-
"eslint-plugin-jest": "
|
|
87
|
-
"eslint-plugin-jsdoc": "
|
|
88
|
-
"eslint-plugin-prefer-arrow": "
|
|
83
|
+
"eslint-plugin-jest": "~27.2.3",
|
|
84
|
+
"eslint-plugin-jsdoc": "~46.4.5",
|
|
85
|
+
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
89
86
|
"eslint-plugin-unicorn": "^47.0.0",
|
|
90
87
|
"isomorphic-fetch": "~3.0.0",
|
|
91
|
-
"jest": "~29.6.
|
|
92
|
-
"jest-junit": "
|
|
88
|
+
"jest": "~29.6.2",
|
|
89
|
+
"jest-junit": "~16.0.0",
|
|
93
90
|
"mem-fs": "^2.2.1",
|
|
94
91
|
"npm-run-all": "^4.1.5",
|
|
95
|
-
"nx": "~16.
|
|
92
|
+
"nx": "~16.6.0",
|
|
96
93
|
"onchange": "^7.0.2",
|
|
97
94
|
"pid-from-port": "^1.1.3",
|
|
98
95
|
"semver": "^7.5.2",
|
|
99
|
-
"ts-jest": "
|
|
96
|
+
"ts-jest": "~29.1.1",
|
|
100
97
|
"type-fest": "^3.12.0",
|
|
101
|
-
"typescript": "~5.
|
|
98
|
+
"typescript": "~5.1.6"
|
|
102
99
|
},
|
|
103
100
|
"openApiSupportedVersion": "~6.6.0",
|
|
104
101
|
"engines": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface NgGenerateApiExtensionSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgGenerateApiExtensionSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Extension Name */
|
|
4
4
|
name: string;
|
|
5
5
|
/** Type of the core API to extend */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/api-extension/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/api-extension/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,sCAAuC,SAAQ,qBAAqB;IACnF,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC/B,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-api-cli.generator.d.ts","sourceRoot":"","sources":["../../../../schematics/code-generator/open-api-cli-generator/open-api-cli.generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAoC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAI5F;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa,CAAC,iBAAiB,CAAC;IAEvE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,KAAK,GAAG,MAAM,CAAC;IAClD,SAAS,KAAK,oBAAoB,IAAI,KAAK,GAAG,MAAM,CAEnD;IAED,kBAAkB;IAClB,SAAS,CAAC,QAAQ,CAAC,aAAa,6BAA6B;gBAEjD,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,EAAE,CAAA;KAAE;IAK9D;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAelC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"open-api-cli.generator.d.ts","sourceRoot":"","sources":["../../../../schematics/code-generator/open-api-cli-generator/open-api-cli.generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAoC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAI5F;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa,CAAC,iBAAiB,CAAC;IAEvE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,KAAK,GAAG,MAAM,CAAC;IAClD,SAAS,KAAK,oBAAoB,IAAI,KAAK,GAAG,MAAM,CAEnD;IAED,kBAAkB;IAClB,SAAS,CAAC,QAAQ,CAAC,aAAa,6BAA6B;gBAEjD,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,EAAE,CAAA;KAAE;IAK9D;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAelC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAuBpB,kBAAkB;IAClB,SAAS,CAAC,iBAAiB,0BAA2C;IAEtE,kBAAkB;IAClB,SAAS,CAAC,uBAAuB,oBAAoB;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,yBAI5C,iBAAiB,wBAclD;CACH"}
|
|
@@ -73,7 +73,8 @@ class OpenApiCliGenerator extends code_generator_1.CodeGenerator {
|
|
|
73
73
|
'-g', generatorOptions.generatorName,
|
|
74
74
|
'-i', generatorOptions.specPath,
|
|
75
75
|
...generatorOptions.specConfigPath ? ['-c', generatorOptions.specConfigPath] : [],
|
|
76
|
-
'-o', generatorOptions.outputPath
|
|
76
|
+
'-o', generatorOptions.outputPath,
|
|
77
|
+
...generatorOptions.globalProperty ? ['--global-property', generatorOptions.globalProperty] : []
|
|
77
78
|
];
|
|
78
79
|
return new Promise((resolve, reject) => {
|
|
79
80
|
(0, node_child_process_1.spawn)(this.packageManagerRunner, args, spawnOptions)
|
|
@@ -10,7 +10,7 @@ export type OpenApiCliOptions = CodegenTaskOptions & {
|
|
|
10
10
|
* - the one defined in your openapitools.json
|
|
11
11
|
* - the latest version if openapitools.json is missing
|
|
12
12
|
*
|
|
13
|
-
* @default
|
|
13
|
+
* @default ''
|
|
14
14
|
*/
|
|
15
15
|
generatorVersion: string;
|
|
16
16
|
/**
|
|
@@ -25,6 +25,15 @@ export type OpenApiCliOptions = CodegenTaskOptions & {
|
|
|
25
25
|
* @default path to our own custom typescript generator
|
|
26
26
|
*/
|
|
27
27
|
generatorCustomPath: string;
|
|
28
|
+
/**
|
|
29
|
+
* Comma separated string of options to give to the openapi-generator-cli
|
|
30
|
+
*
|
|
31
|
+
* @example debugModels to log the full json structure used to generate models
|
|
32
|
+
* @example debugOperations to log the full json structure used to generate operations
|
|
33
|
+
*
|
|
34
|
+
* @default ''
|
|
35
|
+
*/
|
|
36
|
+
globalProperty: string;
|
|
28
37
|
};
|
|
29
38
|
/**
|
|
30
39
|
* Default options to run our custom typescript generator
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-api-cli.options.d.ts","sourceRoot":"","sources":["../../../../schematics/code-generator/open-api-cli-generator/open-api-cli.options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAGrD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IACnD;;;;;;;OAOG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"open-api-cli.options.d.ts","sourceRoot":"","sources":["../../../../schematics/code-generator/open-api-cli-generator/open-api-cli.options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAGrD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IACnD;;;;;;;OAOG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;;;;;OAOG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iCAAiC,EAAE,iBAQ/C,CAAC"}
|
|
@@ -11,6 +11,7 @@ exports.defaultTypescriptGeneratorOptions = {
|
|
|
11
11
|
generatorCustomPath: path.join(__dirname, '..', '..', 'typescript', 'core', 'openapi-codegen-typescript', 'target', 'typescriptFetch-openapi-generator.jar'),
|
|
12
12
|
specPath: 'swagger-spec.yaml',
|
|
13
13
|
outputPath: '.',
|
|
14
|
-
specConfigPath: ''
|
|
14
|
+
specConfigPath: '',
|
|
15
|
+
globalProperty: ''
|
|
15
16
|
};
|
|
16
17
|
//# sourceMappingURL=open-api-cli.options.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface NgGenerateJavaClientCoreSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgGenerateJavaClientCoreSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Path to the swagger specification used to generate the SDK */
|
|
4
4
|
specPath: string;
|
|
5
5
|
/** Swagger config file */
|
|
6
|
-
specConfigPath
|
|
6
|
+
specConfigPath?: string | undefined;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/java/client-core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/java/client-core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,wCAAyC,SAAQ,qBAAqB;IACrF,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IAEjB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC"}
|
|
Binary file
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface NgAddSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgAddSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Project name */
|
|
4
|
-
projectName
|
|
4
|
+
projectName?: string | undefined;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AAgBvE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,2CAA2C,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AAgBvE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,2CAA2C,GAAG,IAAI,CAgHlG"}
|
|
@@ -24,7 +24,8 @@ const getPathObjectTemplate = (pathObj) => {
|
|
|
24
24
|
*/
|
|
25
25
|
function ngGenerateTypescriptSDK(options) {
|
|
26
26
|
const specPath = path.resolve(process.cwd(), options.specPath);
|
|
27
|
-
const targetPath = options.directory || '
|
|
27
|
+
const targetPath = options.directory || '';
|
|
28
|
+
const globalProperty = options.globalProperty;
|
|
28
29
|
const generateOperationFinder = async () => {
|
|
29
30
|
const swayOptions = {
|
|
30
31
|
definition: path.resolve(options.specPath)
|
|
@@ -50,10 +51,10 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
50
51
|
* @param _context
|
|
51
52
|
*/
|
|
52
53
|
const clearGeneratedCode = (tree, _context) => {
|
|
53
|
-
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
54
|
-
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
55
|
-
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'models', 'base', '**', '!(index).ts')).forEach((file) => tree.delete(file));
|
|
56
|
-
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'spec', '!(operation-adapter|index).ts')).forEach((file) => tree.delete(file));
|
|
54
|
+
(0, tree_glob_1.treeGlob)(tree, path.posix.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
55
|
+
(0, tree_glob_1.treeGlob)(tree, path.posix.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
56
|
+
(0, tree_glob_1.treeGlob)(tree, path.posix.join(targetPath, 'src', 'models', 'base', '**', '!(index).ts')).forEach((file) => tree.delete(file));
|
|
57
|
+
(0, tree_glob_1.treeGlob)(tree, path.posix.join(targetPath, 'src', 'spec', '!(operation-adapter|index).ts')).forEach((file) => tree.delete(file));
|
|
57
58
|
return tree;
|
|
58
59
|
};
|
|
59
60
|
/**
|
|
@@ -100,7 +101,7 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
100
101
|
return () => tree;
|
|
101
102
|
};
|
|
102
103
|
const runGeneratorRule = (tree, context) => {
|
|
103
|
-
const generatorOptions = { specPath };
|
|
104
|
+
const generatorOptions = { specPath, globalProperty };
|
|
104
105
|
const packageJsonFile = JSON.parse(((0, node_fs_1.readFileSync)(path.join(__dirname, '..', '..', '..', 'package.json'))).toString());
|
|
105
106
|
const packageOpenApiSupportedVersion = packageJsonFile.openApiSupportedVersion?.replace(/\^|~/, '');
|
|
106
107
|
let openApiVersion = '';
|
|
Binary file
|
|
Binary file
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface NgGenerateTypescriptSDKCoreSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgGenerateTypescriptSDKCoreSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Path to the swagger specification used to generate the SDK */
|
|
4
4
|
specPath: string;
|
|
5
5
|
/** Directory where to generate the SDK */
|
|
6
|
-
directory
|
|
6
|
+
directory?: string | undefined;
|
|
7
7
|
/** Package manager to be used in the generated SDK */
|
|
8
|
-
packageManager: 'npm' | 'yarn' |
|
|
8
|
+
packageManager: 'npm' | 'yarn' | undefined;
|
|
9
9
|
/** Path to the spec generation configuration */
|
|
10
|
-
specConfigPath: string |
|
|
10
|
+
specConfigPath: string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Comma separated string of options to give to the openapi-generator-cli
|
|
13
|
+
*
|
|
14
|
+
* @example debugModels to log the full json structure used to generate models
|
|
15
|
+
* @example debugOperations to log the full json structure used to generate operations
|
|
16
|
+
* @default ''
|
|
17
|
+
*/
|
|
18
|
+
globalProperty: string | undefined;
|
|
11
19
|
}
|
|
12
20
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,2CAA4C,SAAQ,qBAAqB;IACxF,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IAEjB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B,sDAAsD;IACtD,cAAc,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IAE3C,gDAAgD;IAChD,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC"}
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"packageManager": {
|
|
25
25
|
"type": "string",
|
|
26
26
|
"enum": [
|
|
27
|
-
"",
|
|
28
27
|
"npm",
|
|
29
28
|
"yarn"
|
|
30
29
|
],
|
|
31
|
-
"description": "Package manager to be used in the generated SDK"
|
|
32
|
-
|
|
30
|
+
"description": "Package manager to be used in the generated SDK"
|
|
31
|
+
},
|
|
32
|
+
"globalProperty": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Comma separated string of options to give to the openapi-generator-cli"
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
37
|
"additionalProperties": true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface NgGenerateMockSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgGenerateMockSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Name of the api model to generate */
|
|
4
4
|
apiModel: string;
|
|
5
5
|
/** True if the api model has a property id */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/mock/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/mock/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IAC3E,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IAEjB,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IAEpB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IAEb,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAIL,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAIL,MAAM,4BAA4B,CAAC;AAKpC,OAAO,KAAK,EAAC,4CAA4C,EAAC,MAAM,UAAU,CAAC;AAE3E;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,4CAA4C,GAAG,IAAI,CAoFnG"}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ngGenerateTypescriptSDK = void 0;
|
|
4
4
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
5
|
const js_yaml_1 = require("js-yaml");
|
|
6
|
-
const read_package_1 = require("../../helpers/read-package");
|
|
7
6
|
const node_path_1 = require("node:path");
|
|
8
7
|
const node_install_1 = require("../../helpers/node-install");
|
|
8
|
+
const read_package_1 = require("../../helpers/read-package");
|
|
9
9
|
/**
|
|
10
10
|
* @param options
|
|
11
11
|
*/
|
|
@@ -47,6 +47,7 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
47
47
|
projectName: options.name,
|
|
48
48
|
projectPackageName: options.package,
|
|
49
49
|
projectDescription: options.description,
|
|
50
|
+
packageManager: (0, node_install_1.getPackageManagerName)(options.packageManager),
|
|
50
51
|
projectHosting: options.hosting,
|
|
51
52
|
sdkCoreVersion: amaSdkSchematicsPackageJson.version,
|
|
52
53
|
angularVersion: amaSdkSchematicsPackageJson.dependencies['@angular-devkit/core'],
|
|
@@ -56,20 +57,22 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
56
57
|
engineVersions,
|
|
57
58
|
empty: ''
|
|
58
59
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
if (properties.packageManager === 'yarn') {
|
|
61
|
+
const yarnrcPath = '.yarnrc.yml';
|
|
62
|
+
const yarnrc = ((0, js_yaml_1.load)(tree.exists(yarnrcPath) ? tree.readText(yarnrcPath) : '') || {});
|
|
63
|
+
yarnrc.nodeLinker ||= 'pnp';
|
|
64
|
+
yarnrc.packageExtensions ||= {};
|
|
65
|
+
yarnrc.packageExtensions['@ama-sdk/schematics@*'] = {
|
|
66
|
+
dependencies: {
|
|
67
|
+
'isomorphic-fetch': '~2.2.1'
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (tree.exists(yarnrcPath)) {
|
|
71
|
+
tree.overwrite(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
tree.create(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
66
75
|
}
|
|
67
|
-
};
|
|
68
|
-
if (tree.exists(yarnrcPath)) {
|
|
69
|
-
tree.overwrite(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
tree.create(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
73
76
|
}
|
|
74
77
|
const targetPath = options.directory || tree.root.path;
|
|
75
78
|
const baseRule = (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./templates/base'), [
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface NgGenerateTypescriptSDKShellSchematicsSchema extends
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface NgGenerateTypescriptSDKShellSchematicsSchema extends SchematicOptionObject {
|
|
3
3
|
/** Project name (NPM package scope, package.json name will be @{projectName}/{packageName}) */
|
|
4
4
|
name: string;
|
|
5
5
|
/** Package name (package.json name will be @{projectName}/{packageName}) */
|
|
6
6
|
package: string;
|
|
7
7
|
/** Project description */
|
|
8
|
-
description
|
|
8
|
+
description?: string | undefined;
|
|
9
9
|
/** Directory where to generate the SDK */
|
|
10
|
-
directory
|
|
10
|
+
directory?: string | undefined;
|
|
11
11
|
/** Package manager to be used in the generated SDK */
|
|
12
|
-
packageManager
|
|
12
|
+
packageManager?: 'npm' | 'yarn' | undefined;
|
|
13
13
|
/** Skip NPM install */
|
|
14
14
|
skipInstall: boolean;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,4CAA6C,SAAQ,qBAAqB;IACzF,+FAA+F;IAC/F,IAAI,EAAE,MAAM,CAAC;IAEb,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAEhB,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B,sDAAsD;IACtD,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IAE5C,uBAAuB;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -31,12 +31,10 @@
|
|
|
31
31
|
"packageManager": {
|
|
32
32
|
"type": "string",
|
|
33
33
|
"enum": [
|
|
34
|
-
"",
|
|
35
34
|
"npm",
|
|
36
35
|
"yarn"
|
|
37
36
|
],
|
|
38
|
-
"description": "Package manager to be used in the generated SDK"
|
|
39
|
-
"default": ""
|
|
37
|
+
"description": "Package manager to be used in the generated SDK"
|
|
40
38
|
}
|
|
41
39
|
},
|
|
42
40
|
"additionalProperties": true,
|
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
/generated-*
|
|
7
7
|
/build
|
|
8
8
|
|
|
9
|
-
# Local configurations
|
|
10
|
-
.custom.yo-rc.json
|
|
11
|
-
|
|
12
9
|
# Open API
|
|
13
10
|
.openapi-generator
|
|
14
11
|
|
|
@@ -38,6 +35,7 @@
|
|
|
38
35
|
.history
|
|
39
36
|
.ionide
|
|
40
37
|
|
|
38
|
+
<% if (packageManager === 'yarn') { %>
|
|
41
39
|
# Support for Project snippet scope
|
|
42
40
|
|
|
43
41
|
### yarn ###
|
|
@@ -56,10 +54,8 @@
|
|
|
56
54
|
|
|
57
55
|
# and uncomment the following lines
|
|
58
56
|
.pnp.*
|
|
59
|
-
|
|
60
|
-
### Yeoman ###
|
|
57
|
+
<% } %>
|
|
61
58
|
node_modules/
|
|
62
|
-
bower_components/
|
|
63
59
|
*.log
|
|
64
60
|
|
|
65
61
|
build/
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"updateInternalDeps": true,
|
|
28
28
|
"postUpdateOptions": [
|
|
29
|
-
"yarnDedupeHighest"
|
|
29
|
+
<% if (packageManager === 'yarn') { %>"yarnDedupeHighest",<% } %>
|
|
30
30
|
],
|
|
31
31
|
"rangeStrategy": "replace",
|
|
32
32
|
"automerge": true,
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
],
|
|
40
40
|
"postUpgradeTasks": {
|
|
41
41
|
"commands": [
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"<%=packageManager%> install",
|
|
43
|
+
"<%=packageManager%> run generate"
|
|
44
44
|
],
|
|
45
45
|
"executionMode": "branch"
|
|
46
46
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"typescript.preferences.importModuleSpecifier": "relative",
|
|
3
3
|
"typescript.preferences.quoteStyle": "single",
|
|
4
|
-
"jest.jestCommandLine": "
|
|
4
|
+
"jest.jestCommandLine": "<%=packageManager%> exec jest",
|
|
5
5
|
"jest.autoRun": {
|
|
6
6
|
"watch": false,
|
|
7
7
|
"onSave": "test-file"
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
"files.readonlyFromPermissions": true,
|
|
10
10
|
"files.readonlyInclude": {
|
|
11
11
|
"**/.cache/**": true,
|
|
12
|
+
<% if (packageManager === 'yarn') { %>
|
|
12
13
|
"**/.pnp.*": true,
|
|
13
14
|
"**/.yarn/**": true,
|
|
15
|
+
<% } %>
|
|
14
16
|
"**/node_modules/**": true,
|
|
15
17
|
"src/base/*/*.ts": true
|
|
16
18
|
},
|
|
@@ -12,12 +12,15 @@ module.exports = {
|
|
|
12
12
|
'^@<%=projectName%>/<%=projectPackageName%>$': ['<rootDir>/dist/cjs', '<rootDir>/src'],
|
|
13
13
|
'^@<%=projectName%>/<%=projectPackageName%>/(.*)$': ['<rootDir>/dist/cjs/$1', '<rootDir>/src/$1'],
|
|
14
14
|
},
|
|
15
|
-
|
|
15
|
+
transform: {
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
17
|
-
'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
'^.+\\.tsx?$': [
|
|
18
|
+
'ts-jest',
|
|
19
|
+
{
|
|
20
|
+
tsconfig: '<rootDir>/testing/tsconfig.spec.json',
|
|
21
|
+
isolatedModules: true,
|
|
22
|
+
stringifyContentPathRegex: '\\.html$',
|
|
23
|
+
}
|
|
24
|
+
]
|
|
22
25
|
}
|
|
23
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@<%=projectName%>/<%=projectPackageName%>",
|
|
3
|
-
"version": "0.0.0",
|
|
3
|
+
"version": "0.0.0-placeholder",
|
|
4
4
|
"description": "<%=projectPackageName%> - SDK",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"clean": "rimraf test/ test-dev/ dist/ dist-dev/ dist-test/ build/",
|
|
33
33
|
"lint:ci": "eslint '**/*[jt]s' --quiet --format junit --output-file ./dist-lint/result.xml",
|
|
34
34
|
"lint": "eslint '**/*[jt]s' --cache",
|
|
35
|
-
"start": "tsc-watch -b tsconfigs/esm2020 --noClear --onFirstSuccess \"
|
|
36
|
-
"build": "
|
|
35
|
+
"start": "tsc-watch -b tsconfigs/esm2020 --noClear --onFirstSuccess \"<%=packageManager%> run files:pack --watch\"",
|
|
36
|
+
"build": "<%=packageManager%> run build:cjs && <%=packageManager%> run build:esm2015 && <%=packageManager%> run build:esm2020 && <%=packageManager%> run files:pack",
|
|
37
37
|
"build:cjs": "swc src -d dist/cjs -C module.type=commonjs -q",
|
|
38
38
|
"build:esm2015": "swc src -d dist/esm2015 -C module.type=es6 -q",
|
|
39
39
|
"build:esm2020": "tsc -b tsconfigs/esm2020",
|
|
40
|
-
"set:version": "set-version --placeholder 0.0.0",
|
|
40
|
+
"set:version": "set-version --placeholder 0.0.0-placeholder",
|
|
41
41
|
"resolve": "node -e 'process.stdout.write(require.resolve(process.argv[1]));'",
|
|
42
42
|
"generate": "schematics @ama-sdk/schematics:typescript-core --spec-path ./swagger-spec.yaml",
|
|
43
|
-
"spec:regen": "
|
|
43
|
+
"spec:regen": "<%=packageManager%> run generate && <%=packageManager%> exec clear-index",
|
|
44
44
|
"clear-index": "node scripts/clear-index.js",
|
|
45
45
|
"files:pack": "node scripts/files-pack.js",
|
|
46
46
|
"test": "jest --passWithNoTests",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"lint-staged": {
|
|
54
54
|
"**/*.(js|ts)": [
|
|
55
|
-
"
|
|
55
|
+
"<%=packageManager%> exec eslint --quiet --fix --global fast"
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
@@ -94,16 +94,16 @@
|
|
|
94
94
|
"eslint-plugin-prefer-arrow": "<%= versions['eslint-plugin-prefer-arrow'] %>",
|
|
95
95
|
"eslint-plugin-unicorn": "<%= versions['eslint-plugin-unicorn'] %>",
|
|
96
96
|
"glob": "^8.0.0",
|
|
97
|
-
"husky": "
|
|
97
|
+
"husky": "~8.0.3",
|
|
98
98
|
"isomorphic-fetch": "<%= versions['isomorphic-fetch'] %>",
|
|
99
99
|
"jest": "<%= versions['jest'] %>",
|
|
100
|
-
"jest-junit": "
|
|
100
|
+
"jest-junit": "~16.0.0",
|
|
101
101
|
"lint-staged": "^13.0.0",
|
|
102
102
|
"minimist": "^1.2.6",
|
|
103
|
-
"rimraf": "^5.0.
|
|
103
|
+
"rimraf": "^5.0.1",
|
|
104
104
|
"standard-version": "^9.0.0",
|
|
105
105
|
"ts-jest": "<%= versions['ts-jest'] %>",
|
|
106
|
-
"typedoc": "~0.24.
|
|
106
|
+
"typedoc": "~0.24.8",
|
|
107
107
|
"tsc-watch": "^6.0.0",
|
|
108
108
|
"typescript": "<%= versions['typescript'] %>"
|
|
109
109
|
},
|
|
@@ -115,6 +115,5 @@
|
|
|
115
115
|
"node": "<%= engineVersions['node'] %>",
|
|
116
116
|
"npm": "<%= engineVersions['npm'] %>",
|
|
117
117
|
"yarn": "<%= engineVersions['yarn'] %>"
|
|
118
|
-
}
|
|
119
|
-
"packageManager": "yarn@3.6.1"
|
|
118
|
+
}
|
|
120
119
|
}
|
|
@@ -22,6 +22,7 @@ The Code can be regenerated by running the following command:
|
|
|
22
22
|
```shell
|
|
23
23
|
yarn schematics @ama-sdk/sdk:typescript-core --spec-path [path to your swagger file]
|
|
24
24
|
```
|
|
25
|
+
Note that you can use ```npm exec``` instead of ```yarn``` for every command specified in this documentation.
|
|
25
26
|
|
|
26
27
|
***
|
|
27
28
|
|
|
@@ -109,11 +110,95 @@ You can build and run UT with:
|
|
|
109
110
|
yarn test
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
##
|
|
113
|
+
## Manage dates
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
### The timezone issue
|
|
116
|
+
Managing dates with timezones has always been a bit painful in front end applications.
|
|
117
|
+
Let's give a concrete example to understand the problem:
|
|
118
|
+
An API returns the date and hour of your flight in the timezone of the airport location. In our use case, let's say the departure airport is on GTM+7 : 2023-07-10T00:37:00.000+07:00.
|
|
119
|
+
The timezone sent is the one from the airport, here GMT+7. If you just use the Date(), the computer browser will convert this in its own timezone.
|
|
120
|
+
For example, if the user is in GMT+2 you will end up displaying the following: 2023-07-09T19:37:00.000+02:00.
|
|
121
|
+
This is not what you want. You want the exact date time of the flight at the airport timezone, not the one of your user's computer.
|
|
122
|
+
However, there might be cases where you might still need the timezone information.
|
|
123
|
+
For example, you want to be able to display that the flight is in X hours.
|
|
124
|
+
You will need to compute this information with the two timezones -- the airport's and the user's.
|
|
115
125
|
|
|
116
|
-
###
|
|
126
|
+
### Solution proposed to remove the timezone: utils.DateTime
|
|
127
|
+
We have introduced the utils.Date object to replace the Date implementation and ignore the timezone.
|
|
128
|
+
As we need to get rid of the timezones more often than not, this will be our default behavior.
|
|
129
|
+
By default, the Date models are replaced with utils.Date.
|
|
130
|
+
|
|
131
|
+
When we need to keep the timezone information, we create a new field directly in the SDK.
|
|
132
|
+
As this field does not exist in the specification, it will not be part of the base model but of the core model instead.
|
|
133
|
+
|
|
134
|
+
Simple example:
|
|
135
|
+
```yaml
|
|
136
|
+
Flight:
|
|
137
|
+
type: "object"
|
|
138
|
+
required:
|
|
139
|
+
- departureDateTime
|
|
140
|
+
properties:
|
|
141
|
+
departureDateTime:
|
|
142
|
+
type: string
|
|
143
|
+
format: date-time
|
|
144
|
+
```
|
|
145
|
+
Base model generated
|
|
146
|
+
```typescript
|
|
147
|
+
// flight.ts generated in base models
|
|
148
|
+
export interface Flight {
|
|
149
|
+
/** @see utils.DateTime */
|
|
150
|
+
departureDateTime: utils.DateTime;
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
You need to create a core model to store the timezone information (src/models/core/flight.ts):
|
|
154
|
+
```typescript
|
|
155
|
+
import type { IgnoreEnum } from '@ama-sdk/core';
|
|
156
|
+
import type { Flight } from '../../base/flight/flight';
|
|
157
|
+
export type FlightStopCoreIfy<T extends IgnoreEnum<Flight>> = T & {
|
|
158
|
+
/** Departure date time of the flight considering timezone */
|
|
159
|
+
departureDateTimeConsideringTimezone?: Date;
|
|
160
|
+
};
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
And an associated reviver (src/models/core/flight.reviver.ts):
|
|
164
|
+
```typescript
|
|
165
|
+
import type { Flight } from '../../base/flight/flight';
|
|
166
|
+
import type { reviveFlight } from '../../base/flight/flight.reviver';
|
|
167
|
+
import type { FlightCoreIfy } from './flight';
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @param baseRevive
|
|
171
|
+
*/
|
|
172
|
+
export function reviveFlightFactory<R extends typeof reviveFlight>(baseRevive: R) {
|
|
173
|
+
const reviver = <T extends Flight = Flight>(data: any, dictionaries?: any) => {
|
|
174
|
+
const originalData: any = {...data};
|
|
175
|
+
const revivedData = baseRevive<FlightCoreIfy<T>>(data, dictionaries);
|
|
176
|
+
if (!revivedData) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
revivedData.departureDateTimeConsideringTimezone = originalData.departureDateTimeConsideringTimezone && new Date(originalData.departureDateTimeConsideringTimezone)
|
|
180
|
+
|| originalData.departureDateTime && new Date(originalData.departureDateTime);
|
|
181
|
+
return revivedData;
|
|
182
|
+
};
|
|
183
|
+
return reviver;
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
And export it here (src/models/core/flight/index.ts):
|
|
188
|
+
```typescript
|
|
189
|
+
export * from './flight';
|
|
190
|
+
export * from './flight.reviver';
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
And here (src/models/core/index.ts):
|
|
194
|
+
```typescript
|
|
195
|
+
export * from './flight/index';
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
You can now use departureDateTimeConsideringTimezone to access the timezone information.
|
|
199
|
+
See [utils.Date](https://github.com/AmadeusITGroup/otter/blob/main/packages/%40ama-sdk/core/src/fwk/date.ts) for more information.
|
|
200
|
+
|
|
201
|
+
### How to keep the timezone (prevent Date replacement with utils.Date)
|
|
117
202
|
|
|
118
203
|
In order to add the timezone to your timestamp property you can add the x-date-timezone extension in your yaml, for example:
|
|
119
204
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { };
|
|
File without changes
|