@aws/nx-plugin 0.28.2 → 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
  });
@@ -18,6 +18,7 @@ from collections.abc import Callable
18
18
  from aws_lambda_powertools import Logger, Metrics, Tracer
19
19
  from aws_lambda_powertools.metrics import MetricUnit
20
20
  from fastapi import FastAPI, Request, Response
21
+ from fastapi.middleware.cors import CORSMiddleware
21
22
  from fastapi.openapi.utils import get_openapi
22
23
  from fastapi.responses import JSONResponse
23
24
  from fastapi.routing import APIRoute
@@ -51,6 +52,12 @@ lambda_handler = logger.inject_lambda_context(lambda_handler, clear_state=True)
51
52
  # Add metrics last to properly flush metrics.
52
53
  lambda_handler = metrics.log_metrics(lambda_handler, capture_cold_start_metric=True)
53
54
 
55
+ # Add cors middleware
56
+ app.add_middleware(CORSMiddleware,
57
+ allow_origins=['*'],
58
+ allow_methods=['*'],
59
+ allow_headers=['*'])
60
+
54
61
  # Add exception middleware(s)
55
62
  app.add_middleware(ExceptionMiddleware, handlers=app.exception_handlers)
56
63
 
@@ -5,9 +5,7 @@ from collections.abc import Callable
5
5
  from aws_lambda_powertools import Logger, Metrics, Tracer
6
6
  from aws_lambda_powertools.metrics import MetricUnit
7
7
  from fastapi import FastAPI, Request, Response
8
- <%_ if (computeType === 'ServerlessApiGatewayRestApi') { _%>
9
8
  from fastapi.middleware.cors import CORSMiddleware
10
- <%_ } _%>
11
9
  from fastapi.openapi.utils import get_openapi
12
10
  from fastapi.responses import JSONResponse
13
11
  from fastapi.routing import APIRoute
@@ -41,11 +39,12 @@ lambda_handler = logger.inject_lambda_context(lambda_handler, clear_state=True)
41
39
  # Add metrics last to properly flush metrics.
42
40
  lambda_handler = metrics.log_metrics(lambda_handler, capture_cold_start_metric=True)
43
41
 
44
- <%_ if (computeType === 'ServerlessApiGatewayRestApi') { _%>
45
42
  # Add cors middleware
46
- app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=['*'])
43
+ app.add_middleware(CORSMiddleware,
44
+ allow_origins=['*'],
45
+ allow_methods=['*'],
46
+ allow_headers=['*'])
47
47
 
48
- <%_ } _%>
49
48
  # Add exception middleware(s)
50
49
  app.add_middleware(ExceptionMiddleware, handlers=app.exception_handlers)
51
50
 
@@ -391,9 +391,11 @@ export interface TestApiProps<
391
391
  */
392
392
  integrations: TIntegrations;
393
393
  /**
394
- * User pool for Cognito authentication
394
+ * Identity details for Cognito Authentication
395
395
  */
396
- userPool: IUserPool;
396
+ identity: {
397
+ userPool: IUserPool;
398
+ };
397
399
  }
398
400
 
399
401
  /**
@@ -448,7 +450,7 @@ export class TestApi<
448
450
  defaultMethodOptions: {
449
451
  authorizationType: AuthorizationType.COGNITO,
450
452
  authorizer: new CognitoUserPoolsAuthorizer(scope, 'TestApiAuthorizer', {
451
- cognitoUserPools: [props.userPool],
453
+ cognitoUserPools: [props.identity.userPool],
452
454
  }),
453
455
  },
454
456
  defaultCorsPreflightOptions: {
@@ -67,9 +67,11 @@ export interface <%= apiNameClassName %>Props<
67
67
  integrations: TIntegrations;
68
68
  <%_ if (auth === 'Cognito') { _%>
69
69
  /**
70
- * User pool for Cognito authentication
70
+ * Identity details for Cognito Authentication
71
71
  */
72
- userPool: IUserPool;
72
+ identity: {
73
+ userPool: IUserPool;
74
+ };
73
75
  <%_ } _%>
74
76
  }
75
77
 
@@ -145,7 +147,7 @@ export class <%= apiNameClassName %><
145
147
  <%_ } else if (auth === 'Cognito') { _%>
146
148
  authorizationType: AuthorizationType.COGNITO,
147
149
  authorizer: new CognitoUserPoolsAuthorizer(scope, '<%= apiNameClassName %>Authorizer', {
148
- cognitoUserPools: [props.userPool],
150
+ cognitoUserPools: [props.identity.userPool],
149
151
  }),
150
152
  <%_ } else if (auth === 'None') { _%>
151
153
  authorizationType: AuthorizationType.NONE,
@@ -7,6 +7,10 @@ import { Tree } from '@nx/devkit';
7
7
  * Returns all files from the tree root that are not gitignored (both tracked and untracked)
8
8
  */
9
9
  export declare const getGitIncludedFiles: (tree: Tree) => string[];
10
+ /**
11
+ * Return whether or not a tree is within a git repo
12
+ */
13
+ export declare const isWithinGitRepo: (tree: Tree) => boolean;
10
14
  /**
11
15
  * Update a .gitignore file. Will create a new .gitignore file if it does not exist
12
16
  */
package/src/utils/git.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateGitIgnore = exports.getGitIncludedFiles = void 0;
3
+ exports.updateGitIgnore = exports.isWithinGitRepo = exports.getGitIncludedFiles = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /**
6
6
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -31,6 +31,24 @@ const getGitIncludedFiles = (tree) => {
31
31
  ].filter((f) => tree.exists(f));
32
32
  };
33
33
  exports.getGitIncludedFiles = getGitIncludedFiles;
34
+ /**
35
+ * Return whether or not a tree is within a git repo
36
+ */
37
+ const isWithinGitRepo = (tree) => {
38
+ if (tree.exists('.git')) {
39
+ return true;
40
+ }
41
+ try {
42
+ return (0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
43
+ encoding: 'utf-8',
44
+ cwd: tree.root,
45
+ }).startsWith('true');
46
+ }
47
+ catch (_a) {
48
+ return false;
49
+ }
50
+ };
51
+ exports.isWithinGitRepo = isWithinGitRepo;
34
52
  /**
35
53
  * Update a .gitignore file. Will create a new .gitignore file if it does not exist
36
54
  */
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../../../../../packages/nx-plugin/src/utils/git.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAAqD;AACrD,iDAAyC;AACzC,0EAAmC;AAEnC;;GAEG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