I'm trying to build a simple API with Swagger/Flask/Connexion, however the example on their GitHub does not work, even after installing connexion[swagger-ui] as specified here
pip3 install 'connexion[swagger-ui]'
Here is my helloworld-api.yaml:
openapi: "3.0.0"
info:
title: Hello World
version: "1.0"
servers:
- url: http://localhost:9090/swagger
paths:
/greeting:
get:
summary: Generate greeting
description: Generates a greeting message.
operationId: hello.get_greeting
responses:
200:
description: greeting response
content:
text/plain:
schema:
type: string
example: "hello dave!"
parameters:
- in: query
name: name
required: true
schema:
type: string
example: "dave"
description: Name of the person to greet.
and my hello.py
#!/usr/bin/env python3
import connexion
def get_greeting(name: str) -> str:
return f'Hello {name}'
if __name__ == '__main__':
app = connexion.FlaskApp(__name__, specification_dir='openapi/')
app.add_api('helloworld-api.yaml', arguments={'title': 'Hello World Example'})
app.run(port=8080)
hello.py is in the root directory and helloworld-api.yaml is in a folder called openapi/. Navigating to a 0.0.0.0:8080/swagger in a browser returns this:
{
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404,
"title": "Not Found",
"type": "about:blank"
}
Same goes for the get method I've specified. Any ideas? I've been banging my head against a brick wall over this.