Browse Source
* Allow to add OpenAPI tag descriptions * fix type hint * fix type hint 2 * refactor test to assure 100% coverage * 📝 Update tags metadata example * 📝 Update docs for tags metadata * ✅ Move tags metadata test to tutorial subdir * 🎨 Update format in applications * 🍱 Update docs UI image based on new example * 🎨 Apply formatting after solving conflicts Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>pull/1576/head
committed by
GitHub
7 changed files with 153 additions and 3 deletions
After Width: | Height: | Size: 47 KiB |
@ -0,0 +1,28 @@ |
|||||
|
from fastapi import FastAPI |
||||
|
|
||||
|
tags_metadata = [ |
||||
|
{ |
||||
|
"name": "users", |
||||
|
"description": "Operations with users. The **login** logic is also here.", |
||||
|
}, |
||||
|
{ |
||||
|
"name": "items", |
||||
|
"description": "Manage items. So _fancy_ they have their own docs.", |
||||
|
"externalDocs": { |
||||
|
"description": "Items external docs", |
||||
|
"url": "https://fastapi.tiangolo.com/", |
||||
|
}, |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
app = FastAPI(openapi_tags=tags_metadata) |
||||
|
|
||||
|
|
||||
|
@app.get("/users/", tags=["users"]) |
||||
|
async def get_users(): |
||||
|
return [{"name": "Harry"}, {"name": "Ron"}] |
||||
|
|
||||
|
|
||||
|
@app.get("/items/", tags=["items"]) |
||||
|
async def get_items(): |
||||
|
return [{"name": "wand"}, {"name": "flying broom"}] |
@ -0,0 +1,65 @@ |
|||||
|
from fastapi.testclient import TestClient |
||||
|
|
||||
|
from metadata.tutorial004 import app |
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
openapi_schema = { |
||||
|
"openapi": "3.0.2", |
||||
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
||||
|
"paths": { |
||||
|
"/users/": { |
||||
|
"get": { |
||||
|
"tags": ["users"], |
||||
|
"summary": "Get Users", |
||||
|
"operationId": "get_users_users__get", |
||||
|
"responses": { |
||||
|
"200": { |
||||
|
"description": "Successful Response", |
||||
|
"content": {"application/json": {"schema": {}}}, |
||||
|
} |
||||
|
}, |
||||
|
} |
||||
|
}, |
||||
|
"/items/": { |
||||
|
"get": { |
||||
|
"tags": ["items"], |
||||
|
"summary": "Get Items", |
||||
|
"operationId": "get_items_items__get", |
||||
|
"responses": { |
||||
|
"200": { |
||||
|
"description": "Successful Response", |
||||
|
"content": {"application/json": {"schema": {}}}, |
||||
|
} |
||||
|
}, |
||||
|
} |
||||
|
}, |
||||
|
}, |
||||
|
"tags": [ |
||||
|
{ |
||||
|
"name": "users", |
||||
|
"description": "Operations with users. The **login** logic is also here.", |
||||
|
}, |
||||
|
{ |
||||
|
"name": "items", |
||||
|
"description": "Manage items. So _fancy_ they have their own docs.", |
||||
|
"externalDocs": { |
||||
|
"description": "Items external docs", |
||||
|
"url": "https://fastapi.tiangolo.com/", |
||||
|
}, |
||||
|
}, |
||||
|
], |
||||
|
} |
||||
|
|
||||
|
|
||||
|
def test_openapi_schema(): |
||||
|
response = client.get("/openapi.json") |
||||
|
assert response.status_code == 200, response.text |
||||
|
assert response.json() == openapi_schema |
||||
|
|
||||
|
|
||||
|
def test_path_operations(): |
||||
|
response = client.get("/items/") |
||||
|
assert response.status_code == 200, response.text |
||||
|
response = client.get("/users/") |
||||
|
assert response.status_code == 200, response.text |
Loading…
Reference in new issue