为 Azure Functions PowerShell API 打开 API 规范配置
OpenAPI specification configuration for Azure Functions PowerShell API
如何通过 Visual Studio 代码在 Azure Functions 中配置 PowerShell API 运行,以便它可以作为 OpenAPI-Specification API 从 Azure API 管理喜欢 this URL, as mentioned in the tutorial?
目前,如果我尝试在 Azure API 管理中添加以下 PowerShell API 作为 OpenAPI-Specification API,则会出现错误
Unable to parse specified file. Please ensure it is valid OpenAPI specification document.
Azure 函数 PowerShell API URL:
https://vscpsapi.azurewebsites.net/api/VSCPSapi
APIM 支持导入:
- OpenAPI 规范
- WSDL
- WADL
您的 link - https://vscpsapi.azurewebsites.net/api/VSCPSapi - 中的内容都不是。我完全不确定它的格式。所以无法导入。
更新
情况发生了变化,当我们在V2 Function app中点击API定义时,看到
Function API definition (Swagger) feature is not supported for V2 runtime currently.
我们可以直接import Function app to API Management而不用API定义。
您需要先为您的 Azure 函数创建一个 OpenAPI 定义。
步数:
平台功能 > API 定义。
在 API 定义源下,选择 Function(Preview)
将您的 HTTP 触发器用作 API 处理程序。
生成 API 定义模板 > 保存。
为 httptrigger 函数模板粘贴以下 swagger 模板。
然后用你的函数应用和触发器名称修改它。如果您的功能授权级别是匿名的,请删除 security
部分。
swagger: '2.0'
info:
title: <myfunctionapp>.azurewebsites.net
version: 1.0.0
host: <myfunctionapp>.azurewebsites.net
basePath: /
schemes:
- https
- http
paths:
/api/<MyHttpTrigger>:
get:
operationId: /api/<MyHttpTrigger>/get
description: Send a name to API to get Hello name back
summary: Get Hello name
parameters:
- in: query
name: name
description: Name to send
required: true
type: string
responses:
'200':
description: Return Hello name
security:
- apikeyQuery: []
post:
operationId: /api/<MyHttpTrigger>/post
description: Send a name to API to get Hello name back
summary: Get Hello name
consumes:
- application/json
parameters:
- name: requestbody
in: body
description: Name to send
required: true
schema:
type: object
properties:
name:
type: string
responses:
'200':
description: Return Hello name
security:
- apikeyQuery: []
securityDefinitions:
apikeyQuery:
type: apiKey
name: code
in: query
在API管理中添加API时,可以选择OpenAPI specification
或Function App
。
如果您离开安全部分,因为您的功能授权级别是 Admin/Function,您必须在功能下拉菜单 Manage
blade 中找到功能键并更新后端 URL 在 Inbound Processing
.
当您选择 Function App
时,您可能会收到添加密钥的明确提示。
Function App "funcappname" has been imported. Please make sure to replace the values of the following Named Values with the secrets of your functions: funcappname_triggername_query_xxxxxx.
如果您需要修改您的 swagger,请参阅 OpenAPI 2.0 docs。
如何通过 Visual Studio 代码在 Azure Functions 中配置 PowerShell API 运行,以便它可以作为 OpenAPI-Specification API 从 Azure API 管理喜欢 this URL, as mentioned in the tutorial?
目前,如果我尝试在 Azure API 管理中添加以下 PowerShell API 作为 OpenAPI-Specification API,则会出现错误
Unable to parse specified file. Please ensure it is valid OpenAPI specification document.
Azure 函数 PowerShell API URL: https://vscpsapi.azurewebsites.net/api/VSCPSapi
APIM 支持导入:
- OpenAPI 规范
- WSDL
- WADL
您的 link - https://vscpsapi.azurewebsites.net/api/VSCPSapi - 中的内容都不是。我完全不确定它的格式。所以无法导入。
更新
情况发生了变化,当我们在V2 Function app中点击API定义时,看到
Function API definition (Swagger) feature is not supported for V2 runtime currently.
我们可以直接import Function app to API Management而不用API定义。
您需要先为您的 Azure 函数创建一个 OpenAPI 定义。
步数:
平台功能 > API 定义。
在 API 定义源下,选择
Function(Preview)
将您的 HTTP 触发器用作 API 处理程序。生成 API 定义模板 > 保存。
为 httptrigger 函数模板粘贴以下 swagger 模板。
然后用你的函数应用和触发器名称修改它。如果您的功能授权级别是匿名的,请删除 security
部分。
swagger: '2.0'
info:
title: <myfunctionapp>.azurewebsites.net
version: 1.0.0
host: <myfunctionapp>.azurewebsites.net
basePath: /
schemes:
- https
- http
paths:
/api/<MyHttpTrigger>:
get:
operationId: /api/<MyHttpTrigger>/get
description: Send a name to API to get Hello name back
summary: Get Hello name
parameters:
- in: query
name: name
description: Name to send
required: true
type: string
responses:
'200':
description: Return Hello name
security:
- apikeyQuery: []
post:
operationId: /api/<MyHttpTrigger>/post
description: Send a name to API to get Hello name back
summary: Get Hello name
consumes:
- application/json
parameters:
- name: requestbody
in: body
description: Name to send
required: true
schema:
type: object
properties:
name:
type: string
responses:
'200':
description: Return Hello name
security:
- apikeyQuery: []
securityDefinitions:
apikeyQuery:
type: apiKey
name: code
in: query
在API管理中添加API时,可以选择
OpenAPI specification
或Function App
。如果您离开安全部分,因为您的功能授权级别是 Admin/Function,您必须在功能下拉菜单
Manage
blade 中找到功能键并更新后端 URL 在Inbound Processing
.当您选择
Function App
时,您可能会收到添加密钥的明确提示。Function App "funcappname" has been imported. Please make sure to replace the values of the following Named Values with the secrets of your functions: funcappname_triggername_query_xxxxxx.
如果您需要修改您的 swagger,请参阅 OpenAPI 2.0 docs。