Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic index route #179

Merged
merged 8 commits into from
Jun 28, 2023
27 changes: 27 additions & 0 deletions app/openapi.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ tags:
- name: Health
- name: User
paths:
/:
get:
parameters: []
responses:
'200':
content:
application/json:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, why did apiflask generate this as application/json? is it a bug/unsupported functionality in apiflask or did we need to configure something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this and was wondering the same thing. I'll take a look at the documentation and see why it did that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having looked at how the generation works before, you'll need to look in apispec: https://apispec.readthedocs.io/en/latest/ as it is what generates the schema

Alternatively, do you think it would make sense to not include this in the schema? I'm not sure about when you define a route directly, but if you make an APIBlueprint, you should be able to pass in enable_openapi=False and it shouldn't be a part of Openapi.

schema:
type: object
properties:
message:
type: string
description: The message to return
data: {}
status_code:
type: integer
description: The HTTP status code
warnings:
type: array
items:
$ref: '#/components/schemas/ValidationError'
errors:
type: array
items:
$ref: '#/components/schemas/ValidationError'
description: Successful response
summary: Index
/health:
get:
parameters: []
Expand Down
17 changes: 17 additions & 0 deletions app/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def create_app() -> APIFlask:

configure_app(app)
register_blueprints(app)
build_index_route(app)
kylegunby marked this conversation as resolved.
Show resolved Hide resolved

return app


Expand Down Expand Up @@ -73,3 +75,18 @@ def register_blueprints(app: APIFlask) -> None:

def get_project_root_dir() -> str:
return os.path.join(os.path.dirname(__file__), "..")


def build_index_route(app: APIFlask) -> None:
@app.route("/")
def index():
return '''
<!Doctype html>
<html>
<head><title>Home</title></head>
<body>
<h1>Home</h1>
<p>Visit <a href="/docs">/docs</a> to view the api documentation for this project.</p>
</body>
</html>
'''