Skip to content

Commit ba4db10

Browse files
committed
fix: correct spelling of 'azureFunctionRoutePrefix' in multiple files and update package versions
1 parent e2718fb commit ba4db10

File tree

12 files changed

+13
-46
lines changed

12 files changed

+13
-46
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/azure-functions-openapi/README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,42 @@
11
# @apvee/azure-functions-openapi
22

33
## Overview
4-
54
`@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.
65

76
## Benefits of Documenting APIs with OpenAPI
8-
97
Documenting your APIs with OpenAPI offers several significant advantages:
10-
118
- **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-
139
- **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-
1510
- **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-
1711
- **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-
1912
- **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-
2113
- **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.
2214

2315
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.
2416

2517
## Key Features
26-
2718
- **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.
2819
- **Integrated Swagger UI**: Serve a Swagger UI interface that dynamically loads and visualizes the OpenAPI definitions.
2920
- **Type-Safe Request and Response Validation**: Leverage Zod schemas to validate request bodies, query parameters, headers, and more.
3021
- **Flexible API Configuration**: Customize security schemas, routes, authentication levels, and request/response handling through simple utility functions.
3122
- **Native Azure Functions Support**: Seamlessly integrates with Azure Functions V4 to enhance your serverless applications with robust API documentation.
3223

3324
## Installation
34-
3525
To install the package and its dependencies, run:
36-
3726
```bash
3827
npm install @apvee/azure-functions-openapi
3928
```
40-
4129
You'll also need the following peer dependencies:
4230
```bash
4331
npm install @azure/functions zod
4432
```
45-
4633
## Exposing OpenAPI and Swagger UI
4734
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.
4835

4936
### Expose OpenAPI Documentation
5037
The registerOpenAPIHandler function registers an HTTP GET handler that serves the OpenAPI definition.
5138

5239
Example (index.ts):
53-
5440
```typescript
5541
import { OpenAPIObjectConfig, registerOpenAPIHandler, registerSwaggerUIHandler } from '@apvee/azure-functions-openapi';
5642
import { app } from '@azure/functions';
@@ -95,7 +81,6 @@ const documents = [
9581

9682
registerSwaggerUIHandler("anonymous", 'api', documents);
9783
```
98-
9984
#### ```registerOpenAPIHandler```
10085
This function registers an OpenAPI handler for an Azure Function.
10186

@@ -110,7 +95,6 @@ This function registers an OpenAPI handler for an Azure Function.
11095
- An object containing the title and URL of the registered OpenAPI document.
11196

11297
**Example**:
113-
11498
```typescript
11599
const documentInfo = registerOpenAPIHandler('anonymous', openAPIConfig, '3.1.0', 'json');
116100
```
@@ -124,24 +108,20 @@ This function registers a Swagger UI handler for an Azure Function.
124108
- **documents**: An array of OpenAPI document information objects.
125109

126110
**Example**:
127-
128111
```typescript
129112
registerSwaggerUIHandler('anonymous', 'api', documents);
130113
```
131114

132115
#### ```registerApiKeySecuritySchema```
133116
This function registers an API key security schema in the OpenAPI registry.
134-
135117
**Parameters**:
136118
- **name**: The name of the API key (e.g., **X-API-KEY**).
137119
- **input**: The location of the API key in the request (**'header'**, **'query'**, or **'cookie'**).
138120

139121
**Example**:
140-
141122
```typescript
142123
const securityRequirement = registerApiKeySecuritySchema('X-API-KEY', 'header');
143124
```
144-
145125
#### ```registerTypeSchema```
146126
This function registers Zod schemas as named types in the OpenAPI registry.
147127

@@ -150,7 +130,6 @@ This function registers Zod schemas as named types in the OpenAPI registry.
150130
- **schema**: The Zod schema defining the structure.
151131

152132
**Example**:
153-
154133
```typescript
155134
const UserSchema = z.object({
156135
id: z.string(),
@@ -169,7 +148,6 @@ This function registers an Azure Function with OpenAPI documentation, including
169148
- **options**: Configuration for the handler, HTTP methods, request validation, and responses.
170149

171150
**Example**:
172-
173151
```typescript
174152
registerFunction("myFunction", "Processes user data", {
175153
handler: async (req, ctx) => {
@@ -201,7 +179,6 @@ In the context of integrating OpenAPI documentation with Azure Functions, it is
201179
- **Enhanced Configuration**: Provides additional configuration options for request validation, response handling, and security schemas.
202180

203181
## Utility Functions for Handling Parameters with Zod
204-
205182
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.
206183

207184
```convertHttpRequestParamsToObject```:
@@ -219,7 +196,6 @@ export function convertHttpRequestParamsToObject(params: HttpRequestParams): { [
219196
- A plain object where keys and values are strings.
220197

221198
**Example**:
222-
223199
```typescript
224200
import { z } from 'zod';
225201
import { convertHttpRequestParamsToObject } from './utils';
@@ -250,7 +226,6 @@ export function convertURLSearchParamsToObject(params: URLSearchParams): { [key:
250226
- A plain object where keys are strings and values are either strings or arrays of strings.
251227

252228
**Example**:
253-
254229
```typescript
255230
import { z } from 'zod';
256231
import { convertURLSearchParamsToObject } from './utils';
@@ -277,5 +252,4 @@ https://github.com/apvee/azure-functions-nodejs-monorepo/tree/main/packages/test
277252
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.
278253

279254
## License
280-
281255
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.

packages/azure-functions-openapi/core/registerFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function registerPath(
112112
summary: summary,
113113
method: mapHttpMethod(method),
114114
// Add the route to the OpenAPI registry, with the route prefix if it exists
115-
path: (options.azureFuntionRoutePrefix) ? `/${options.azureFuntionRoutePrefix}/${options.route}` : options.route,
115+
path: (options.azureFunctionRoutePrefix) ? `/${options.azureFunctionRoutePrefix}/${options.route}` : options.route,
116116
security: options.security,
117117
request: options.request,
118118
responses: options.responses,

packages/azure-functions-openapi/core/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ export type OpenAPIObjectConfig = Omit<OpenAPIObject, 'paths' | 'components' | '
5050
* @property {HttpHandler} handler - The handler function for the route.
5151
* @property {HttpMethod[]} methods - An array of HTTP methods supported by the route.
5252
* @property {'anonymous' | 'function' | 'admin'} authLevel - The authorization level required for the route.
53-
* @property {string} azureFuntionRoutePrefix - The prefix for the Azure Function route.
53+
* @property {string} azureFunctionRoutePrefix - The prefix for the Azure Function route.
5454
* @property {string} route - The route path.
5555
*/
5656
export type FunctionRouteConfig = Omit<RouteConfig, 'method' | 'path' | 'summary'> & {
5757
handler: HttpHandler,
5858
methods: HttpMethod[];
5959
authLevel: 'anonymous' | 'function' | 'admin',
60-
azureFuntionRoutePrefix: string,
60+
azureFunctionRoutePrefix: string,
6161
route: string
6262
};
6363

packages/azure-functions-openapi/handlers/swaggerUI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { OpenAPIDocumentInfo } from "../core/types";
55
* Registers a Swagger UI handler for an Azure Function.
66
*
77
* @param {'anonymous' | 'function' | 'admin'} authLevel - The authorization level required to access the Swagger UI.
8-
* @param {string} azureFuntionRoutePrefix - The route prefix for the Azure Function. Defaults to 'api'.
8+
* @param {string} azureFunctionRoutePrefix - The route prefix for the Azure Function. Defaults to 'api'.
99
* @param {OpenAPIDocumentInfo[]} openAPIDocuments - An array of OpenAPI document information objects to be included in the Swagger UI.
1010
*
1111
* This function sets up an HTTP GET handler that serves a Swagger UI page, which lists the provided OpenAPI documents.
1212
* The Swagger UI is configured to use the provided URLs and titles for the OpenAPI documents.
1313
*/
14-
export function registerSwaggerUIHandler(authLevel: 'anonymous' | 'function' | 'admin' = 'anonymous', azureFuntionRoutePrefix: string | null = 'api', openAPIDocuments: OpenAPIDocumentInfo[]): void {
14+
export function registerSwaggerUIHandler(authLevel: 'anonymous' | 'function' | 'admin' = 'anonymous', azureFunctionRoutePrefix: string | null = 'api', openAPIDocuments: OpenAPIDocumentInfo[]): void {
1515
const fxHandler = async (request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => {
1616
context.log(`Invoking SwaggerUI handler for url "${request.url}"`);
1717

1818
const urls = openAPIDocuments.map(doc => {
1919
return {
20-
url: `/${azureFuntionRoutePrefix}/${doc.url}`,
20+
url: `/${azureFunctionRoutePrefix}/${doc.url}`,
2121
name: doc.title
2222
};
2323
});

packages/azure-functions-openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apvee/azure-functions-openapi",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/apvee/azure-functions-nodejs-monorepo.git"

packages/test-functions/src/functions/AddTodo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ registerFunction(
3737
methods: ['POST'],
3838
authLevel: 'anonymous',
3939
security: [apiKeySecurity],
40-
azureFuntionRoutePrefix: 'api',
40+
azureFunctionRoutePrefix: 'api',
4141
route: 'todos',
4242
request: {
4343
body: {

packages/test-functions/src/functions/DeleteTodo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ registerFunction(
3535
methods: ['DELETE'],
3636
authLevel: 'anonymous',
3737
security: [apiKeySecurity],
38-
azureFuntionRoutePrefix: 'api',
38+
azureFunctionRoutePrefix: 'api',
3939
route: 'todos/{id}',
4040
request: {
4141
params: TodoParamIDSchema

packages/test-functions/src/functions/GetAllTodos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ registerFunction(
5252
methods: ['GET'],
5353
authLevel: 'anonymous',
5454
security: [apiKeySecurity],
55-
azureFuntionRoutePrefix: 'api',
55+
azureFunctionRoutePrefix: 'api',
5656
route: 'todos',
5757
request: {
5858
query: FilterParamsSchema

packages/test-functions/src/functions/GetSingleTodo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ registerFunction(
4242
methods: ['GET'],
4343
authLevel: 'anonymous',
4444
security: [apiKeySecurity],
45-
azureFuntionRoutePrefix: 'api',
45+
azureFunctionRoutePrefix: 'api',
4646
route: 'todos/{id}',
4747
request: {
4848
params: TodoParamIDSchema

0 commit comments

Comments
 (0)