Ошибка публикации API WSO2 для файла Flasgger Swagger - схема / свойства являются неожиданными

Я создал приложение, используя Python+Flask и Flasgger для создания развязной страницы. Swagger генерируется правильно и работает нормально.

Я использую менеджер API WSO2 (v2.5.0) и пытаюсь добавить новый API, используя URL-адрес Swagger (созданный приложением выше).

При импорте файла json Swagger; тег схемы, объекта или свойств (присутствует в json-файле Сваггера), ни один из них не распознается WSO2, который не может быть опубликован моим API в WSO2.

Ниже мой файл чванства JSON

            {
      "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 издателя

Ниже приведен код Python, в котором я написал определение чванства

    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, которое использует тело запроса в формате json и API успешно публикуется в WSO2?

1 ответ

Ошибка, которую я делал, была смешана с синтаксисом OpenAPI 2.0 и 3.0, как указано в комментариях. После исправления спецификации файл (спецификации Swiger JSON api) теперь успешно публикуется в WSO2 API.

Вопрос был обновлен с правильной спецификацией JSON

У меня есть образец для Sagger на WSO2 api. Я делаю ref schame и пишу параметр

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

Другие вопросы по тегам