Azure函数PowerShell API的OpenAPI规范配置

Azure函数PowerShell API的OpenAPI规范配置,azure,azure-functions,swagger-2.0,azure-api-management,Azure,Azure Functions,Swagger 2.0,Azure Api Management,如何通过Visual Studio代码配置在Azure函数中运行的PowerShell API,以便它可以作为Azure API管理中的OpenAPI规范API使用,如中所述 目前,如果我尝试将下面的PowerShell API添加为Azure API管理中的OpenAPI规范API,则会出现错误 Unable to parse specified file. Please ensure it is valid OpenAPI specification document. Azure函数Po

如何通过Visual Studio代码配置在Azure函数中运行的PowerShell API,以便它可以作为Azure API管理中的OpenAPI规范API使用,如中所述

目前,如果我尝试将下面的PowerShell API添加为Azure API管理中的OpenAPI规范API,则会出现错误

Unable to parse specified file. Please ensure it is valid OpenAPI specification document.
Azure函数PowerShell API URL:

APIM支持导入:

  • OpenAPI规范
  • WSDL
  • 小河

链接中的内容--两者都不是。我一点也不确定它的格式。因此无法导入。APIM支持导入:

  • OpenAPI规范
  • WSDL
  • 小河

链接中的内容--两者都不是。我一点也不确定它的格式。因此无法导入。

更新

事情发生了变化,当我们在V2函数应用程序中单击API定义时,请参见

当前V2运行时不支持函数API定义(Swagger)功能

我们可以直接使用,而无需API定义


您需要首先为Azure函数创建OpenAPI定义

步骤:

  • 平台功能>API定义

  • 在API定义源下,选择
    Function(Preview)
    将HTTP触发器用作API处理程序

  • 生成API定义模板>保存

  • 为httptrigger函数模板粘贴以下招摇过市模板

  • 然后用你的函数应用和触发器名称修改它。如果您的功能授权级别为匿名,请删除
    安全性
    部分

    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
    
    swagger:'2.0'
    信息:
    标题:.azurewebsites.net
    版本:1.0.0
    主机:.azurewebsites.net
    基本路径:/
    计划:
    -https
    -http
    路径:
    /api/:
    获取:
    操作ID:/api//get
    描述:将名称发送到API以获取Hello名称
    摘要:获取Hello name
    参数:
    -in:查询
    姓名:姓名
    描述:要发送的名称
    必填项:true
    类型:字符串
    响应:
    '200':
    description:返回Hello name
    安全:
    -apikeyQuery:[]
    职位:
    操作ID:/api//post
    描述:将名称发送到API以获取Hello名称
    摘要:获取Hello name
    消耗:
    -应用程序/json
    参数:
    -姓名:requestbody
    在:身体
    描述:要发送的名称
    必填项:true
    模式:
    类型:对象
    特性:
    姓名:
    类型:字符串
    响应:
    '200':
    description:返回Hello name
    安全:
    -apikeyQuery:[]
    证券定义:
    apikeyQuery:
    类型:apiKey
    姓名:代码
    in:查询
    
  • 在API管理中添加API时,可以选择
    OpenAPI规范
    函数应用

    如果您离开安全部分,因为您的功能授权级别是Admin/function,那么您必须在
    Manage
    blade of function下拉菜单中找到功能键,并在
    Inbound Processing
    中更新后端URL

    当您选择
    Function-App
    时,您可能会得到添加密钥的明确提示

    已导入函数应用程序“funcappname”。请确保将以下命名值的值替换为函数的机密:funcappname\u triggername\u query\uxxxxxx

  • 看看你是否需要改变你的招摇过市


  • 更新

    事情发生了变化,当我们在V2函数应用程序中单击API定义时,请参见

    当前V2运行时不支持函数API定义(Swagger)功能

    我们可以直接使用,而无需API定义


    您需要首先为Azure函数创建OpenAPI定义

    步骤:

  • 平台功能>API定义

  • 在API定义源下,选择
    Function(Preview)
    将HTTP触发器用作API处理程序

  • 生成API定义模板>保存

  • 为httptrigger函数模板粘贴以下招摇过市模板

  • 然后用你的函数应用和触发器名称修改它。如果您的功能授权级别为匿名,请删除
    安全性
    部分

    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
    
    swagger:'2.0'
    信息:
    标题:.azurewebsites.net
    版本:1.0.0
    主机:.azurewebsites.net
    基本路径:/
    计划:
    -https
    -http
    路径:
    /api/:
    获取:
    操作ID:/api//get
    描述:将名称发送到API以获取Hello名称
    摘要:获取Hello name
    参数:
    -in:查询
    姓名:姓名
    描述:要发送的名称
    必填项:true
    类型:字符串
    响应:
    '200':
    description:返回Hello name
    安全:
    -apikeyQuery:[]
    职位:
    操作ID:/api//post
    描述:将名称发送到API以获取Hello名称
    摘要:获取Hello name
    消耗:
    -应用程序/json
    参数:
    -姓名:requestbody
    在:身体
    描述:要发送的名称
    必填项:true
    模式:
    类型:对象
    特性:
    姓名:
    类型:字符串
    响应:
    '200':
    description:返回Hello name
    安全:
    -apikeyQuery:[]
    证券定义:
    apikeyQuery:
    类型:apiKey
    姓名:代码
    in:查询
    
  • 在API管理中添加API时,可以选择
    OpenAPI规范
    函数应用

    如果您离开安全部分,因为您的功能授权级别是Admin/function,您必须在
    Manage
    blade of function下拉菜单中找到功能键,并在
    Inbound Processi中更新后端URL