首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flasgger Swagger文件-架构/属性的WSO2 API发布错误是意外的

Flasgger Swagger文件-架构/属性的WSO2 API发布错误是意外的
EN

Stack Overflow用户
提问于 2018-08-23 12:03:23
回答 2查看 545关注 0票数 0

我使用Python+Flask和Flasgger创建了一个应用程序来创建swagger页面。Swagger正在被正确地生成,并且运行良好。

我正在使用WSO2 (v2.5.0) API管理器,并试图使用Swagger (由上面的应用程序生成)添加一个新的API。

在导入Swagger的json文件;模式、对象或属性标记(出现在Swagger的json文件中)时,没有一个是由WSO2识别的,因为WSO2无法在WSO2中发布my。

下面是我的豪迈的json文件

代码语言:javascript
复制
            {
      "definitions": {}, 
      "info": {
        "description": "powered by Flasgger", 
        "termsOfService": "/tos", 
        "title": "A swagger API", 
        "version": "0.0.1"
      }, 
      "paths": {
        "/api/runTimeEngine": {
          "get": {
            "consumes": [
              "application/x-www-form-urlencoded"
            ], 
            "parameters": [
              {
                "description": "output options json in string format holding value for output array body to contain intermediate data. {\"optParam1\" true,\"optParam2\" false,\"optParam3\" false,\"optParam4\" false,\"optParam5\" false,\"optParam6\" false,\"optParam7\" false}",  
                "in": "formData", 
                "name": "output_request", 
                "type": "string"
              }
            ], 
            "produces": [
              "application/json"
            ], 
            "responses": {
              "200": {
                "description": "Time Analysis Engine predicted output. JSON based", 
                "schema": {
                  "properties": {
                    "ResponseParam1": {
                      "description": "The ResponseParam1 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "ResponseParam2": {
                      "description": "The ResponseParam2 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "ResponseParam3": {
                      "description": "The ResponseParam3 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "timestamp": {
                      "description": "The time of output in String format. Convert this to date time as per your convenience. The dateTime stays in the same zone format as supplied", 
                      "type": "string"
                    }
                  }
                }
              }, 
              "400": {
                "description": "#Bad request.\n\nAuthorization Token Missing.\n\nMalformed Request, Analysis Engine cannot be executed\n
              }, 
              "401": {
                "description": "You are not authorized to this request"
              }
            }, 
            "security": [
              {
                "APIKeyHeader": []
              }, 
              {
                "APIKeyQueryParam": []
              }
            ], 
            "summary": "This is the API to execute Time Analysis Engine With Default Configuration", 
            "tags": [
              "Time Analysis Engine API"
            ]
          }, 
          "post": {
            "consumes": [
              "multipart/form-data"
            ], 
            "parameters": [
              {
                "description": "Configuration File for execution of Time Analysis Engine", 
                "in": "formData", 
                "name": "fileParam1", 
                "required": true, 
                "type": "file"
              }, 
              {
                "description": " Data File for execution of Time Analysis Engine", 
                "in": "formData", 
                "name": "fileParam2", 
                "required": true, 
                "type": "file"
              }, 
              {
                "description": "output options json in string format holding value for output array body to contain intermediate data. {\"optParam1\" true,\"optParam2\" false,\"optParam3\" false,\"optParam4\" false,\"optParam5\" false,\"optParam6\" false,\"optParam7\" false}", 
                "in": "formData", 
                "name": "output_request", 
                "type": "string"
              }
            ], 
            "produces": [
              "application/json"
            ], 
            "responses": {
              "200": {
                "description": "Time Analysis engine predicted output. JSON based", 
                "schema": {
                  "properties": {
                    "ResponseParam1": {
                      "description": "The ResponseParam1 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "ResponseParam2": {
                      "description": "The ResponseParam2 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "ResponseParam3": {
                      "description": "The ResponseParam3 output at the timestamp analysis was executed", 
                      "type": "number"
                    }, 
                    "timestamp": {
                      "description": "The time of output in String format. Convert this to date time as per your convenience. The dateTime stays in the same zone format as supplied", 
                      "type": "string"
                    }
                  }
                }
              }, 
              "400": {
                "description": "#Bad request.\n\nAuthorization Token Missing.\n\nMalformed Request, Time Analysis Engine cannot be executed\n\nFile holder name is missing. The supported file holders are fileParam1, fileParam2\n\nWrong File uploaded against config param Supported extensions are xlsx or xls\n"
              }, 
              "401": {
                "description": "You are not authorized to this request"
              }
            }, 
            "security": [
              {
                "APIKeyHeader": []
              }, 
              {
                "APIKeyQueryParam": []
              }
            ], 
            "summary": "Call this api passing a Config File, Data File and choice of options in json body", 
            "tags": [
              "Time Analysis Engine API"
            ]
          }
        }
      }, 
      "securityDefinitions": {
        "APIKeyHeader": {
          "in": "header", 
          "name": "X-Api-Key", 
          "type": "apiKey"
        }, 
        "APIKeyQueryParam": {
          "in": "query", 
          "name": "api_key", 
          "type": "apiKey"
        }
      }, 
      "swagger": "2.0"
    }

尝试在WSO2 API发布服务器中发布时出现错误片段

下面是我编写了swagger定义的python代码

代码语言:javascript
复制
    from flask import Flask, request, abort, render_template, send_from_directory
    from flasgger import Swagger

    import os
    import sys


    engine_main = Flask(__name__)
    Swagger(engine_main)

    @engine_main.route('/')
    def index():
        return render_template('index.html')


    @engine_main.route('/api/runEngine', methods=['GET'])
    def runEngineGet():
        """
        This is the API to execute Engine With Default Configuration
        ---
        tags:
          - Engine API,
        consumes:
            - application/x-www-form-urlencoded
        produces:
         - application/json
        parameters:
          - in: header
            name: Authorization
            type: string
            schema:
                type: string
                format: Bearer ********
            required: true
            description: Bearer ******** where ****** is your api token name. This name is used to make directories
          - name: X
            in: formData
            type: file
            required: true
            description: File1 for execution of Engine
          - name: Y
            in: formData
            type: file
            required: true
            description: File2 for execution of Engine
          - name: output_request
            type: object
            in: formData
            schema: {"Op1": true,"Op2": false,"Op3": false,"Op4": false,"Op5": false,"Op6": false,"Op7": false}
            description: output options json holding value for output array body to contain intermediate data. { "Op1" true, "Op2" false, "Op3" false, "Op4" false, "Op5" false, "Op6" false, "Op7" false}
        responses:
          400:
            description:  |
             #Bad request.

             Authorization Token Missing.

             Malformed Request, Engine cannot be executed

             File holder name is missing. The supported file holders are X, Y

             Wrong File uploaded against config param Supported extensions are xlsx or xls

          401:
            description: You are not authorized to this request
          200:
            description: Predicted output. JSON based
            schema:
              properties:
                timestamp:
                  type: datetime
                  description: The time of output
                Response1:
                  type: float
                  description: The Response1 output at the timestamp analysis was executed
                Response2:
                  type: float
                  description: The Response2 output at the timestamp analysis was executed
                Response3:
                  type: float
                  description: The Response3 output at the timestamp analysis was executed
        """
        //////Method Call


        #print(request.json)


    if __name__ == '__main__':
        engine_main.run(port='9090', debug=True)

是否有其他方法为Python+Flask应用程序生成适当的swagger,该应用程序以json格式使用请求体,api被成功地发布到WSO2

EN

回答 2

Stack Overflow用户

发布于 2018-08-23 15:41:42

正如注释中指出的那样,我所犯的错误是混合了OpenAPI 2.0和3.0语法。在修改规范之后,文件(Swagger规范)现在已经成功地发布到发布的WSO2 api中。

这个问题已经用适当的JSON规范更新了

票数 0
EN

Stack Overflow用户

发布于 2019-10-31 05:18:14

我有WSO2 api上的Sagger示例。我引用schame并写参数。

代码语言:javascript
复制
swagger: "2.0"
paths:
  /listProforma:
    get:
      responses:
        "200":
          description: ""
      x-auth-type: "Application & Application User"
      x-throttling-tier: Unlimited
    post:
      parameters:
        - name: Payload
          description: Request Body
          required: false
          in: body
          schema:
            type: object
            required:
              - page
              - limit
            properties:
              page:
                type: integer
                example: 1
              limit:
                type: integer
                example: 1
              containerIn:
                type: string
                example: TAKU6017000
      responses:
        "200":
          description: ""
      x-auth-type: "Application & Application User"
      x-throttling-tier: Unlimited
  /list:
    post:
      parameters:
        - name: Payload
          in: body
          description: Request Body Parameter
          required: false
          schema:
            $ref: "#/definitions/paramPayloadList"
      responses:
        "200":
          description: ""
      x-auth-type: "Application & Application User"
      x-throttling-tier: Unlimited
      x-roles: ""
      produces:
        - application/json
      consumes:
        - application/json
definitions:
  paramPayloadList:
    required:
      - page
      - limit
    properties:
      page:
        type: integer
        example: 1
      limit:
        type: integer
        example: 4
      containerIn:
        type: string
        example: TAKU6017000
info:
  title: CustomerBilling
  version: v1.0.0

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51985402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档