You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+8-141Lines changed: 8 additions & 141 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -485,7 +485,7 @@ This value will override the value of the failed response validation http code s
485
485
486
486
We use the `Annotated` type to tell the Event Handler that a particular parameter is not only an optional string, but also a query string with constraints.
487
487
488
-
In the following example, we use a new `Query` OpenAPI type to add [one out of many possible constraints](#customizing-openapi-parameters), which should read as:
488
+
In the following example, we use a new `Query` OpenAPI type to add [one out of many possible constraints](openapi.md#customizing-parameters), which should read as:
489
489
490
490
*`completed` is a query string with a `None` as its default value
491
491
*`completed`, when set, should have at minimum 4 characters
@@ -539,7 +539,7 @@ In the following example, we use a new `Query` OpenAPI type to add [one out of m
539
539
540
540
#### Validating path parameters
541
541
542
-
Just like we learned in [query string validation](#validating-query-strings), we can use a new `Path` OpenAPI type to [add constraints](#customizing-openapi-parameters).
542
+
Just like we learned in [query string validation](#validating-query-strings), we can use a new `Path` OpenAPI type to [add constraints](openapi.md#customizing-parameters).
543
543
544
544
For example, we could validate that `<todo_id>` dynamic path should be no greater than three digits.
545
545
@@ -555,7 +555,7 @@ For example, we could validate that `<todo_id>` dynamic path should be no greate
555
555
556
556
We use the `Annotated` type to tell the Event Handler that a particular parameter is a header that needs to be validated. Also, we adhere to [HTTP RFC standards](https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2){target="_blank" rel="nofollow"}, which means we treat HTTP headers as case-insensitive.
557
557
558
-
In the following example, we use a new `Header` OpenAPI type to add [one out of many possible constraints](#customizing-openapi-parameters), which should read as:
558
+
In the following example, we use a new `Header` OpenAPI type to add [one out of many possible constraints](openapi.md#customizing-parameters), which should read as:
559
559
560
560
*`correlation_id` is a header that must be present in the request
561
561
*`correlation_id` should have 16 characters
@@ -716,28 +716,15 @@ We provide pre-defined errors for the most popular ones based on [AWS Lambda API
716
716
717
717
### Enabling SwaggerUI
718
718
719
-
!!! note "This feature requires [data validation](#data-validation) feature to be enabled."
719
+
???+ tip "OpenAPI documentation has moved"
720
+
For complete OpenAPI documentation including Swagger UI customization, security schemes, and OpenAPI Merge for micro-functions, see the dedicated [OpenAPI documentation](openapi.md).
720
721
721
-
Behind the scenes, the [data validation](#data-validation) feature auto-generates an OpenAPI specification from your routes and type annotations. You can use [Swagger UI](https://swagger.io/tools/swagger-ui/){target="_blank" rel="nofollow"} to visualize and interact with your newly auto-documented API.
722
-
723
-
There are some important **caveats** that you should know before enabling it:
| Swagger UI is **publicly accessible by default**| When using `enable_swagger` method, you can [protect sensitive API endpoints by implementing a custom middleware](#customizing-swagger-ui) using your preferred authorization mechanism. |
728
-
|**No micro-functions support** yet | Swagger UI is enabled on a per resolver instance which will limit its accuracy here. |
729
-
| You need to expose a **new route**| You'll need to expose the following path to Lambda: `/swagger`; ignore if you're routing this path already. |
730
-
| JS and CSS files are **embedded within Swagger HTML**| If you are not using an external CDN to serve Swagger UI assets, we embed JS and CSS directly into the HTML. To enhance performance, please consider enabling the `compress` option to minimize the size of HTTP requests. |
731
-
| Authorization data is **lost** on browser close/refresh | Use `enable_swagger(persist_authorization=True)` to persist authorization data, like OAuath 2.0 access tokens. |
722
+
Use `enable_swagger()` to serve interactive API documentation:
1.`enable_swagger` creates a route to serve Swagger UI and allows quick customizations. <br><br> You can also include middlewares to protect or enhance the overall experience.
738
-
739
-
Here's an example of what it looks like by default:
740
-
741
728

742
729
743
730
### Custom Domain API Mappings
@@ -1179,128 +1166,8 @@ This will enable full tracebacks errors in the response, print request and respo
1179
1166
1180
1167
### OpenAPI
1181
1168
1182
-
When you enable [Data Validation](#data-validation), we use a combination of Pydantic Models and [OpenAPI](https://www.openapis.org/){target="_blank" rel="nofollow"} type annotations to add constraints to your API's parameters.
1183
-
1184
-
???+ warning "OpenAPI schema version depends on the installed version of Pydantic"
In OpenAPI documentation tools like [SwaggerUI](#enabling-swaggerui), these annotations become readable descriptions, offering a self-explanatory API interface. This reduces boilerplate code while improving functionality and enabling auto-documentation.
1188
-
1189
-
???+ note
1190
-
We don't have support for files, form data, and header parameters at the moment. If you're interested in this, please [open an issue](https://github.com/aws-powertools/powertools-lambda-python/issues/new?assignees=&labels=feature-request%2Ctriage&projects=&template=feature_request.yml&title=Feature+request%3A+TITLE).
The `enable_swagger` method accepts the same metadata as described at [Customizing OpenAPI metadata](#customizing-openapi-metadata).
1222
-
1223
-
The Swagger UI appears by default at the `/swagger` path, but you can customize this to serve the documentation from another path and specify the source for Swagger UI assets.
1224
-
1225
-
Below is an example configuration for serving Swagger UI from a custom path or CDN, with assets like CSS and JavaScript loading from a chosen CDN base URL.
???-info "Does Powertools implement any of the security schemes?"
1244
-
No. Powertools adds support for generating OpenAPI documentation with [security schemes](https://swagger.io/docs/specification/authentication/), but it doesn't implement any of the security schemes itself, so you must implement the security mechanisms separately.
1245
-
1246
-
Security schemes are declared at the top-level first. You can reference them globally or on a per path _(operation)_ level. **However**, if you reference security schemes that are not defined at the top-level it will lead to a `SchemaValidationError`_(invalid OpenAPI spec)_.
|[HTTP auth](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml){target="_blank"} |`HTTPBase`| HTTP authentication schemes using the Authorization header (e.g: [Basic auth](https://swagger.io/docs/specification/authentication/basic-authentication/){target="_blank"}, [Bearer](https://swagger.io/docs/specification/authentication/bearer-authentication/){target="_blank"}) |
1277
-
|[API keys](https://swagger.io/docs/specification/authentication/api-keys/){target="_blank"} (e.g: query strings, cookies) |`APIKey`| API keys in headers, query strings or [cookies](https://swagger.io/docs/specification/authentication/cookie-authentication/){target="_blank"}. |
1278
-
|[OAuth 2](https://swagger.io/docs/specification/authentication/oauth2/){target="_blank"} |`OAuth2`| Authorization protocol that gives an API client limited access to user data on a web server. |
1279
-
|[OpenID Connect Discovery](https://swagger.io/docs/specification/authentication/openid-connect-discovery/){target="_blank"} |`OpenIdConnect`| Identity layer built [on top of the OAuth 2.0 protocol](https://openid.net/developers/how-connect-works/){target="_blank"} and supported by some OAuth 2.0. |
For a better experience when working with Lambda and Amazon API Gateway, customers can define extensions using the `openapi_extensions` parameter. We support defining OpenAPI extensions at the following levels of the OpenAPI JSON Schema: Root, Servers, Operation, and Security Schemes.
1292
-
1293
-
???+ warning
1294
-
We do not support the `x-amazon-apigateway-any-method` and `x-amazon-apigateway-integrations` extensions.
For complete OpenAPI documentation including customization, security schemes, extensions, and OpenAPI Merge for micro-functions, see the dedicated [OpenAPI documentation](openapi.md).
0 commit comments