@aws/nx-plugin 0.12.0 → 0.13.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "license": "Apache-2.0",
@@ -11,6 +11,7 @@ from collections.abc import Callable
11
11
  from aws_lambda_powertools import Logger, Metrics, Tracer
12
12
  from aws_lambda_powertools.metrics import MetricUnit
13
13
  from fastapi import FastAPI, Request, Response
14
+ from fastapi.openapi.utils import get_openapi
14
15
  from fastapi.responses import JSONResponse
15
16
  from fastapi.routing import APIRoute
16
17
  from mangum import Mangum
@@ -53,7 +54,7 @@ async def metrics_handler(request: Request, call_next):
53
54
  metrics.add_metric(name="RequestCount", unit=MetricUnit.Count, value=1)
54
55
 
55
56
  response = await call_next(request)
56
-
57
+
57
58
  if response.status_code == 200:
58
59
  metrics.add_metric(name="Success", unit=MetricUnit.Count, value=1)
59
60
 
@@ -98,7 +99,26 @@ class LoggerRouteHandler(APIRoute):
98
99
 
99
100
  return route_handler
100
101
 
101
- app.router.route_class = LoggerRouteHandler",
102
+ app.router.route_class = LoggerRouteHandler
103
+
104
+ def custom_openapi():
105
+ if app.openapi_schema:
106
+ return app.openapi_schema
107
+ for route in app.routes:
108
+ if isinstance(route, APIRoute):
109
+ route.operation_id = route.name
110
+ openapi_schema = get_openapi(
111
+ title=app.title,
112
+ version=app.version,
113
+ openapi_version=app.openapi_version,
114
+ description=app.description,
115
+ routes=app.routes,
116
+ )
117
+ app.openapi_schema = openapi_schema
118
+ return app.openapi_schema
119
+
120
+ app.openapi = custom_openapi
121
+ ",
102
122
  "apps/test_api/test_api/main.py": "from .init import app, lambda_handler, tracer
103
123
 
104
124
  handler = lambda_handler
@@ -5,6 +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
+ from fastapi.openapi.utils import get_openapi
8
9
  from fastapi.responses import JSONResponse
9
10
  from fastapi.routing import APIRoute
10
11
  from mangum import Mangum
@@ -47,7 +48,7 @@ async def metrics_handler(request: Request, call_next):
47
48
  metrics.add_metric(name="RequestCount", unit=MetricUnit.Count, value=1)
48
49
 
49
50
  response = await call_next(request)
50
-
51
+
51
52
  if response.status_code == 200:
52
53
  metrics.add_metric(name="Success", unit=MetricUnit.Count, value=1)
53
54
 
@@ -92,4 +93,22 @@ class LoggerRouteHandler(APIRoute):
92
93
 
93
94
  return route_handler
94
95
 
95
- app.router.route_class = LoggerRouteHandler
96
+ app.router.route_class = LoggerRouteHandler
97
+
98
+ def custom_openapi():
99
+ if app.openapi_schema:
100
+ return app.openapi_schema
101
+ for route in app.routes:
102
+ if isinstance(route, APIRoute):
103
+ route.operation_id = route.name
104
+ openapi_schema = get_openapi(
105
+ title=app.title,
106
+ version=app.version,
107
+ openapi_version=app.openapi_version,
108
+ description=app.description,
109
+ routes=app.routes,
110
+ )
111
+ app.openapi_schema = openapi_schema
112
+ return app.openapi_schema
113
+
114
+ app.openapi = custom_openapi
@@ -1,19 +1,12 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`fastapi react generator > should generate OpenAPI spec script > generate_open_api.py 1`] = `
4
- "from fastapi.openapi.utils import get_openapi
5
- from src.main import app
4
+ "from src.main import app
6
5
  import json, os, sys
7
6
 
8
7
  os.makedirs(os.path.dirname(sys.argv[1]), exist_ok=True)
9
8
  with open(sys.argv[1], 'w') as f:
10
- json.dump(get_openapi(
11
- title=app.title,
12
- version=app.version,
13
- openapi_version=app.openapi_version,
14
- description=app.description,
15
- routes=app.routes,
16
- ), f)
9
+ json.dump(app.openapi(), f)
17
10
  "
18
11
  `;
19
12
 
@@ -1,13 +1,6 @@
1
- from fastapi.openapi.utils import get_openapi
2
1
  from <%= moduleName %>.main import app
3
2
  import json, os, sys
4
3
 
5
4
  os.makedirs(os.path.dirname(sys.argv[1]), exist_ok=True)
6
5
  with open(sys.argv[1], 'w') as f:
7
- json.dump(get_openapi(
8
- title=app.title,
9
- version=app.version,
10
- openapi_version=app.openapi_version,
11
- description=app.description,
12
- routes=app.routes,
13
- ), f)
6
+ json.dump(app.openapi(), f)