I am trying to write code for my openapi 3.0.0 which can generate the JSON output according to the yml specs I have written for my code, my Python Flask code is present in controller called default_controllers.py. It is basically open api generator by which I have to get values using my GET api I am building in yml through swagger editor.
My Code -->default_controllers.py present in controllers directory
from flask import Flask, jsonify, request
from flask import Flask, jsonify
from flasgger import Swagger, swag_from
app = Flask(__name__)
app.config['SWAGGER'] = {
'openapi': '3.0.0'
}
swagger = Swagger(app)
@app.route('/calls/<details>/')
@swag_from('/home/teladmin/Desktop/python-flask-server-generated/swagger_server/swagger/swagger.yaml')
def calls(details):
all_calls = {
'totalCalls': [1000],
'message': [200],
'successfulCalls': [800],
'failedCalls': [300],
}
if details == 'all':A
result = all_calls
else:
result = {details: all_calls.get(details)}
return jsonify(result)
app.run(debug=True)
Below is my yaml file which I have written using swaggereditor.io and generate python-flask zip using Generate Server tab
openapi: 3.0.0
info:
title: Simple API overview
version: 2.0.0
servers:
- url: /
paths:
/details/{allCalls}:
get:
summary: Get a allCalls details
operationId: details_all_calls_get
parameters:
- name: allCalls
in: path
description: Numeric ID of the user to get
required: true
style: simple
explode: false
schema:
type: integer
responses:
"200":
description: 200 response
x-openapi-router-controller: swagger_server.controllers.default_controller
/details/{totalCalls}:
get:
summary: Get a total Calls details
operationId: details_total_calls_get
parameters:
- name: totalCalls
in: path
description: Numeric ID of the user to get
required: true
style: simple
explode: false
schema:
type: integer
responses:
"200":
description: 200 response
x-openapi-router-controller: swagger_server.controllers.default_controller
/details/{message}:
get:
summary: Get message details
operationId: details_message_get
parameters:
- name: message
in: path
description: Numeric ID of the user to get
required: true
style: simple
explode: false
schema:
type: integer
responses:
"200":
description: 200 response
x-openapi-router-controller: swagger_server.controllers.default_controller
/details/{successfulCalls}:
get:
summary: Get a succesfull call details
operationId: details_successful_calls_get
parameters:
- name: successfulCalls
in: path
description: Numeric ID of the user to get
required: true
style: simple
explode: false
schema:
type: integer
responses:
"200":
description: 200 response
x-openapi-router-controller: swagger_server.controllers.default_controller
/details/{failedCalls}:
get:
summary: Get a failedCalls details
operationId: details_failed_calls_get
parameters:
- name: failedCalls
in: path
description: Numeric ID of the user to get
required: true
style: simple
explode: false
schema:
type: integer
responses:
"200":
description: 200 response
x-openapi-router-controller: swagger_server.controllers.default_controller
components: {}
I want my output as below when I run my python code on the localhost:port/apidocs
{
"totalCalls": [
1000
],
"message": [
200
],
"successfulCalls": [
800
],
"failedCalls": [
300
]
}
I already debugged it alot but not able to fix it, Please help me it is much needed thing.