@aws/nx-plugin 0.28.3 → 0.28.4

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.
@@ -1002,9 +1002,7 @@ export class TestApi {
1002
1002
  const body =
1003
1003
  input === undefined
1004
1004
  ? undefined
1005
- : typeof input === 'object'
1006
- ? JSON.stringify(input === null ? null : input)
1007
- : String(input === null ? null : input);
1005
+ : JSON.stringify(input === null ? null : input);
1008
1006
 
1009
1007
  const response = await this.$fetch(
1010
1008
  this.$url('/single-nullable-array', pathParameters, queryParameters),
@@ -1547,12 +1545,7 @@ export class TestApi {
1547
1545
  if (!this.$config.options?.omitContentTypeHeader) {
1548
1546
  headerParameters['Content-Type'] = 'application/json';
1549
1547
  }
1550
- const body =
1551
- input === undefined
1552
- ? undefined
1553
- : typeof input === 'object'
1554
- ? JSON.stringify(input)
1555
- : String(input);
1548
+ const body = input === undefined ? undefined : JSON.stringify(input);
1556
1549
 
1557
1550
  const response = await this.$fetch(
1558
1551
  this.$url(
@@ -1584,12 +1577,7 @@ export class TestApi {
1584
1577
  if (!this.$config.options?.omitContentTypeHeader) {
1585
1578
  headerParameters['Content-Type'] = 'application/json';
1586
1579
  }
1587
- const body =
1588
- input === undefined
1589
- ? undefined
1590
- : typeof input === 'object'
1591
- ? JSON.stringify(input)
1592
- : String(input);
1580
+ const body = input === undefined ? undefined : JSON.stringify(input);
1593
1581
 
1594
1582
  const response = await this.$fetch(
1595
1583
  this.$url('/array-of-maps-of-numbers', pathParameters, queryParameters),
@@ -1060,12 +1060,7 @@ export class TestApi {
1060
1060
  if (!this.$config.options?.omitContentTypeHeader) {
1061
1061
  headerParameters['Content-Type'] = 'application/json';
1062
1062
  }
1063
- const body =
1064
- input === undefined
1065
- ? undefined
1066
- : typeof input === 'object'
1067
- ? JSON.stringify(input)
1068
- : String(input);
1063
+ const body = input === undefined ? undefined : JSON.stringify(input);
1069
1064
 
1070
1065
  const response = await this.$fetch(
1071
1066
  this.$url('/arrays', pathParameters, queryParameters),
@@ -1100,17 +1095,10 @@ export class TestApi {
1100
1095
  const body =
1101
1096
  input === undefined
1102
1097
  ? undefined
1103
- : typeof input === 'object'
1104
- ? JSON.stringify(
1105
- $IO.TestArraysWithOtherParametersRequestBodyParameters.toJson(
1106
- input,
1107
- ).body,
1108
- )
1109
- : String(
1110
- $IO.TestArraysWithOtherParametersRequestBodyParameters.toJson(
1111
- input,
1112
- ).body,
1113
- );
1098
+ : JSON.stringify(
1099
+ $IO.TestArraysWithOtherParametersRequestBodyParameters.toJson(input)
1100
+ .body,
1101
+ );
1114
1102
 
1115
1103
  const response = await this.$fetch(
1116
1104
  this.$url(
@@ -391,9 +391,25 @@ export class <%- className %> {
391
391
  <%_ } else if (op.parametersBody.isPrimitive || ["binary", "any", "unknown"].includes(op.parametersBody.type) || op.parametersBody.isEnum || op.parametersBody.export === 'enum') { _%>
392
392
  const body = <% if (!op.parametersBody.isRequired) { %>input === undefined ? undefined : <% } %>input<%- op.explicitRequestBodyParameter ? `.${op.explicitRequestBodyParameter.typescriptName}` : '' %><%- op.parametersBody.type === 'unknown' ? ' as any' : '' %>;
393
393
  <%_ } else if (op.explicitRequestBodyParameter) { _%>
394
- const body = <% if (!op.explicitRequestBodyParameter.isRequired) { %>input === undefined ? undefined : <% } %>(typeof input === 'object' ? JSON.stringify($IO.<%- op.operationIdPascalCase %>RequestBodyParameters.toJson(input).<%- op.explicitRequestBodyParameter.prop %>) : String($IO.<%- op.operationIdPascalCase %>RequestBodyParameters.toJson(input).<%- op.explicitRequestBodyParameter.prop %>));
394
+ const body = <% if (!op.explicitRequestBodyParameter.isRequired) { %>input === undefined ? undefined : <% } %>(
395
+ <%_ if (op.explicitRequestBodyParameter.export !== 'array') { _%>
396
+ typeof input === 'object' ?
397
+ <%_ } _%>
398
+ JSON.stringify($IO.<%- op.operationIdPascalCase %>RequestBodyParameters.toJson(input).<%- op.explicitRequestBodyParameter.prop %>)
399
+ <%_ if (op.explicitRequestBodyParameter.export !== 'array') { _%>
400
+ : String($IO.<%- op.operationIdPascalCase %>RequestBodyParameters.toJson(input).<%- op.explicitRequestBodyParameter.prop %>)
401
+ <%_ } _%>
402
+ );
395
403
  <%_ } else { _%>
396
- const body = <% if (!op.parametersBody.isRequired) { %>input === undefined ? undefined : <% } %>(typeof input === 'object' ? JSON.stringify(<%- renderToJsonValue(op.parametersBody, 'input') %>) : String(<%- renderToJsonValue(op.parametersBody, 'input') %>));
404
+ const body = <% if (!op.parametersBody.isRequired) { %>input === undefined ? undefined : <% } %>(
405
+ <%_ if (op.parametersBody.export !== 'array') { _%>
406
+ typeof input === 'object' ?
407
+ <%_ } _%>
408
+ JSON.stringify(<%- renderToJsonValue(op.parametersBody, 'input') %>)
409
+ <%_ if (op.parametersBody.export !== 'array') { _%>
410
+ : String(<%- renderToJsonValue(op.parametersBody, 'input') %>)
411
+ <%_ } _%>
412
+ );
397
413
  <%_ } _%>
398
414
  <%_ } else { %>
399
415
  const body = undefined;
@@ -33,7 +33,7 @@ import type {
33
33
  });
34
34
  } _%>
35
35
  <%_ const modelsByName = Object.fromEntries(models.map(m => [m.name, m])); _%>
36
- <%_ uniq(allOperations.flatMap((op) => op.result && modelsByName[op.result.type] ? [op.result.typescriptType] : [])).forEach((returnTypeModel) => { _%>
36
+ <%_ uniq(allOperations.flatMap((op) => op.result && modelsByName[op.result.type] ? [op.result.type] : [])).forEach((returnTypeModel) => { _%>
37
37
  <%- returnTypeModel %>,
38
38
  <%_ }); _%>
39
39
  } from './types.gen.js';
@@ -24,6 +24,7 @@ import {
24
24
  } from '@tanstack/react-query';
25
25
  import React from 'react';
26
26
  import { Mock } from 'vitest';
27
+ import { PET_STORE_SPEC } from '../ts-client/generator.petstore.spec';
27
28
 
28
29
  describe('openApiTsHooksGenerator', () => {
29
30
  let tree: Tree;
@@ -1784,4 +1785,19 @@ describe('openApiTsHooksGenerator', () => {
1784
1785
  }),
1785
1786
  );
1786
1787
  });
1788
+
1789
+ it('should generate valid code for the petstore example ', async () => {
1790
+ tree.write('openapi.json', JSON.stringify(PET_STORE_SPEC));
1791
+
1792
+ await openApiTsHooksGenerator(tree, {
1793
+ openApiSpecPath: 'openapi.json',
1794
+ outputPath: 'src/generated',
1795
+ });
1796
+
1797
+ validateTypeScript([
1798
+ 'src/generated/client.gen.ts',
1799
+ 'src/generated/types.gen.ts',
1800
+ 'src/generated/options-proxy.gen.ts',
1801
+ ]);
1802
+ });
1787
1803
  });