Reputation: 23
I have created an application using Python+Flask and Flasgger to create swagger page. Swagger is getting generated properly and is working fine.
I am using WSO2 (v2.5.0) API manager and trying to add a new API using a Swagger URL(generated by above app).
While importing the Swagger's json file; schema or object or properties tag (present in Swagger's json file), none of them are being recognized by WSO2 which fails my API publish in WSO2.
Below is my swagger json file
{
"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
Below is the python code in which I have written the swagger definition
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)
Is there any other way to generate a proper swagger for a Python+Flask app which consumes request body in json format and the api gets published to WSO2 successfull
Upvotes: 0
Views: 673
Reputation: 11
i have sample for Sagger on WSO2 api. i make ref schame and write on parameter
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
Upvotes: 0
Reputation: 23
The Mistake I was doing was mixed of OpenAPI 2.0 and 3.0 syntax as pointed in comments. After correcting the spec, the file (Swagger JSON api spec) is now successfully getting published to the WSO2 API published.
The question has been updated with proper JSON spec
Upvotes: 0