I want to use Flasgger to read my openapi definitions from a swagger.yml
file.
My swagger.yml file:
# swagger.yml
openapi: 3.0.0
info:
title: "Job DB Flask EST API"
description: "An API about opportunities and applications"
version: "1.0.0"
paths:
/companies:
get:
operationId: "companies.read_all"
tags:
- Companies
summary: "Read the list of companies"
responses:
200:
description: "Successfully read companies list"
post:
operationId: "companies.create"
tags:
- Companies
summary: "Create a Company"
requestBody:
description: "Company to create"
required: True
content:
application/json:
schema:
x-body-name: "company"
$ref: "#/components/schemas/Company"
responses:
201:
description: "Successfully created company"
/companies/{Id}:
get:
operationId: "companies.read_one"
tags:
- Companies
summary: "Read one company"
parameters:
- $ref: "#/components/parameters/id"
responses:
200:
description: "Successfully read company"
put:
operationId: "companies.update"
tags:
- Companies
summary: "Update a company"
parameters:
- $ref: "#/components/parameters/id"
responses:
200:
description: "Successfully updated company"
requestBody:
content:
application/json:
schema:
x-body-name: "company"
$ref: "#/components/schemas/Company"
delete:
operationId: "companies.delete"
tags:
- Companies
summary: "Delete a company"
parameters:
- $ref: "#/components/parameters/id"
responses:
204:
description: "Successfully deleted company"
components:
parameters:
id:
name: "Id"
description: "Guid Identifier"
in: path
required: True
schema:
type: "string"
format: uuid
schemas:
CompanyStatus:
required:
- Id
properties:
Id:
type: "string"
format: uuid
Description:
type: "string"
Company:
type: "object"
required:
- Id
properties:
Id:
type: "string"
format: uuid
Name:
type: "string"
Description:
type: "string"
CompanyStatusId:
type: "string"
format: uuid
Opportunity:
required:
- Id
properties:
Id:
type: "string"
format: uuid
CompanyId:
type: "string"
format: uuid
Title:
type: "string"
Url:
type: "string"
Content:
type: "string"
Notes:
type: "string"
ApplicationMethod:
required:
- Id
properties:
Id:
type: "string"
format: uuid
Description:
type: "string"
ApplicationStatus:
required:
- Id
properties:
Id:
type: "string"
format: uuid
Description:
type: "string"
Application:
required:
- Id
properties:
Id:
type: "string"
format: uuid
Submitted:
type: "string"
format: date-time
OpportunityId:
type: "string"
format: uuid
ApplicationStatusId:
type: "string"
format: uuid
ApplicationMethodId:
type: "string"
format: uuid
Updated:
type: "string"
format: "date-time"
My init.py file:
from flask import Flask, jsonify, request
from .config import Config
from .extensions import db, swagger
from flasgger import Swagger, swag_from
from .models import Company
def create_app():
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
swagger.init_app(app)
@app.route('/companies', methods=['GET'])
@swag_from('swagger.yml', validation=True)
def companies_read_all():
"""
Read the list of my companies
:return: The list of companies
"""
companies = db.session.query(Company).all()
return jsonify([company.serialize() for company in companies])
return app
When I call flask run
and navigate to the Swagger UI (localhost/apidocs/) the UI loads but when I go to expand the endpoint the loading animation appears and stays there. No console messages or errors get printed out.
I've tried looking for documentation around the @app.route
and swag_from
lines. I've tried enabling validation as well. I get the feeling I'm missing something simple.