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: packages/azure-functions-openapi/README.md
-26Lines changed: 0 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,56 +1,42 @@
1
1
# @apvee/azure-functions-openapi
2
2
3
3
## Overview
4
-
5
4
`@apvee/azure-functions-openapi` is an extension for Azure Functions V4 that simplifies the process of integrating OpenAPI documentation. It automatically generates and serves OpenAPI 2.0, 3.0.3, and 3.1.0 definitions and provides a Swagger UI for your Azure Functions. Built on top of `@asteasolutions/zod-to-openapi`, it uses **Zod Schemas** for type-safe request validation and response handling, ensuring that your API is well-documented and easy to explore.
6
5
7
6
## Benefits of Documenting APIs with OpenAPI
8
-
9
7
Documenting your APIs with OpenAPI offers several significant advantages:
10
-
11
8
-**Always Up-to-Date Documentation**: By integrating OpenAPI documentation directly into your codebase, you ensure that your API documentation is always in sync with the implementation. This reduces the risk of discrepancies between the documentation and the actual API behavior, leading to a more reliable and trustworthy API.
12
-
13
9
-**Auto-Generated Client Libraries**: OpenAPI specifications can be used to automatically generate client libraries for various programming languages. Tools like [Kiota](https://github.com/microsoft/kiota) and [OpenAPI Generator](https://openapi-generator.tech/) can create client SDKs that developers can use to interact with your API. This saves time and effort, as developers do not need to manually write and maintain client code.
14
-
15
10
-**Improved Developer Experience**: Comprehensive and accurate API documentation makes it easier for developers to understand and use your API. With tools like Swagger UI, developers can interact with your API directly from the documentation, making it easier to test and explore the available endpoints.
16
-
17
11
-**Enhanced API Testing**: OpenAPI documentation can be used to generate test cases and validate API responses. This helps ensure that your API behaves as expected and meets the defined specifications.
18
-
19
12
-**Standardization and Consistency**: Using OpenAPI promotes standardization and consistency across your API endpoints. This makes it easier for developers to work with your API and reduces the learning curve for new users.
20
-
21
13
-**Interoperability**: OpenAPI is a widely adopted standard, and many tools and platforms support it. By documenting your API with OpenAPI, you ensure that it can be easily integrated with other systems and tools that support the OpenAPI standard.
22
14
23
15
By leveraging the benefits of OpenAPI documentation, you can create a more robust, user-friendly, and maintainable API that meets the needs of both developers and end-users.
24
16
25
17
## Key Features
26
-
27
18
-**Automatic OpenAPI Specification Generation**: Generate OpenAPI 2.0, 3.0.3, and 3.1.0 definitions for your Azure Functions based on registered schemas and handlers.
28
19
-**Integrated Swagger UI**: Serve a Swagger UI interface that dynamically loads and visualizes the OpenAPI definitions.
29
20
-**Type-Safe Request and Response Validation**: Leverage Zod schemas to validate request bodies, query parameters, headers, and more.
30
21
-**Flexible API Configuration**: Customize security schemas, routes, authentication levels, and request/response handling through simple utility functions.
31
22
-**Native Azure Functions Support**: Seamlessly integrates with Azure Functions V4 to enhance your serverless applications with robust API documentation.
32
23
33
24
## Installation
34
-
35
25
To install the package and its dependencies, run:
36
-
37
26
```bash
38
27
npm install @apvee/azure-functions-openapi
39
28
```
40
-
41
29
You'll also need the following peer dependencies:
42
30
```bash
43
31
npm install @azure/functions zod
44
32
```
45
-
46
33
## Exposing OpenAPI and Swagger UI
47
34
You can expose OpenAPI documentation and serve a Swagger UI interface using two key functions: registerOpenAPIHandler and registerSwaggerUIHandler. These functions can be invoked from the index.ts file in the src directory of your Azure Functions project, making it easy to configure global behaviors for your functions.
48
35
49
36
### Expose OpenAPI Documentation
50
37
The registerOpenAPIHandler function registers an HTTP GET handler that serves the OpenAPI definition.
This function registers Zod schemas as named types in the OpenAPI registry.
147
127
@@ -150,7 +130,6 @@ This function registers Zod schemas as named types in the OpenAPI registry.
150
130
-**schema**: The Zod schema defining the structure.
151
131
152
132
**Example**:
153
-
154
133
```typescript
155
134
const UserSchema =z.object({
156
135
id: z.string(),
@@ -169,7 +148,6 @@ This function registers an Azure Function with OpenAPI documentation, including
169
148
-**options**: Configuration for the handler, HTTP methods, request validation, and responses.
170
149
171
150
**Example**:
172
-
173
151
```typescript
174
152
registerFunction("myFunction", "Processes user data", {
175
153
handler: async (req, ctx) => {
@@ -201,7 +179,6 @@ In the context of integrating OpenAPI documentation with Azure Functions, it is
201
179
-**Enhanced Configuration**: Provides additional configuration options for request validation, response handling, and security schemas.
202
180
203
181
## Utility Functions for Handling Parameters with Zod
204
-
205
182
This library provides two utility functions to convert parameters from HttpRequestParams and URLSearchParams into plain JavaScript objects. These functions are useful for validating and processing parameters using Zod schemas.
206
183
207
184
```convertHttpRequestParamsToObject```:
@@ -219,7 +196,6 @@ export function convertHttpRequestParamsToObject(params: HttpRequestParams): { [
219
196
- A plain object where keys and values are strings.
By exploring the ```test-functions``` project, you can gain a better understanding of how to leverage the features provided by ```@apvee/azure-functions-openapi``` to enhance your Azure Functions with comprehensive OpenAPI documentation.
278
253
279
254
## License
280
-
281
255
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.
0 commit comments