This tool generates an OpenAPI definition for an Azure Function App built with the @senacor/azure-function-middleware.
npm install @senacor/azure-function-middleware-openapi-generator --save-devCreate a configuration file openapi-generation.config.json in the project's root directory:
{
"apiDefinitions": [
{
"title": "My API",
"outputFile": "api.yaml"
}
]
}See chapter configuration for more options.
Run the OpenAPI generator with:
npx @senacor/azure-function-middleware-openapi-generatorThe configuration is stored in the file openapi-generation.config.json. Every API is described by an ApiDefinitionConfiguration object stored in the
apiDefinitions array.
Parameters for ApiDefinitionConfiguration:
| Name | Type | Required | Description |
|---|---|---|---|
| title | string | x | Title of the API definition |
| description | string | Description for the API definition | |
| servers | ServerObject[] | Details for the server section of the OpenAPI definition | |
| servers[].url | string | x | |
| servers[].description | string | ||
| servers[].variables | Record<string, string> | ||
| outputFile | string | x | Name of the generated file. Supported file extensions are .json and .yaml |
| functionNameRegexToInclude | string[] | List of regex patters to include http functions based on their name | |
| functionNameRegexToExclude | string[] | List of regex patters to exclude http functions based on their name | |
| excludeRequestBody | boolean | Exclude the request body from the generated API definition | |
| excludeResponseBody | boolean | Exclude the response body from the generated API definition |
Logic to include / exclude http functions:
- If
functionNameRegexToIncludeandfunctionNameRegexToExcludeare not specified all functions are used. - Otherwise:
- If
functionNameRegexToExcludeis defined and the http function name matches some pattern fromfunctionNameRegexToExclude, then the http function will be excluded from the api definition. - If
functionNameRegexToIncludeis defined and the http function name matches some pattern fromfunctionNameRegexToInclude, then the http function will be included into the api definition.
- If
- URL path parameters
- URL query parameters if
requestQueryParamsValidationis used - Request body schema if
requestBodyValidationis used - Response body schema if
responseBodyValidationis used - Security schemas for bearer and function key authentication