@vc-shell/api-client-generator 1.2.1 → 1.2.3-beta.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.
@@ -1,6 +1,15 @@
1
1
  /* eslint-disable */
2
+
2
3
  export class AuthApiBase {
3
4
  authToken = "";
5
+
6
+ /**
7
+ * JSON parse reviver for converting date strings to Date objects.
8
+ * Subclasses use this when parsing API responses.
9
+ * The dateReviver function is defined in File.Header.liquid template.
10
+ */
11
+ protected jsonParseReviver = dateReviver;
12
+
4
13
  protected constructor() {}
5
14
 
6
15
  // Enforce always return empty string as baseUrl
@@ -0,0 +1,96 @@
1
+ {% if HasOperations -%}
2
+ {% if GenerateClientInterfaces -%}
3
+ {% if ExportTypes %}export {% endif %}interface I{{ Class }} {
4
+ {% for operation in Operations %}
5
+
6
+ {% template Client.Method.Documentation %}
7
+ {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {%endif%}{% endfor %}{% if UseAbortSignal %}{% if operation.Parameters.size > 0 %}, {% endif %}signal?: AbortSignal{% endif %}): Promise<{{ operation.ResultType }}>;
8
+ {%- endfor %}}
9
+ {%- endif -%}
10
+
11
+ {% if UseAureliaHttpInjection -%}
12
+ @inject({% if HasConfigurationClass %}{{ ConfigurationClass }}, {% endif %}String, HttpClient)
13
+ {%- endif -%}
14
+ {% if ExportTypes %}export {% endif %}class {{ Class }} {% if HasBaseClass %}extends {{ BaseClass }} {% endif %}{% if GenerateClientInterfaces %}implements I{{ Class }} {% endif %}{
15
+ private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
16
+ private baseUrl: string;
17
+ {%- unless HasBaseClass -%}
18
+ protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
19
+ {%- endunless -%}
20
+ {{ '' }}
21
+ {%- if HasExtendedConstructor == false -%}
22
+ constructor({% if HasConfigurationClass %}configuration: {{ ConfigurationClass }}, {% endif %}baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
23
+ {%- if HasBaseClass -%}
24
+ super({% if HasConfigurationClass %}configuration{% endif %});
25
+ {%- endif -%}
26
+ this.http = http ? http : window as any;
27
+ {%- if UseGetBaseUrlMethod -%}
28
+ this.baseUrl = this.getBaseUrl("{{ BaseUrl }}", baseUrl);
29
+ {%- else -%}
30
+ this.baseUrl = baseUrl ?? "{{ BaseUrl }}";
31
+ {%- endif -%}
32
+ }
33
+ {%- endif -%}
34
+ {%- if HasExtensionCode -%}
35
+
36
+ {{ ExtensionCode }}
37
+ {%- endif -%}
38
+ {% for operation in Operations %}
39
+
40
+ {% template Client.Method.Documentation %}
41
+ {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {% endif %}{% endfor %}{% if UseAbortSignal %}{% if operation.Parameters.size > 0 %}, {% endif %}signal?: AbortSignal{% endif %}): Promise<{{ operation.ResultType }}> {
42
+ {% template Client.RequestUrl %}
43
+
44
+ {%- if operation.HasBody -%}
45
+ {% template Client.RequestBody %}
46
+
47
+ {%- endif -%}
48
+ let options_: RequestInit = {
49
+ {%- if operation.HasBody -%}
50
+ body: content_,
51
+ {%- endif -%}
52
+ method: "{{ operation.HttpMethodUpper | upcase }}",
53
+ {%- if UseAbortSignal -%}
54
+ signal,
55
+ {%- endif -%}
56
+ {%- if RequestCredentialsType -%}
57
+ credentials: '{{ RequestCredentialsType }}',
58
+ {%- endif -%}
59
+ {%- if RequestModeType -%}
60
+ mode: '{{ RequestModeType }}',
61
+ {%- endif -%}
62
+ headers: {
63
+ {%- for parameter in operation.HeaderParameters -%}
64
+ "{{ parameter.Name }}": {{ parameter.VariableName }} !== undefined && {{ parameter.VariableName }} !== null ? "" + {{ parameter.VariableName }} : "",
65
+ {%- endfor -%}
66
+ {%- if operation.HasContent or operation.ConsumesOnlyFormUrlEncoded -%}
67
+ "Content-Type": "{{ operation.Consumes }}",
68
+ {%- endif -%}
69
+ {%- if operation.HasResultType and operation.HasAcceptHeaderParameterParameter == false -%}
70
+ "Accept": "{{ operation.Produces }}"
71
+ {%- endif -%}
72
+ }
73
+ };
74
+
75
+ {%- if UseTransformOptionsMethod -%}
76
+ return this.transformOptions(options_).then(transformedOptions_ => {
77
+ return this.http.fetch(url_, transformedOptions_);
78
+ }).then((_response: Response) => {
79
+ {%- else -%}
80
+ return this.http.fetch(url_, options_).then((_response: Response) => {
81
+ {%- endif -%}
82
+ {%- if UseTransformResultMethod -%}
83
+ return this.transformResult(url_, _response, (_response: Response) => this.process{{ operation.ActualOperationNameUpper }}(_response));
84
+ {%- else -%}
85
+ return this.process{{ operation.ActualOperationNameUpper }}(_response);
86
+ {%- endif -%}
87
+ });
88
+ }
89
+
90
+ protected process{{ operation.ActualOperationNameUpper }}(response: Response): Promise<{{ operation.ResultType }}> {
91
+ const status = response.status;
92
+ {% template Client.ProcessResponse %}
93
+ }
94
+ {% endfor -%}
95
+ }
96
+ {%- endif -%}
@@ -2,3 +2,23 @@
2
2
  /* eslint-disable */
3
3
  // ReSharper disable InconsistentNaming
4
4
  // @ts-nocheck
5
+
6
+ // ISO 8601 date string pattern for JSON reviver
7
+ const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$/;
8
+
9
+ /**
10
+ * JSON parse reviver that converts ISO date strings to Date objects.
11
+ * This is needed because when using interface-based types (after NSwag migration),
12
+ * dates are not automatically converted from strings to Date objects.
13
+ */
14
+ function dateReviver(key: string, value: unknown): unknown {
15
+ if (typeof value === "string" && ISO_DATE_PATTERN.test(value)) {
16
+ const date = new Date(value);
17
+ // Only return Date if it's valid
18
+ if (!isNaN(date.getTime())) {
19
+ return date;
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vc-shell/api-client-generator",
3
3
  "description": "Tool for API clients generation",
4
- "version": "1.2.1",
4
+ "version": "1.2.3-beta.0",
5
5
  "type": "module",
6
6
  "bin": "./dist/api-client-generator.js",
7
7
  "files": [
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/cross-spawn": "^6.0.6",
16
- "@vc-shell/ts-config": "1.2.1",
16
+ "@vc-shell/ts-config": "1.2.3-beta.0",
17
17
  "typescript": "^5.8.3"
18
18
  },
19
19
  "dependencies": {
@@ -28,5 +28,5 @@
28
28
  "access": "public",
29
29
  "registry": "https://registry.npmjs.org/"
30
30
  },
31
- "gitHead": "75afdc6afb8a3563385e526f9384a34557fe3561"
31
+ "gitHead": "1394fe061df6f536cd2f0dac0e2a6082eb0c2b64"
32
32
  }
@@ -1,6 +1,15 @@
1
1
  /* eslint-disable */
2
+
2
3
  export class AuthApiBase {
3
4
  authToken = "";
5
+
6
+ /**
7
+ * JSON parse reviver for converting date strings to Date objects.
8
+ * Subclasses use this when parsing API responses.
9
+ * The dateReviver function is defined in File.Header.liquid template.
10
+ */
11
+ protected jsonParseReviver = dateReviver;
12
+
4
13
  protected constructor() {}
5
14
 
6
15
  // Enforce always return empty string as baseUrl
@@ -0,0 +1,96 @@
1
+ {% if HasOperations -%}
2
+ {% if GenerateClientInterfaces -%}
3
+ {% if ExportTypes %}export {% endif %}interface I{{ Class }} {
4
+ {% for operation in Operations %}
5
+
6
+ {% template Client.Method.Documentation %}
7
+ {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {%endif%}{% endfor %}{% if UseAbortSignal %}{% if operation.Parameters.size > 0 %}, {% endif %}signal?: AbortSignal{% endif %}): Promise<{{ operation.ResultType }}>;
8
+ {%- endfor %}}
9
+ {%- endif -%}
10
+
11
+ {% if UseAureliaHttpInjection -%}
12
+ @inject({% if HasConfigurationClass %}{{ ConfigurationClass }}, {% endif %}String, HttpClient)
13
+ {%- endif -%}
14
+ {% if ExportTypes %}export {% endif %}class {{ Class }} {% if HasBaseClass %}extends {{ BaseClass }} {% endif %}{% if GenerateClientInterfaces %}implements I{{ Class }} {% endif %}{
15
+ private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
16
+ private baseUrl: string;
17
+ {%- unless HasBaseClass -%}
18
+ protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
19
+ {%- endunless -%}
20
+ {{ '' }}
21
+ {%- if HasExtendedConstructor == false -%}
22
+ constructor({% if HasConfigurationClass %}configuration: {{ ConfigurationClass }}, {% endif %}baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
23
+ {%- if HasBaseClass -%}
24
+ super({% if HasConfigurationClass %}configuration{% endif %});
25
+ {%- endif -%}
26
+ this.http = http ? http : window as any;
27
+ {%- if UseGetBaseUrlMethod -%}
28
+ this.baseUrl = this.getBaseUrl("{{ BaseUrl }}", baseUrl);
29
+ {%- else -%}
30
+ this.baseUrl = baseUrl ?? "{{ BaseUrl }}";
31
+ {%- endif -%}
32
+ }
33
+ {%- endif -%}
34
+ {%- if HasExtensionCode -%}
35
+
36
+ {{ ExtensionCode }}
37
+ {%- endif -%}
38
+ {% for operation in Operations %}
39
+
40
+ {% template Client.Method.Documentation %}
41
+ {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {% endif %}{% endfor %}{% if UseAbortSignal %}{% if operation.Parameters.size > 0 %}, {% endif %}signal?: AbortSignal{% endif %}): Promise<{{ operation.ResultType }}> {
42
+ {% template Client.RequestUrl %}
43
+
44
+ {%- if operation.HasBody -%}
45
+ {% template Client.RequestBody %}
46
+
47
+ {%- endif -%}
48
+ let options_: RequestInit = {
49
+ {%- if operation.HasBody -%}
50
+ body: content_,
51
+ {%- endif -%}
52
+ method: "{{ operation.HttpMethodUpper | upcase }}",
53
+ {%- if UseAbortSignal -%}
54
+ signal,
55
+ {%- endif -%}
56
+ {%- if RequestCredentialsType -%}
57
+ credentials: '{{ RequestCredentialsType }}',
58
+ {%- endif -%}
59
+ {%- if RequestModeType -%}
60
+ mode: '{{ RequestModeType }}',
61
+ {%- endif -%}
62
+ headers: {
63
+ {%- for parameter in operation.HeaderParameters -%}
64
+ "{{ parameter.Name }}": {{ parameter.VariableName }} !== undefined && {{ parameter.VariableName }} !== null ? "" + {{ parameter.VariableName }} : "",
65
+ {%- endfor -%}
66
+ {%- if operation.HasContent or operation.ConsumesOnlyFormUrlEncoded -%}
67
+ "Content-Type": "{{ operation.Consumes }}",
68
+ {%- endif -%}
69
+ {%- if operation.HasResultType and operation.HasAcceptHeaderParameterParameter == false -%}
70
+ "Accept": "{{ operation.Produces }}"
71
+ {%- endif -%}
72
+ }
73
+ };
74
+
75
+ {%- if UseTransformOptionsMethod -%}
76
+ return this.transformOptions(options_).then(transformedOptions_ => {
77
+ return this.http.fetch(url_, transformedOptions_);
78
+ }).then((_response: Response) => {
79
+ {%- else -%}
80
+ return this.http.fetch(url_, options_).then((_response: Response) => {
81
+ {%- endif -%}
82
+ {%- if UseTransformResultMethod -%}
83
+ return this.transformResult(url_, _response, (_response: Response) => this.process{{ operation.ActualOperationNameUpper }}(_response));
84
+ {%- else -%}
85
+ return this.process{{ operation.ActualOperationNameUpper }}(_response);
86
+ {%- endif -%}
87
+ });
88
+ }
89
+
90
+ protected process{{ operation.ActualOperationNameUpper }}(response: Response): Promise<{{ operation.ResultType }}> {
91
+ const status = response.status;
92
+ {% template Client.ProcessResponse %}
93
+ }
94
+ {% endfor -%}
95
+ }
96
+ {%- endif -%}
@@ -2,3 +2,23 @@
2
2
  /* eslint-disable */
3
3
  // ReSharper disable InconsistentNaming
4
4
  // @ts-nocheck
5
+
6
+ // ISO 8601 date string pattern for JSON reviver
7
+ const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$/;
8
+
9
+ /**
10
+ * JSON parse reviver that converts ISO date strings to Date objects.
11
+ * This is needed because when using interface-based types (after NSwag migration),
12
+ * dates are not automatically converted from strings to Date objects.
13
+ */
14
+ function dateReviver(key: string, value: unknown): unknown {
15
+ if (typeof value === "string" && ISO_DATE_PATTERN.test(value)) {
16
+ const date = new Date(value);
17
+ // Only return Date if it's valid
18
+ if (!isNaN(date.getTime())) {
19
+ return date;
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+