-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external app not include to openapi testing
* Add linting to ci
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from typing import Dict, Union | ||
|
||
from flask import Flask, request | ||
from markupsafe import escape | ||
from pydantic import BaseModel | ||
|
||
from esmerald import JSON, Gateway, Include, get | ||
from esmerald.middleware import WSGIMiddleware | ||
from esmerald.openapi.datastructures import OpenAPIResponse | ||
from esmerald.testclient import create_client | ||
|
||
flask_app = Flask(__name__) | ||
|
||
|
||
@flask_app.route("/") | ||
def flask_main(): | ||
name = request.args.get("name", "Esmerald") | ||
return f"Hello, {escape(name)} from Flask!" | ||
|
||
|
||
class Item(BaseModel): | ||
sku: Union[int, str] | ||
|
||
|
||
@get() | ||
def read_people() -> Dict[str, str]: | ||
return {"id": "foo"} | ||
|
||
|
||
@get( | ||
"/item", | ||
description="Read an item", | ||
responses={200: OpenAPIResponse(model=Item, description="The SKU information of an item")}, | ||
) | ||
async def read_item() -> JSON: | ||
return JSON(content={"id": 1}) | ||
|
||
|
||
def test_external_app_not_include_in_schema(test_client_factory): | ||
with create_client( | ||
routes=[ | ||
Gateway(handler=read_people), | ||
Include("/child", app=WSGIMiddleware(flask_app)), | ||
] | ||
) as client: | ||
response = client.get("/openapi.json") | ||
assert response.status_code == 200, response.text | ||
|
||
assert response.json() == { | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "Esmerald", | ||
"summary": "Esmerald application", | ||
"description": "test_client", | ||
"contact": {"name": "admin", "email": "[email protected]"}, | ||
"version": client.app.version, | ||
}, | ||
"servers": [{"url": "/"}], | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"summary": "Read People", | ||
"operationId": "read_people__get", | ||
"responses": { | ||
"200": { | ||
"description": "Successful response", | ||
"content": {"application/json": {"schema": {}}}, | ||
} | ||
}, | ||
"deprecated": False, | ||
} | ||
}, | ||
}, | ||
} |