我已经使用Python + Flask和Flasgger创建了一个应用程序来创建招摇页面。 Swagger生成正确,并且工作正常。
我正在使用WSO2(v2.5.0)API管理器,并尝试使用Swagger URL(由上述应用生成)添加新的API。
在导入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"
}
Error Snippet when trying to publish in WSO2 API publisher
下面是我在其中写出招摇定义的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
答案 0 :(得分:0)
我正在做的错误混合了注释中指出的OpenAPI 2.0和3.0语法。 更正规范后,文件(Swagger JSON api规范)现在已成功发布到已发布的WSO2 API。
该问题已使用正确的JSON规范进行了更新
答案 1 :(得分:0)
我在WSO2 api上有Sagger的示例。我制作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