@goast/typescript 0.2.19 → 0.3.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.
Files changed (150) hide show
  1. package/README.md +41 -11
  2. package/assets/client/angular/angular-service.utils.ts +80 -80
  3. package/assets/client/angular/request-builder.ts +372 -372
  4. package/assets/client/fetch/fetch-client.utils.ts +52 -52
  5. package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +258 -258
  6. package/cjs/index.js +1 -0
  7. package/cjs/lib/ast/nodes/argument.js +1 -1
  8. package/cjs/lib/ast/nodes/array-type.js +1 -1
  9. package/cjs/lib/ast/nodes/call.js +1 -1
  10. package/cjs/lib/ast/nodes/class.js +1 -1
  11. package/cjs/lib/ast/nodes/constructor-parameter.js +1 -1
  12. package/cjs/lib/ast/nodes/decorator.js +1 -1
  13. package/cjs/lib/ast/nodes/enum-value.js +1 -1
  14. package/cjs/lib/ast/nodes/enum.js +1 -1
  15. package/cjs/lib/ast/nodes/export.js +1 -1
  16. package/cjs/lib/ast/nodes/function.js +1 -1
  17. package/cjs/lib/ast/nodes/generic-parameter.js +1 -1
  18. package/cjs/lib/ast/nodes/indexer.js +1 -1
  19. package/cjs/lib/ast/nodes/interface.js +1 -1
  20. package/cjs/lib/ast/nodes/intersection-type.js +1 -1
  21. package/cjs/lib/ast/nodes/lookup-type.js +1 -1
  22. package/cjs/lib/ast/nodes/method.js +1 -1
  23. package/cjs/lib/ast/nodes/parameter.js +1 -1
  24. package/cjs/lib/ast/nodes/property.js +2 -2
  25. package/cjs/lib/ast/nodes/reference.js +1 -1
  26. package/cjs/lib/ast/nodes/string.js +1 -1
  27. package/cjs/lib/ast/nodes/tuple.js +1 -1
  28. package/cjs/lib/ast/nodes/type-alias.js +1 -1
  29. package/cjs/lib/ast/nodes/typeof.js +1 -1
  30. package/cjs/lib/ast/nodes/union-type.js +1 -1
  31. package/cjs/lib/ast/nodes/variable.js +1 -1
  32. package/cjs/lib/ast/utils/get-type-script-builder-options.js +2 -3
  33. package/cjs/lib/ast/utils/to-ts-node.js +1 -2
  34. package/cjs/lib/ast/utils/write-ts-generic-parameters.js +1 -2
  35. package/cjs/lib/ast/utils/write-ts-members.js +1 -2
  36. package/cjs/lib/ast/utils/write-ts-nodes.js +2 -3
  37. package/cjs/lib/ast/utils/write-ts-parameters.js +1 -2
  38. package/cjs/lib/file-builder.js +2 -2
  39. package/cjs/lib/generators/models/model-generator.js +13 -3
  40. package/cjs/lib/generators/models/models-generator.js +18 -7
  41. package/cjs/lib/generators/models/models.js +13 -2
  42. package/cjs/lib/generators/services/angular-services/angular-service-generator.js +17 -15
  43. package/cjs/lib/generators/services/angular-services/angular-services-generator.js +17 -12
  44. package/cjs/lib/generators/services/angular-services/models.js +19 -3
  45. package/cjs/lib/generators/services/angular-services/refs.js +2 -3
  46. package/cjs/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +13 -12
  47. package/cjs/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -11
  48. package/cjs/lib/generators/services/easy-network-stub/models.js +10 -2
  49. package/cjs/lib/generators/services/easy-network-stub/refs.js +2 -3
  50. package/cjs/lib/generators/services/fetch-clients/fetch-client-generator.js +16 -13
  51. package/cjs/lib/generators/services/fetch-clients/fetch-clients-generator.js +48 -13
  52. package/cjs/lib/generators/services/fetch-clients/models.js +13 -1
  53. package/cjs/lib/generators/services/fetch-clients/refs.js +2 -3
  54. package/cjs/lib/import-collection.js +1 -1
  55. package/cjs/lib/utils.js +5 -6
  56. package/esm/index.js +1 -0
  57. package/esm/lib/ast/nodes/argument.js +1 -1
  58. package/esm/lib/ast/nodes/array-type.js +1 -1
  59. package/esm/lib/ast/nodes/call.js +1 -1
  60. package/esm/lib/ast/nodes/class.js +1 -1
  61. package/esm/lib/ast/nodes/constructor-parameter.js +1 -1
  62. package/esm/lib/ast/nodes/decorator.js +1 -1
  63. package/esm/lib/ast/nodes/enum-value.js +1 -1
  64. package/esm/lib/ast/nodes/enum.js +1 -1
  65. package/esm/lib/ast/nodes/export.js +1 -1
  66. package/esm/lib/ast/nodes/function.js +1 -1
  67. package/esm/lib/ast/nodes/generic-parameter.js +1 -1
  68. package/esm/lib/ast/nodes/indexer.js +1 -1
  69. package/esm/lib/ast/nodes/interface.js +1 -1
  70. package/esm/lib/ast/nodes/intersection-type.js +1 -1
  71. package/esm/lib/ast/nodes/lookup-type.js +1 -1
  72. package/esm/lib/ast/nodes/method.js +1 -1
  73. package/esm/lib/ast/nodes/parameter.js +1 -1
  74. package/esm/lib/ast/nodes/property.js +2 -2
  75. package/esm/lib/ast/nodes/reference.js +1 -1
  76. package/esm/lib/ast/nodes/string.js +1 -1
  77. package/esm/lib/ast/nodes/tuple.js +1 -1
  78. package/esm/lib/ast/nodes/type-alias.js +1 -1
  79. package/esm/lib/ast/nodes/typeof.js +1 -1
  80. package/esm/lib/ast/nodes/union-type.js +1 -1
  81. package/esm/lib/ast/nodes/variable.js +1 -1
  82. package/esm/lib/ast/utils/get-type-script-builder-options.js +1 -1
  83. package/esm/lib/generators/models/model-generator.js +13 -3
  84. package/esm/lib/generators/models/models-generator.js +18 -7
  85. package/esm/lib/generators/models/models.js +13 -2
  86. package/esm/lib/generators/services/angular-services/angular-service-generator.js +17 -15
  87. package/esm/lib/generators/services/angular-services/angular-services-generator.js +17 -12
  88. package/esm/lib/generators/services/angular-services/models.js +19 -3
  89. package/esm/lib/generators/services/angular-services/refs.js +1 -1
  90. package/esm/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +13 -12
  91. package/esm/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -11
  92. package/esm/lib/generators/services/easy-network-stub/models.js +10 -2
  93. package/esm/lib/generators/services/easy-network-stub/refs.js +1 -1
  94. package/esm/lib/generators/services/fetch-clients/fetch-client-generator.js +16 -13
  95. package/esm/lib/generators/services/fetch-clients/fetch-clients-generator.js +46 -11
  96. package/esm/lib/generators/services/fetch-clients/models.js +13 -1
  97. package/esm/lib/generators/services/fetch-clients/refs.js +1 -1
  98. package/esm/lib/import-collection.js +1 -1
  99. package/package.json +8 -3
  100. package/types/index.d.ts +1 -0
  101. package/types/lib/ast/nodes/argument.d.ts +1 -1
  102. package/types/lib/ast/nodes/array-type.d.ts +1 -1
  103. package/types/lib/ast/nodes/arrow-function.d.ts +1 -1
  104. package/types/lib/ast/nodes/call.d.ts +1 -1
  105. package/types/lib/ast/nodes/class.d.ts +1 -1
  106. package/types/lib/ast/nodes/constructor-parameter.d.ts +1 -1
  107. package/types/lib/ast/nodes/constructor.d.ts +1 -1
  108. package/types/lib/ast/nodes/decorator.d.ts +2 -2
  109. package/types/lib/ast/nodes/doc.d.ts +1 -1
  110. package/types/lib/ast/nodes/enum-value.d.ts +2 -2
  111. package/types/lib/ast/nodes/enum.d.ts +1 -1
  112. package/types/lib/ast/nodes/export.d.ts +2 -2
  113. package/types/lib/ast/nodes/function-type.d.ts +1 -1
  114. package/types/lib/ast/nodes/function.d.ts +1 -1
  115. package/types/lib/ast/nodes/generic-parameter.d.ts +1 -1
  116. package/types/lib/ast/nodes/indexer.d.ts +1 -1
  117. package/types/lib/ast/nodes/interface.d.ts +1 -1
  118. package/types/lib/ast/nodes/intersection-type.d.ts +1 -1
  119. package/types/lib/ast/nodes/lookup-type.d.ts +1 -1
  120. package/types/lib/ast/nodes/method.d.ts +2 -2
  121. package/types/lib/ast/nodes/object-type.d.ts +1 -1
  122. package/types/lib/ast/nodes/object.d.ts +1 -1
  123. package/types/lib/ast/nodes/parameter.d.ts +1 -1
  124. package/types/lib/ast/nodes/property-accessor.d.ts +2 -2
  125. package/types/lib/ast/nodes/property.d.ts +15 -15
  126. package/types/lib/ast/nodes/reference.d.ts +4 -4
  127. package/types/lib/ast/nodes/string.d.ts +1 -1
  128. package/types/lib/ast/nodes/tuple.d.ts +1 -1
  129. package/types/lib/ast/nodes/type-alias.d.ts +1 -1
  130. package/types/lib/ast/nodes/typeof.d.ts +2 -2
  131. package/types/lib/ast/nodes/union-type.d.ts +1 -1
  132. package/types/lib/ast/nodes/variable.d.ts +1 -1
  133. package/types/lib/ast/references/angular.d.ts +8 -8
  134. package/types/lib/ast/references/easy-network-stub.d.ts +6 -6
  135. package/types/lib/ast/references/rxjs.d.ts +5 -5
  136. package/types/lib/ast/references/typescript.d.ts +46 -46
  137. package/types/lib/common-results.d.ts +1 -0
  138. package/types/lib/config.d.ts +53 -9
  139. package/types/lib/generators/models/model-generator.d.ts +1 -1
  140. package/types/lib/generators/models/models.d.ts +43 -8
  141. package/types/lib/generators/services/angular-services/angular-services-generator.d.ts +1 -1
  142. package/types/lib/generators/services/angular-services/models.d.ts +61 -20
  143. package/types/lib/generators/services/angular-services/refs.d.ts +9 -9
  144. package/types/lib/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +1 -1
  145. package/types/lib/generators/services/easy-network-stub/models.d.ts +35 -13
  146. package/types/lib/generators/services/easy-network-stub/refs.d.ts +14 -14
  147. package/types/lib/generators/services/fetch-clients/fetch-clients-generator.d.ts +4 -1
  148. package/types/lib/generators/services/fetch-clients/models.d.ts +63 -18
  149. package/types/lib/generators/services/fetch-clients/refs.d.ts +4 -4
  150. package/types/lib/utils.d.ts +2 -1
@@ -30,7 +30,7 @@ export class TsGenericParameter extends TsNode {
30
30
  }
31
31
  }
32
32
  }
33
- const createGenericParameter = (name, options) => new TsGenericParameter(Object.assign(Object.assign({}, options), { name }));
33
+ const createGenericParameter = (name, options) => new TsGenericParameter({ ...options, name });
34
34
  export const tsGenericParameter = Object.assign(createGenericParameter, {
35
35
  write: writeTsGenericParameters,
36
36
  });
@@ -22,7 +22,7 @@ export class TsIndexer extends TsNode {
22
22
  builder.appendLine();
23
23
  }
24
24
  }
25
- const createIndexer = (keyType, valueType, options) => new TsIndexer(Object.assign(Object.assign({}, options), { keyType, valueType }));
25
+ const createIndexer = (keyType, valueType, options) => new TsIndexer({ ...options, keyType, valueType });
26
26
  export const tsIndexer = Object.assign(createIndexer, {
27
27
  write: writeTsNodes,
28
28
  });
@@ -50,7 +50,7 @@ export class TsInterface extends TsNode {
50
50
  builder.appendLine();
51
51
  }
52
52
  }
53
- const createInterface = (name, options) => new TsInterface(Object.assign(Object.assign({}, options), { name }));
53
+ const createInterface = (name, options) => new TsInterface({ ...options, name });
54
54
  export const tsInterface = Object.assign(createInterface, {
55
55
  write: writeTsNodes,
56
56
  });
@@ -22,7 +22,7 @@ export class TsIntersectionType extends TsNode {
22
22
  }
23
23
  }
24
24
  }
25
- const createIntersectionType = (types, options) => new TsIntersectionType(Object.assign(Object.assign({}, options), { types }));
25
+ const createIntersectionType = (types, options) => new TsIntersectionType({ ...options, types });
26
26
  export const tsIntersectionType = Object.assign(createIntersectionType, {
27
27
  write: writeTsNodes,
28
28
  });
@@ -20,7 +20,7 @@ export class TsLookupType extends TsNode {
20
20
  });
21
21
  }
22
22
  }
23
- const createLookupType = (type, index, options) => new TsLookupType(Object.assign(Object.assign({}, options), { type, index }));
23
+ const createLookupType = (type, index, options) => new TsLookupType({ ...options, type, index });
24
24
  export const tsLookupType = Object.assign(createLookupType, {
25
25
  write: writeTsNodes,
26
26
  });
@@ -71,7 +71,7 @@ export class TsMethod extends TsNode {
71
71
  builder.appendLine();
72
72
  }
73
73
  }
74
- export const createMethod = (name, options) => new TsMethod(Object.assign(Object.assign({}, options), { name }));
74
+ export const createMethod = (name, options) => new TsMethod({ ...options, name });
75
75
  export const tsMethod = Object.assign(createMethod, {
76
76
  write: writeTsNodes,
77
77
  });
@@ -35,7 +35,7 @@ export class TsParameter extends TsNode {
35
35
  }
36
36
  }
37
37
  }
38
- const createParameter = (name, options) => new TsParameter(Object.assign(Object.assign({}, options), { name }));
38
+ const createParameter = (name, options) => new TsParameter({ ...options, name });
39
39
  export const tsParameter = Object.assign(createParameter, {
40
40
  write: writeTsParameters,
41
41
  });
@@ -102,9 +102,9 @@ export class TsAccessorProperty extends TsProperty {
102
102
  }
103
103
  const createProperty = (name, options) => {
104
104
  if (options && ('get' in options || 'set' in options)) {
105
- return new TsAccessorProperty(Object.assign(Object.assign({}, options), { name }));
105
+ return new TsAccessorProperty({ ...options, name });
106
106
  }
107
- return new TsSimpleProperty(Object.assign(Object.assign({}, options), { name }));
107
+ return new TsSimpleProperty({ ...options, name });
108
108
  };
109
109
  export const tsProperty = Object.assign(createProperty, {
110
110
  write: writeTsNodes,
@@ -32,7 +32,7 @@ TsReference.addImportHandlers = [
32
32
  handler: (builder, reference) => builder.addImport(reference.name, reference.moduleNameOrfilePath),
33
33
  },
34
34
  ];
35
- const createReference = (name, moduleNameOrfilePath, options) => new TsReference(Object.assign(Object.assign({}, options), { name, moduleNameOrfilePath }));
35
+ const createReference = (name, moduleNameOrfilePath, options) => new TsReference({ ...options, name, moduleNameOrfilePath });
36
36
  function _createFactory(name, moduleNameOrfilePath) {
37
37
  return Object.assign(() => createReference(name, moduleNameOrfilePath), {
38
38
  refName: name,
@@ -20,7 +20,7 @@ export class TsString extends TsNode {
20
20
  builder.append(value);
21
21
  }
22
22
  }
23
- const createString = (value, options) => new TsString(Object.assign(Object.assign({}, options), { value }));
23
+ const createString = (value, options) => new TsString({ ...options, value });
24
24
  export const tsString = Object.assign(createString, {
25
25
  write: writeTsNodes,
26
26
  });
@@ -23,7 +23,7 @@ export class TsTuple extends TsNode {
23
23
  }
24
24
  }
25
25
  }
26
- const createTuple = (elements, options) => new TsTuple(Object.assign(Object.assign({}, options), { elements }));
26
+ const createTuple = (elements, options) => new TsTuple({ ...options, elements });
27
27
  export const tsTuple = Object.assign(createTuple, {
28
28
  write: writeTsNodes,
29
29
  });
@@ -28,7 +28,7 @@ export class TsTypeAlias extends TsNode {
28
28
  builder.appendLine();
29
29
  }
30
30
  }
31
- const createTypeAlias = (name, type, options) => new TsTypeAlias(Object.assign(Object.assign({}, options), { name, type }));
31
+ const createTypeAlias = (name, type, options) => new TsTypeAlias({ ...options, name, type });
32
32
  export const tsTypeAlias = Object.assign(createTypeAlias, {
33
33
  write: writeTsNodes,
34
34
  });
@@ -12,7 +12,7 @@ export class TsTypeof extends TsNode {
12
12
  builder.append(this.inject.afterValue);
13
13
  }
14
14
  }
15
- export const createTypeof = (value, options) => new TsTypeof(Object.assign(Object.assign({}, options), { value }));
15
+ export const createTypeof = (value, options) => new TsTypeof({ ...options, value });
16
16
  export const tsTypeof = Object.assign(createTypeof, {
17
17
  write: writeTsNodes,
18
18
  });
@@ -22,7 +22,7 @@ export class TsUnionType extends TsNode {
22
22
  }
23
23
  }
24
24
  }
25
- const createUnionType = (types, options) => new TsUnionType(Object.assign(Object.assign({}, options), { types }));
25
+ const createUnionType = (types, options) => new TsUnionType({ ...options, types });
26
26
  export const tsUnionType = Object.assign(createUnionType, {
27
27
  write: writeTsNodes,
28
28
  });
@@ -30,7 +30,7 @@ export class TsVariable extends TsNode {
30
30
  builder.appendLine();
31
31
  }
32
32
  }
33
- const createVariable = (name, options) => new TsVariable(Object.assign(Object.assign({}, options), { name }));
33
+ const createVariable = (name, options) => new TsVariable({ ...options, name });
34
34
  export const tsVariable = Object.assign(createVariable, {
35
35
  write: writeTsNodes,
36
36
  });
@@ -9,7 +9,7 @@ export function getTypeScriptBuilderOptions(builder) {
9
9
  if (tsConfigSymbol in builder.options) {
10
10
  return builder.options[tsConfigSymbol];
11
11
  }
12
- const options = Object.assign(Object.assign(Object.assign({}, defaultOpenApiGeneratorConfig), defaultTypeScriptGeneratorConfig), builder.options);
12
+ const options = { ...defaultOpenApiGeneratorConfig, ...defaultTypeScriptGeneratorConfig, ...builder.options };
13
13
  builder[tsConfigSymbol] = options;
14
14
  return options;
15
15
  }
@@ -8,13 +8,22 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
8
8
  if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
9
9
  const name = this.getDeclarationTypeName(ctx, ctx.schema);
10
10
  const filePath = this.getFilePath(ctx, ctx.schema);
11
+ const fileContent = this.getFileContent(ctx);
11
12
  TypeScriptFileBuilder.generate({
12
13
  logName: `model ${name}`,
13
14
  filePath,
14
15
  options: ctx.config,
15
- generator: (b) => b.append(this.getFileContent(ctx)),
16
+ generator: (b) => b.append(fileContent),
16
17
  });
17
- return { component: name, filePath, imports: [{ kind: 'file', name, modulePath: filePath }] };
18
+ return {
19
+ component: name,
20
+ filePath,
21
+ imports: [{ kind: 'file', name, modulePath: filePath }],
22
+ additionalExports: fileContent.values
23
+ .filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
24
+ .filter((x) => x.name !== name)
25
+ .map((x) => x.name),
26
+ };
18
27
  }
19
28
  else {
20
29
  const builder = new TypeScriptFileBuilder(undefined, ctx.config);
@@ -318,6 +327,7 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
318
327
  .filter((item, index, self) => self.indexOf(item) === index);
319
328
  }
320
329
  getFilePath(ctx, schema) {
321
- return resolve(ctx.config.outputDir, ctx.config.modelsDirPath, `${toCasing(schema.name, ctx.config.fileNameCasing)}.ts`);
330
+ var _a;
331
+ return resolve(ctx.config.outputDir, ctx.config.modelsDir, `${toCasing(schema.name, (_a = ctx.config.modelFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
322
332
  }
323
333
  }
@@ -11,8 +11,10 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
11
11
  }
12
12
  initResult() {
13
13
  return {
14
- models: {},
15
- indexFiles: { models: undefined },
14
+ typescript: {
15
+ models: {},
16
+ indexFiles: { models: undefined },
17
+ },
16
18
  };
17
19
  }
18
20
  buildContext(context, config) {
@@ -20,15 +22,18 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
20
22
  }
21
23
  onGenerate(ctx) {
22
24
  const output = super.onGenerate(ctx);
23
- output.indexFiles.models = this.generateIndexFile(ctx);
25
+ output.typescript.indexFiles.models = this.generateIndexFile(ctx);
24
26
  return output;
25
27
  }
26
28
  generateSchema(ctx, schema) {
27
29
  const modelGenerator = this._modelGeneratorFactory.create();
28
- return modelGenerator.generate(Object.assign(Object.assign({}, ctx), { schema }));
30
+ return modelGenerator.generate({
31
+ ...ctx,
32
+ schema,
33
+ });
29
34
  }
30
35
  addSchemaResult(ctx, schema, result) {
31
- ctx.output.models[schema.id] = result;
36
+ ctx.output.typescript.models[schema.id] = result;
32
37
  }
33
38
  generateIndexFile(ctx) {
34
39
  const filePath = this.getIndexFilePath(ctx);
@@ -41,9 +46,15 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
41
46
  return filePath;
42
47
  }
43
48
  getIndexFilePath(ctx) {
44
- return ctx.config.indexFilePath ? resolve(ctx.config.outputDir, ctx.config.indexFilePath) : null;
49
+ return ctx.config.modelsIndexFile ? resolve(ctx.config.outputDir, ctx.config.modelsIndexFile) : null;
45
50
  }
46
51
  getIndexFileContent(ctx) {
47
- return appendValueGroup(Object.values(ctx.output.models).map((x) => (x.filePath ? ts.export(x.component, x.filePath) : null)));
52
+ return appendValueGroup(Object.values(ctx.output.typescript.models).flatMap((x) => {
53
+ var _a, _b;
54
+ const { filePath } = x;
55
+ if (!filePath)
56
+ return [];
57
+ return [ts.export(x.component, filePath), ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => ts.export(e, filePath))) !== null && _b !== void 0 ? _b : [])];
58
+ }));
48
59
  }
49
60
  }
@@ -1,3 +1,14 @@
1
1
  import { defaultTypeScriptGeneratorConfig } from '../../config';
2
- export const defaultTypeScriptModelGeneratorConfig = Object.assign(Object.assign({}, defaultTypeScriptGeneratorConfig), { enumGeneration: 'union', immutableTypes: false, inlineUnnamedSchemas: true, modelsDirPath: 'models', typeDeclaration: 'type' });
3
- export const defaultTypeScriptModelsGeneratorConfig = Object.assign(Object.assign({}, defaultTypeScriptModelGeneratorConfig), { indexFilePath: 'models.ts' });
2
+ export const defaultTypeScriptModelGeneratorConfig = {
3
+ ...defaultTypeScriptGeneratorConfig,
4
+ enumGeneration: 'union',
5
+ immutableTypes: false,
6
+ inlineUnnamedSchemas: true,
7
+ modelsDir: 'models',
8
+ modelFileNameCasing: undefined,
9
+ typeDeclaration: 'type',
10
+ };
11
+ export const defaultTypeScriptModelsGeneratorConfig = {
12
+ ...defaultTypeScriptModelGeneratorConfig,
13
+ modelsIndexFile: 'models.ts',
14
+ };
@@ -99,7 +99,7 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
99
99
  parser: (_a = value === null || value === void 0 ? void 0 : value.parser) !== null && _a !== void 0 ? _a : 'text',
100
100
  type: typeof (value === null || value === void 0 ? void 0 : value.type) === 'function'
101
101
  ? this.getSchemaType(ctx, value.type(ctx.data.schemas))
102
- : value !== null && value !== void 0 ? value : ts.refs.never(),
102
+ : (value !== null && value !== void 0 ? value : ts.refs.never()),
103
103
  },
104
104
  ];
105
105
  }),
@@ -137,7 +137,7 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
137
137
  description: parameter.description,
138
138
  tags: [parameter.deprecated ? ts.docTag('deprecated') : null],
139
139
  }),
140
- type: schema ? (b) => b.appendModelUsage(ctx.input.models[schema.id]) : this.getAnyType(ctx),
140
+ type: schema ? (b) => b.appendModelUsage(ctx.input.typescript.models[schema.id]) : this.getAnyType(ctx),
141
141
  optional: !parameter.required,
142
142
  }));
143
143
  }
@@ -146,7 +146,7 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
146
146
  const schema = body.content[0].schema;
147
147
  type.members.push(ts.property('body', {
148
148
  doc: ts.doc({ description: body.description }),
149
- type: schema ? (b) => b.appendModelUsage(ctx.input.models[schema.id]) : this.getAnyType(ctx),
149
+ type: schema ? (b) => b.appendModelUsage(ctx.input.typescript.models[schema.id]) : this.getAnyType(ctx),
150
150
  optional: !body.required,
151
151
  }));
152
152
  }
@@ -228,13 +228,13 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
228
228
  }
229
229
  : null,
230
230
  '',
231
- s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
232
- this.http.request(rb.build({${s.indent `
233
- responseType: ${ts.string(responseType)},
234
- accept: ${ts.string(accept)},
235
- context,`}
236
- })),
237
- {${s.indent `
231
+ s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
232
+ this.http.request(rb.build({${s.indent `
233
+ responseType: ${ts.string(responseType)},
234
+ accept: ${ts.string(accept)},
235
+ context,`}
236
+ })),
237
+ {${s.indent `
238
238
  errorResponseTypes: ${ts.object({
239
239
  members: [
240
240
  ...Object.entries(this.getEndpointStatusCodes(ctx, endpoint))
@@ -243,8 +243,8 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
243
243
  return ts.property(key, { value: ts.string(value.parser) });
244
244
  }),
245
245
  ],
246
- })}`}
247
- }`}
246
+ })}`}
247
+ }`}
248
248
  )`,
249
249
  ], '\n'),
250
250
  });
@@ -269,16 +269,18 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
269
269
  return toCasing(endpoint.name, ctx.config.functionNameCasing);
270
270
  }
271
271
  getServiceFilePath(ctx) {
272
- return resolve(ctx.config.outputDir, ctx.config.servicesDirPath, `${toCasing(ctx.service.name, ctx.config.fileNameCasing)}.ts`);
272
+ var _a;
273
+ return resolve(ctx.config.outputDir, ctx.config.servicesDir, `${toCasing(ctx.service.name, (_a = ctx.config.serviceFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
273
274
  }
274
275
  getResponseModelFilePath(ctx) {
275
- return resolve(ctx.config.outputDir, ctx.config.responseModelsDirPath, `${toCasing(ctx.service.name, ctx.config.responseModelFileNameCasing)}.ts`);
276
+ var _a;
277
+ return resolve(ctx.config.outputDir, ctx.config.responseModelsDir, `${toCasing(ctx.service.name, (_a = ctx.config.responseModelFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
276
278
  }
277
279
  hasEndpointParams(ctx, endpoint) {
278
280
  return endpoint.parameters.length > 0 || endpoint.requestBody !== undefined;
279
281
  }
280
282
  getSchemaType(ctx, schema, fallback) {
281
- const output = schema && ctx.input.models[schema.id];
283
+ const output = schema && ctx.input.typescript.models[schema.id];
282
284
  if (!output)
283
285
  return fallback !== null && fallback !== void 0 ? fallback : this.getAnyType(ctx);
284
286
  return (b) => b.appendModelUsage(output);
@@ -15,8 +15,10 @@ export class TypeScriptAngularServicesGenerator extends OpenApiServicesGeneratio
15
15
  }
16
16
  initResult() {
17
17
  return {
18
- services: {},
19
- indexFiles: { services: undefined, responseModels: undefined },
18
+ typescript: {
19
+ services: {},
20
+ indexFiles: { services: undefined, responseModels: undefined },
21
+ },
20
22
  };
21
23
  }
22
24
  buildContext(context, config) {
@@ -28,20 +30,23 @@ export class TypeScriptAngularServicesGenerator extends OpenApiServicesGeneratio
28
30
  onGenerate(ctx) {
29
31
  const output = super.onGenerate(ctx);
30
32
  this.generateUtilsFiles(ctx);
31
- output.indexFiles = this.generateIndexFiles(ctx);
33
+ output.typescript.indexFiles = this.generateIndexFiles(ctx);
32
34
  return output;
33
35
  }
34
36
  generateService(ctx, service) {
35
37
  const clientGenerator = this._clientGeneratorFactory.create();
36
- return clientGenerator.generate(Object.assign(Object.assign({}, ctx), { service }));
38
+ return clientGenerator.generate({
39
+ ...ctx,
40
+ service,
41
+ });
37
42
  }
38
43
  addServiceResult(ctx, service, result) {
39
- ctx.output.services[service.id] = result;
44
+ ctx.output.typescript.services[service.id] = result;
40
45
  }
41
46
  // #region Utils
42
47
  generateUtilsFiles(ctx) {
43
48
  const sourceDir = resolve(dirname(require.resolve('@goast/typescript')), '../assets/client/angular');
44
- const targetDir = resolve(ctx.config.outputDir, ctx.config.utilsDirPath);
49
+ const targetDir = resolve(ctx.config.outputDir, ctx.config.utilsDir);
45
50
  ensureDirSync(targetDir);
46
51
  this.copyFile('Request Builder', sourceDir, targetDir, 'request-builder.ts');
47
52
  this.copyFile('Angular Service Utils', sourceDir, targetDir, 'angular-service.utils.ts');
@@ -146,7 +151,7 @@ export class TypeScriptAngularServicesGenerator extends OpenApiServicesGeneratio
146
151
  'return ',
147
152
  ts.tuple([
148
153
  (b) => b.append('config ? { provide: ', ctx.refs.apiConfiguration(), ', useValue: config } : ', ctx.refs.apiConfiguration()),
149
- ...Object.values(ctx.output.services).map((x) => ts.reference(x.component, x.filePath)),
154
+ ...Object.values(ctx.output.typescript.services).map((x) => ts.reference(x.component, x.filePath)),
150
155
  ]),
151
156
  ';',
152
157
  ]),
@@ -185,20 +190,20 @@ export class TypeScriptAngularServicesGenerator extends OpenApiServicesGeneratio
185
190
  ctx.config.provideKind === 'provide-fn'
186
191
  ? ts.export(ctx.refs.provide.refName, ctx.refs.provide.moduleNameOrfilePath)
187
192
  : null,
188
- ...Object.values(ctx.output.services).map((x) => ts.export(x.component, x.filePath)),
193
+ ...Object.values(ctx.output.typescript.services).map((x) => ts.export(x.component, x.filePath)),
189
194
  ]);
190
195
  }
191
196
  getResponseModelsIndexFileContent(ctx) {
192
- return appendValueGroup(Object.values(ctx.output.services)
197
+ return appendValueGroup(Object.values(ctx.output.typescript.services)
193
198
  .flatMap((x) => Object.values(x.responseModels))
194
199
  .map((x) => ts.export(x.component, x.filePath)));
195
200
  }
196
201
  getServicesIndexFilePath(ctx) {
197
- return ctx.config.servicesIndexFilePath ? resolve(ctx.config.outputDir, ctx.config.servicesIndexFilePath) : null;
202
+ return ctx.config.servicesIndexFile ? resolve(ctx.config.outputDir, ctx.config.servicesIndexFile) : null;
198
203
  }
199
204
  getResponseModelsIndexFilePath(ctx) {
200
- return ctx.config.responseModelsIndexFilePath
201
- ? resolve(ctx.config.outputDir, ctx.config.responseModelsIndexFilePath)
205
+ return ctx.config.responseModelsIndexFile
206
+ ? resolve(ctx.config.outputDir, ctx.config.responseModelsIndexFile)
202
207
  : null;
203
208
  }
204
209
  // #endregion
@@ -1,10 +1,26 @@
1
1
  import { defaultTypeScriptGeneratorConfig } from '../../../config';
2
- export const defaultTypeScriptAngularServicesGeneratorConfig = Object.assign(Object.assign({}, defaultTypeScriptGeneratorConfig), { fileNameCasing: { casing: 'kebab', suffix: '.service' }, responseModelFileNameCasing: { casing: 'kebab', suffix: '-responses.model' }, provideKind: 'provide-fn', strictResponseTypes: true, defaultStatusCodeResponseTypes: {
2
+ export const defaultTypeScriptAngularServicesGeneratorConfig = {
3
+ ...defaultTypeScriptGeneratorConfig,
4
+ provideKind: 'provide-fn',
5
+ domainName: undefined,
6
+ strictResponseTypes: true,
7
+ defaultStatusCodeResponseTypes: {
3
8
  401: null,
4
9
  403: null,
5
10
  500: null,
6
- }, possibleStatusCodes: [
11
+ },
12
+ possibleStatusCodes: [
7
13
  100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308,
8
14
  400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 425,
9
15
  426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,
10
- ], servicesDirPath: 'services', servicesIndexFilePath: 'services.ts', responseModelsDirPath: 'models/responses', responseModelsIndexFilePath: 'responses.ts', utilsDirPath: 'utils' });
16
+ ],
17
+ rootUrl: undefined,
18
+ pathModifier: undefined,
19
+ servicesDir: 'services',
20
+ serviceFileNameCasing: { casing: 'kebab', suffix: '.service' },
21
+ servicesIndexFile: 'services.ts',
22
+ responseModelsDir: 'models/responses',
23
+ responseModelFileNameCasing: { casing: 'kebab', suffix: '-responses.model' },
24
+ responseModelsIndexFile: 'responses.ts',
25
+ utilsDir: 'utils',
26
+ };
@@ -4,7 +4,7 @@ import { ts } from '../../../ast';
4
4
  // See packages/typescript/assets/client/angular for reference
5
5
  export function getReferenceFactories(options) {
6
6
  var _a, _b;
7
- const utilsDirPath = resolve(options.outputDir, options.utilsDirPath);
7
+ const utilsDirPath = resolve(options.outputDir, options.utilsDir);
8
8
  return {
9
9
  // angular-service.utils.ts
10
10
  abortablePromise: ts.reference.genericFactory('AbortablePromise', join(utilsDirPath, 'angular-service.utils.ts')),
@@ -94,22 +94,23 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
94
94
  ],
95
95
  returnType: 'this',
96
96
  body: appendValueGroup([
97
- s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
98
- ${ts.string(endpoint.method.toUpperCase())},
99
- ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
100
- async (request) => {${s.indent `
101
- if (this.stubWrapper.options.rememberRequests) {${s.indent `
102
- this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
103
- }
104
- throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
105
- }`}
97
+ s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
98
+ ${ts.string(endpoint.method.toUpperCase())},
99
+ ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
100
+ async (request) => {${s.indent `
101
+ if (this.stubWrapper.options.rememberRequests) {${s.indent `
102
+ this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
103
+ }
104
+ throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
105
+ }`}
106
106
  );`,
107
107
  'return this;',
108
108
  ], '\n'),
109
109
  });
110
110
  }
111
111
  getStubFilePath(ctx) {
112
- return resolve(ctx.config.outputDir, ctx.config.stubsDirPath, `${toCasing(ctx.service.name, ctx.config.fileNameCasing)}.ts`);
112
+ var _a;
113
+ return resolve(ctx.config.outputDir, ctx.config.stubsDir, `${toCasing(ctx.service.name, (_a = ctx.config.stubFileNameCasing) !== null && _a !== void 0 ? _a : ctx.config.fileNameCasing)}.ts`);
113
114
  }
114
115
  getResponderVariableName(ctx, endpoint) {
115
116
  return toCasing(endpoint.name + '_Responder', ctx.config.propertyNameCasing);
@@ -134,7 +135,7 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
134
135
  let path = endpoint.path;
135
136
  let isFirstQueryParam = true;
136
137
  for (const param of endpoint.parameters) {
137
- let type = ((_b = (param.schema && ((_a = ctx.input.models[param.schema.id]) === null || _a === void 0 ? void 0 : _a.component))) !== null && _b !== void 0 ? _b : ts.refs.unknown.name).replace(/^readonly /, '');
138
+ let type = ((_b = (param.schema && ((_a = ctx.input.typescript.models[param.schema.id]) === null || _a === void 0 ? void 0 : _a.component))) !== null && _b !== void 0 ? _b : ts.refs.unknown.name).replace(/^readonly /, '');
138
139
  const arrayMatch = /^\((.*)\)\[\]$/.exec(type);
139
140
  if (arrayMatch !== null) {
140
141
  type = `${arrayMatch[1]}[]`;
@@ -161,7 +162,7 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
161
162
  ]);
162
163
  }
163
164
  getSchemaType(ctx, schema, fallback) {
164
- const output = schema && ctx.input.models[schema.id];
165
+ const output = schema && ctx.input.typescript.models[schema.id];
165
166
  if (!output)
166
167
  return fallback !== null && fallback !== void 0 ? fallback : this.getAnyType(ctx);
167
168
  return (b) => b.appendModelUsage(output);
@@ -13,8 +13,10 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
13
13
  }
14
14
  initResult() {
15
15
  return {
16
- stubs: {},
17
- indexFiles: { stubs: undefined },
16
+ typescript: {
17
+ stubs: {},
18
+ indexFiles: { stubs: undefined },
19
+ },
18
20
  };
19
21
  }
20
22
  buildContext(context, config) {
@@ -26,19 +28,22 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
26
28
  onGenerate(ctx) {
27
29
  const output = super.onGenerate(ctx);
28
30
  this.generateUtilsFiles(ctx);
29
- output.indexFiles = this.generateIndexFiles(ctx);
31
+ output.typescript.indexFiles = this.generateIndexFiles(ctx);
30
32
  return output;
31
33
  }
32
34
  generateService(ctx, service) {
33
35
  const clientGenerator = this._generatorFactory.create();
34
- return clientGenerator.generate(Object.assign(Object.assign({}, ctx), { service }));
36
+ return clientGenerator.generate({
37
+ ...ctx,
38
+ service,
39
+ });
35
40
  }
36
41
  addServiceResult(ctx, service, result) {
37
- ctx.output.stubs[service.id] = result;
42
+ ctx.output.typescript.stubs[service.id] = result;
38
43
  }
39
44
  generateUtilsFiles(ctx) {
40
45
  const sourceDir = resolve(dirname(require.resolve('@goast/typescript')), '../assets/stubs/easy-network-stub');
41
- const targetDir = resolve(ctx.config.outputDir, ctx.config.utilsDirPath);
46
+ const targetDir = resolve(ctx.config.outputDir, ctx.config.utilsDir);
42
47
  ensureDirSync(targetDir);
43
48
  this.copyFile('easy-network-stub utils', sourceDir, targetDir, 'easy-network-stub.utils.ts');
44
49
  }
@@ -56,7 +61,7 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
56
61
  }
57
62
  getStubsIndexFileContent(ctx) {
58
63
  return appendValueGroup([
59
- appendValueGroup(Object.values(ctx.output.stubs).map((x) => ts.export(x.component, x.filePath))),
64
+ appendValueGroup(Object.values(ctx.output.typescript.stubs).map((x) => ts.export(x.component, x.filePath))),
60
65
  this.getStubsClass(ctx),
61
66
  ], '\n');
62
67
  }
@@ -71,7 +76,7 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
71
76
  readonly: true,
72
77
  type: ctx.refs.easyNetworkStubWrapper(),
73
78
  }),
74
- ...Object.entries(ctx.output.stubs).map(([id, x]) => ts.property(toCasing(serviceNames[id], fieldCasing), {
79
+ ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ts.property(toCasing(serviceNames[id], fieldCasing), {
75
80
  accessModifier: 'private',
76
81
  optional: true,
77
82
  type: ctx.refs.easyNetworkStubGroup([ts.reference(x.component, x.filePath), 'this']),
@@ -93,7 +98,7 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
93
98
  body: appendValueGroup(['return this._stubWrapper.requests;'], '\n'),
94
99
  }),
95
100
  }),
96
- ...Object.entries(ctx.output.stubs).map(([id, x]) => ts.property(toCasing(serviceNames[id], ctx.config.propertyNameCasing), {
101
+ ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ts.property(toCasing(serviceNames[id], ctx.config.propertyNameCasing), {
97
102
  accessModifier: 'public',
98
103
  type: ctx.refs.easyNetworkStubGroup([ts.reference(x.component, x.filePath), 'this']),
99
104
  get: ts.property.getter({
@@ -106,7 +111,7 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
106
111
  accessModifier: 'public',
107
112
  returnType: 'this',
108
113
  body: appendValueGroup([
109
- ...Object.keys(ctx.output.stubs).map((id) => `this.${toCasing(serviceNames[id], fieldCasing)}?.reset();`),
114
+ ...Object.keys(ctx.output.typescript.stubs).map((id) => `this.${toCasing(serviceNames[id], fieldCasing)}?.reset();`),
110
115
  'return this;',
111
116
  ], '\n'),
112
117
  }),
@@ -114,7 +119,7 @@ export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerati
114
119
  });
115
120
  }
116
121
  getStubsIndexFilePath(ctx) {
117
- return ctx.config.stubsIndexFilePath ? resolve(ctx.config.outputDir, ctx.config.stubsIndexFilePath) : null;
122
+ return ctx.config.stubsIndexFile ? resolve(ctx.config.outputDir, ctx.config.stubsIndexFile) : null;
118
123
  }
119
124
  getStubsClassName(ctx) {
120
125
  var _a;
@@ -1,7 +1,15 @@
1
1
  import { ts } from '../../../ast';
2
2
  import { defaultTypeScriptGeneratorConfig } from '../../../config';
3
- export const defaultTypeScriptEasyNetworkStubsGeneratorConfig = Object.assign(Object.assign({}, defaultTypeScriptGeneratorConfig), { fileNameCasing: { casing: 'kebab', suffix: '.stubs' }, defaultStatusCodeResponseTypes: {
3
+ export const defaultTypeScriptEasyNetworkStubsGeneratorConfig = {
4
+ ...defaultTypeScriptGeneratorConfig,
5
+ domainName: undefined,
6
+ defaultStatusCodeResponseTypes: {
4
7
  401: ts.refs.never(),
5
8
  403: ts.refs.never(),
6
9
  500: ts.refs.never(),
7
- }, stubsDirPath: 'stubs', stubsIndexFilePath: 'stubs.ts', utilsDirPath: 'utils' });
10
+ },
11
+ stubsDir: 'stubs',
12
+ stubFileNameCasing: { casing: 'kebab', suffix: '.stubs' },
13
+ stubsIndexFile: 'stubs.ts',
14
+ utilsDir: 'utils',
15
+ };
@@ -2,7 +2,7 @@ import { join, resolve } from 'path';
2
2
  import { ts } from '../../../ast';
3
3
  // See packages/typescript/assets/stubs/easy-network-stub for reference
4
4
  export function getReferenceFactories(options) {
5
- const utilsDirPath = resolve(options.outputDir, options.utilsDirPath);
5
+ const utilsDirPath = resolve(options.outputDir, options.utilsDir);
6
6
  const easyNetworkStubUtilsPath = join(utilsDirPath, 'easy-network-stub.utils.ts');
7
7
  return {
8
8
  // easy-network-stub.utils.ts