@goast/typescript 0.2.15 → 0.2.17

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.
@@ -1,7 +1,7 @@
1
1
  import { HttpErrorResponse, HttpEvent, HttpResponse } from '@angular/common/http';
2
2
  import { Observable, Subscription, filter, take, map, catchError, EMPTY } from 'rxjs';
3
3
 
4
- export type AbortablePromise<T> = {
4
+ export type AbortablePromise<T> = Omit<Promise<T>, 'then' | 'catch' | 'finally'> & {
5
5
  abort(): void;
6
6
  then<TResult1 = T, TResult2 = never>(
7
7
  onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
@@ -16,6 +16,8 @@ class TsTypeAlias extends node_1.TsNode {
16
16
  this.export = (_d = options.export) !== null && _d !== void 0 ? _d : false;
17
17
  }
18
18
  onWrite(builder) {
19
+ if (this.doc)
20
+ (0, write_ts_nodes_1.writeTsNode)(builder, this.doc);
19
21
  if (this.export)
20
22
  builder.append('export ');
21
23
  builder.append('type ');
@@ -51,6 +51,10 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
51
51
  getEnum(ctx) {
52
52
  var _a, _b;
53
53
  return ast_1.ts.enum(this.getDeclarationTypeName(ctx, ctx.schema), {
54
+ doc: ast_1.ts.doc({
55
+ description: ctx.schema.description,
56
+ tags: [ctx.schema.deprecated ? ast_1.ts.docTag('deprecated') : null],
57
+ }),
54
58
  export: true,
55
59
  members: ((_b = (_a = ctx.schema.enum) === null || _a === void 0 ? void 0 : _a.map((x) => String(x))) !== null && _b !== void 0 ? _b : []).map((x) => ast_1.ts.enumValue((0, core_1.toCasing)(x, ctx.config.enumValueNameCasing), { value: ast_1.ts.string(x) })),
56
60
  });
@@ -58,7 +62,10 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
58
62
  getInterface(ctx, schema) {
59
63
  return ast_1.ts.interface(this.getDeclarationTypeName(ctx, ctx.schema), {
60
64
  export: true,
61
- doc: ast_1.ts.doc({ description: schema.description }),
65
+ doc: ast_1.ts.doc({
66
+ description: schema.description,
67
+ tags: [ctx.schema.deprecated ? ast_1.ts.docTag('deprecated') : null],
68
+ }),
62
69
  members: [...this.getProperties(ctx, schema), this.getIndexer(ctx, schema)],
63
70
  });
64
71
  }
@@ -67,7 +74,10 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
67
74
  const hasDiscriminator = schema.discriminator && Object.keys(schema.discriminator.mapping).length > 0;
68
75
  const result = ast_1.ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (hasDiscriminator ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, { skipSchemas: true }))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
69
76
  export: true,
70
- doc: ast_1.ts.doc({ description: schema.description }),
77
+ doc: ast_1.ts.doc({
78
+ description: schema.description,
79
+ tags: [ctx.schema.deprecated ? ast_1.ts.docTag('deprecated') : null],
80
+ }),
71
81
  });
72
82
  if (hasDiscriminator) {
73
83
  const propertyValue = this.getDiscriminatorTypeName(ctx, ctx.schema);
@@ -108,7 +118,10 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
108
118
  getProperties(ctx, schema) {
109
119
  return Array.from(schema.properties.values()).map((property) => {
110
120
  return ast_1.ts.property(property.name, {
111
- doc: ast_1.ts.doc({ description: property.schema.description }),
121
+ doc: ast_1.ts.doc({
122
+ description: property.schema.description,
123
+ tags: [property.schema.deprecated ? ast_1.ts.docTag('deprecated') : null],
124
+ }),
112
125
  readonly: ctx.config.immutableTypes,
113
126
  optional: !schema.required.has(property.name),
114
127
  type: ast_1.ts.unionType([this.getType(ctx, property.schema), property.schema.nullable ? 'null' : null]),
@@ -78,6 +78,10 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
78
78
  ]),
79
79
  ast_1.ts.objectType({ members: [ast_1.ts.property('status', { type: 'TStatus' })] }),
80
80
  ]), {
81
+ doc: ast_1.ts.doc({
82
+ description: `Response model for operation ${this.getEndpointMethodName(ctx, endpoint)}`,
83
+ tags: [endpoint.deprecated ? ast_1.ts.docTag('deprecated') : null],
84
+ }),
81
85
  export: true,
82
86
  generics: [
83
87
  ast_1.ts.genericParameter('TStatus', {
@@ -132,7 +136,10 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
132
136
  for (const parameter of endpoint.parameters) {
133
137
  const schema = parameter.schema;
134
138
  type.members.push(ast_1.ts.property((0, core_1.toCasing)(parameter.name, ctx.config.propertyNameCasing), {
135
- doc: ast_1.ts.doc({ description: parameter.description }),
139
+ doc: ast_1.ts.doc({
140
+ description: parameter.description,
141
+ tags: [parameter.deprecated ? ast_1.ts.docTag('deprecated') : null],
142
+ }),
136
143
  type: schema ? (b) => b.appendModelUsage(ctx.input.models[schema.id]) : this.getAnyType(ctx),
137
144
  optional: !parameter.required,
138
145
  }));
@@ -152,7 +159,14 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
152
159
  }
153
160
  getClass(ctx) {
154
161
  return ast_1.ts.class(this.getServiceClassName(ctx), {
155
- doc: ast_1.ts.doc({ description: ctx.service.description }),
162
+ doc: ast_1.ts.doc({
163
+ description: ctx.service.description,
164
+ tags: [
165
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
166
+ ? null
167
+ : ast_1.ts.docTag('deprecated'),
168
+ ],
169
+ }),
156
170
  decorators: [
157
171
  ast_1.ts.decorator(ast_1.ts.refs.angular.injectable(), ctx.config.provideKind === 'root' ? [ast_1.ts.toNode({ providedIn: 'root' })] : []),
158
172
  ],
@@ -188,6 +202,10 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
188
202
  : null,
189
203
  ast_1.ts.parameter('context', { optional: true, type: ast_1.ts.refs.angular.httpContext() }),
190
204
  ],
205
+ doc: ast_1.ts.doc({
206
+ description: endpoint.description,
207
+ tags: [endpoint.deprecated ? ast_1.ts.docTag('deprecated') : null],
208
+ }),
191
209
  returnType,
192
210
  body: (0, core_1.appendValueGroup)([
193
211
  (0, core_1.builderTemplate) `const rb = new ${ctx.refs.requestBuilder()}(this.rootUrl, ${this.getServiceClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)}, '${endpoint.method}');`,
@@ -39,7 +39,14 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
39
39
  }
40
40
  getInterface(ctx) {
41
41
  return ast_1.ts.interface(this.getInterfaceName(ctx), {
42
- doc: ast_1.ts.doc({ description: ctx.service.description }),
42
+ doc: ast_1.ts.doc({
43
+ description: ctx.service.description,
44
+ tags: [
45
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
46
+ ? null
47
+ : ast_1.ts.docTag('deprecated'),
48
+ ],
49
+ }),
43
50
  export: true,
44
51
  members: ctx.service.endpoints.map((endpoint) => this.getInterfaceEndpointMethod(ctx, endpoint)),
45
52
  });
@@ -50,13 +57,14 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
50
57
  const bodySchema = (_b = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) === null || _b === void 0 ? void 0 : _b.schema;
51
58
  const responseSchema = this.getResponseSchema(ctx, endpoint);
52
59
  return ast_1.ts.method((0, core_1.toCasing)(endpoint.name, ctx.config.methodCasing), {
53
- doc: ast_1.ts.doc({ description: endpoint.description }),
60
+ doc: ast_1.ts.doc({ description: endpoint.description, tags: [endpoint.deprecated ? ast_1.ts.docTag('deprecated') : null] }),
54
61
  parameters: [
55
62
  params.length > 0
56
63
  ? ast_1.ts.parameter('params', {
57
64
  description: 'Parameters for the endpoint.',
58
65
  type: ast_1.ts.objectType({
59
66
  members: params.map((x) => ast_1.ts.property((0, core_1.toCasing)(x.name, ctx.config.propertyNameCasing), {
67
+ doc: ast_1.ts.doc({ tags: [x.deprecated ? ast_1.ts.docTag('deprecated') : null] }),
60
68
  type: this.getSchemaType(ctx, x.schema),
61
69
  optional: !x.required,
62
70
  })),
@@ -92,7 +100,14 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
92
100
  }
93
101
  getClass(ctx) {
94
102
  return ast_1.ts.class(this.getClassName(ctx), {
95
- doc: ast_1.ts.doc({ description: ctx.service.description }),
103
+ doc: ast_1.ts.doc({
104
+ description: ctx.service.description,
105
+ tags: [
106
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
107
+ ? null
108
+ : ast_1.ts.docTag('deprecated'),
109
+ ],
110
+ }),
96
111
  export: true,
97
112
  implements: this.shouldGenerateInterface(ctx)
98
113
  ? [ast_1.ts.reference(this.getInterfaceName(ctx), this.getInterfaceFilePath(ctx))]
@@ -13,6 +13,8 @@ export class TsTypeAlias extends TsNode {
13
13
  this.export = (_d = options.export) !== null && _d !== void 0 ? _d : false;
14
14
  }
15
15
  onWrite(builder) {
16
+ if (this.doc)
17
+ writeTsNode(builder, this.doc);
16
18
  if (this.export)
17
19
  builder.append('export ');
18
20
  builder.append('type ');
@@ -48,6 +48,10 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
48
48
  getEnum(ctx) {
49
49
  var _a, _b;
50
50
  return ts.enum(this.getDeclarationTypeName(ctx, ctx.schema), {
51
+ doc: ts.doc({
52
+ description: ctx.schema.description,
53
+ tags: [ctx.schema.deprecated ? ts.docTag('deprecated') : null],
54
+ }),
51
55
  export: true,
52
56
  members: ((_b = (_a = ctx.schema.enum) === null || _a === void 0 ? void 0 : _a.map((x) => String(x))) !== null && _b !== void 0 ? _b : []).map((x) => ts.enumValue(toCasing(x, ctx.config.enumValueNameCasing), { value: ts.string(x) })),
53
57
  });
@@ -55,7 +59,10 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
55
59
  getInterface(ctx, schema) {
56
60
  return ts.interface(this.getDeclarationTypeName(ctx, ctx.schema), {
57
61
  export: true,
58
- doc: ts.doc({ description: schema.description }),
62
+ doc: ts.doc({
63
+ description: schema.description,
64
+ tags: [ctx.schema.deprecated ? ts.docTag('deprecated') : null],
65
+ }),
59
66
  members: [...this.getProperties(ctx, schema), this.getIndexer(ctx, schema)],
60
67
  });
61
68
  }
@@ -64,7 +71,10 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
64
71
  const hasDiscriminator = schema.discriminator && Object.keys(schema.discriminator.mapping).length > 0;
65
72
  const result = ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (hasDiscriminator ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, { skipSchemas: true }))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
66
73
  export: true,
67
- doc: ts.doc({ description: schema.description }),
74
+ doc: ts.doc({
75
+ description: schema.description,
76
+ tags: [ctx.schema.deprecated ? ts.docTag('deprecated') : null],
77
+ }),
68
78
  });
69
79
  if (hasDiscriminator) {
70
80
  const propertyValue = this.getDiscriminatorTypeName(ctx, ctx.schema);
@@ -105,7 +115,10 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
105
115
  getProperties(ctx, schema) {
106
116
  return Array.from(schema.properties.values()).map((property) => {
107
117
  return ts.property(property.name, {
108
- doc: ts.doc({ description: property.schema.description }),
118
+ doc: ts.doc({
119
+ description: property.schema.description,
120
+ tags: [property.schema.deprecated ? ts.docTag('deprecated') : null],
121
+ }),
109
122
  readonly: ctx.config.immutableTypes,
110
123
  optional: !schema.required.has(property.name),
111
124
  type: ts.unionType([this.getType(ctx, property.schema), property.schema.nullable ? 'null' : null]),
@@ -75,6 +75,10 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
75
75
  ]),
76
76
  ts.objectType({ members: [ts.property('status', { type: 'TStatus' })] }),
77
77
  ]), {
78
+ doc: ts.doc({
79
+ description: `Response model for operation ${this.getEndpointMethodName(ctx, endpoint)}`,
80
+ tags: [endpoint.deprecated ? ts.docTag('deprecated') : null],
81
+ }),
78
82
  export: true,
79
83
  generics: [
80
84
  ts.genericParameter('TStatus', {
@@ -129,7 +133,10 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
129
133
  for (const parameter of endpoint.parameters) {
130
134
  const schema = parameter.schema;
131
135
  type.members.push(ts.property(toCasing(parameter.name, ctx.config.propertyNameCasing), {
132
- doc: ts.doc({ description: parameter.description }),
136
+ doc: ts.doc({
137
+ description: parameter.description,
138
+ tags: [parameter.deprecated ? ts.docTag('deprecated') : null],
139
+ }),
133
140
  type: schema ? (b) => b.appendModelUsage(ctx.input.models[schema.id]) : this.getAnyType(ctx),
134
141
  optional: !parameter.required,
135
142
  }));
@@ -149,7 +156,14 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
149
156
  }
150
157
  getClass(ctx) {
151
158
  return ts.class(this.getServiceClassName(ctx), {
152
- doc: ts.doc({ description: ctx.service.description }),
159
+ doc: ts.doc({
160
+ description: ctx.service.description,
161
+ tags: [
162
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
163
+ ? null
164
+ : ts.docTag('deprecated'),
165
+ ],
166
+ }),
153
167
  decorators: [
154
168
  ts.decorator(ts.refs.angular.injectable(), ctx.config.provideKind === 'root' ? [ts.toNode({ providedIn: 'root' })] : []),
155
169
  ],
@@ -185,6 +199,10 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
185
199
  : null,
186
200
  ts.parameter('context', { optional: true, type: ts.refs.angular.httpContext() }),
187
201
  ],
202
+ doc: ts.doc({
203
+ description: endpoint.description,
204
+ tags: [endpoint.deprecated ? ts.docTag('deprecated') : null],
205
+ }),
188
206
  returnType,
189
207
  body: appendValueGroup([
190
208
  s `const rb = new ${ctx.refs.requestBuilder()}(this.rootUrl, ${this.getServiceClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)}, '${endpoint.method}');`,
@@ -36,7 +36,14 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
36
36
  }
37
37
  getInterface(ctx) {
38
38
  return ts.interface(this.getInterfaceName(ctx), {
39
- doc: ts.doc({ description: ctx.service.description }),
39
+ doc: ts.doc({
40
+ description: ctx.service.description,
41
+ tags: [
42
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
43
+ ? null
44
+ : ts.docTag('deprecated'),
45
+ ],
46
+ }),
40
47
  export: true,
41
48
  members: ctx.service.endpoints.map((endpoint) => this.getInterfaceEndpointMethod(ctx, endpoint)),
42
49
  });
@@ -47,13 +54,14 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
47
54
  const bodySchema = (_b = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) === null || _b === void 0 ? void 0 : _b.schema;
48
55
  const responseSchema = this.getResponseSchema(ctx, endpoint);
49
56
  return ts.method(toCasing(endpoint.name, ctx.config.methodCasing), {
50
- doc: ts.doc({ description: endpoint.description }),
57
+ doc: ts.doc({ description: endpoint.description, tags: [endpoint.deprecated ? ts.docTag('deprecated') : null] }),
51
58
  parameters: [
52
59
  params.length > 0
53
60
  ? ts.parameter('params', {
54
61
  description: 'Parameters for the endpoint.',
55
62
  type: ts.objectType({
56
63
  members: params.map((x) => ts.property(toCasing(x.name, ctx.config.propertyNameCasing), {
64
+ doc: ts.doc({ tags: [x.deprecated ? ts.docTag('deprecated') : null] }),
57
65
  type: this.getSchemaType(ctx, x.schema),
58
66
  optional: !x.required,
59
67
  })),
@@ -89,7 +97,14 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
89
97
  }
90
98
  getClass(ctx) {
91
99
  return ts.class(this.getClassName(ctx), {
92
- doc: ts.doc({ description: ctx.service.description }),
100
+ doc: ts.doc({
101
+ description: ctx.service.description,
102
+ tags: [
103
+ ctx.service.endpoints.length === 0 || ctx.service.endpoints.some((x) => !x.deprecated)
104
+ ? null
105
+ : ts.docTag('deprecated'),
106
+ ],
107
+ }),
93
108
  export: true,
94
109
  implements: this.shouldGenerateInterface(ctx)
95
110
  ? [ts.reference(this.getInterfaceName(ctx), this.getInterfaceFilePath(ctx))]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/typescript",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",