| 1 |
import importlib |
| 2 |
import json |
| 3 |
import pathlib |
| 4 |
from unittest.mock import patch |
| 5 |
|
| 6 |
from inline_snapshot import snapshot |
| 7 |
|
| 8 |
from docs_src.generate_clients import tutorial003_py310 |
| 9 |
|
| 10 |
|
| 11 |
def test_remove_tags(tmp_path: pathlib.Path): |
| 12 |
tmp_file = tmp_path / "openapi.json" |
| 13 |
openapi_json = tutorial003_py310.app.openapi() |
| 14 |
tmp_file.write_text(json.dumps(openapi_json)) |
| 15 |
|
| 16 |
with patch("pathlib.Path", return_value=tmp_file): |
| 17 |
importlib.import_module("docs_src.generate_clients.tutorial004_py310") |
| 18 |
|
| 19 |
modified_openapi = json.loads(tmp_file.read_text()) |
| 20 |
assert modified_openapi == snapshot( |
| 21 |
{ |
| 22 |
"components": { |
| 23 |
"schemas": { |
| 24 |
"HTTPValidationError": { |
| 25 |
"properties": { |
| 26 |
"detail": { |
| 27 |
"items": { |
| 28 |
"$ref": "#/components/schemas/ValidationError", |
| 29 |
}, |
| 30 |
"title": "Detail", |
| 31 |
"type": "array", |
| 32 |
}, |
| 33 |
}, |
| 34 |
"title": "HTTPValidationError", |
| 35 |
"type": "object", |
| 36 |
}, |
| 37 |
"Item": { |
| 38 |
"properties": { |
| 39 |
"name": { |
| 40 |
"title": "Name", |
| 41 |
"type": "string", |
| 42 |
}, |
| 43 |
"price": { |
| 44 |
"title": "Price", |
| 45 |
"type": "number", |
| 46 |
}, |
| 47 |
}, |
| 48 |
"required": [ |
| 49 |
"name", |
| 50 |
"price", |
| 51 |
], |
| 52 |
"title": "Item", |
| 53 |
"type": "object", |
| 54 |
}, |
| 55 |
"ResponseMessage": { |
| 56 |
"properties": { |
| 57 |
"message": { |
| 58 |
"title": "Message", |
| 59 |
"type": "string", |
| 60 |
}, |
| 61 |
}, |
| 62 |
"required": [ |
| 63 |
"message", |
| 64 |
], |
| 65 |
"title": "ResponseMessage", |
| 66 |
"type": "object", |
| 67 |
}, |
| 68 |
"User": { |
| 69 |
"properties": { |
| 70 |
"email": { |
| 71 |
"title": "Email", |
| 72 |
"type": "string", |
| 73 |
}, |
| 74 |
"username": { |
| 75 |
"title": "Username", |
| 76 |
"type": "string", |
| 77 |
}, |
| 78 |
}, |
| 79 |
"required": [ |
| 80 |
"username", |
| 81 |
"email", |
| 82 |
], |
| 83 |
"title": "User", |
| 84 |
"type": "object", |
| 85 |
}, |
| 86 |
"ValidationError": { |
| 87 |
"properties": { |
| 88 |
"ctx": {"title": "Context", "type": "object"}, |
| 89 |
"input": {"title": "Input"}, |
| 90 |
"loc": { |
| 91 |
"items": { |
| 92 |
"anyOf": [ |
| 93 |
{ |
| 94 |
"type": "string", |
| 95 |
}, |
| 96 |
{ |
| 97 |
"type": "integer", |
| 98 |
}, |
| 99 |
], |
| 100 |
}, |
| 101 |
"title": "Location", |
| 102 |
"type": "array", |
| 103 |
}, |
| 104 |
"msg": { |
| 105 |
"title": "Message", |
| 106 |
"type": "string", |
| 107 |
}, |
| 108 |
"type": { |
| 109 |
"title": "Error Type", |
| 110 |
"type": "string", |
| 111 |
}, |
| 112 |
}, |
| 113 |
"required": [ |
| 114 |
"loc", |
| 115 |
"msg", |
| 116 |
"type", |
| 117 |
], |
| 118 |
"title": "ValidationError", |
| 119 |
"type": "object", |
| 120 |
}, |
| 121 |
}, |
| 122 |
}, |
| 123 |
"info": { |
| 124 |
"title": "FastAPI", |
| 125 |
"version": "0.1.0", |
| 126 |
}, |
| 127 |
"openapi": "3.1.0", |
| 128 |
"paths": { |
| 129 |
"/items/": { |
| 130 |
"get": { |
| 131 |
"operationId": "get_items", |
| 132 |
"responses": { |
| 133 |
"200": { |
| 134 |
"content": { |
| 135 |
"application/json": { |
| 136 |
"schema": { |
| 137 |
"items": { |
| 138 |
"$ref": "#/components/schemas/Item", |
| 139 |
}, |
| 140 |
"title": "Response Items-Get Items", |
| 141 |
"type": "array", |
| 142 |
}, |
| 143 |
}, |
| 144 |
}, |
| 145 |
"description": "Successful Response", |
| 146 |
}, |
| 147 |
}, |
| 148 |
"summary": "Get Items", |
| 149 |
"tags": [ |
| 150 |
"items", |
| 151 |
], |
| 152 |
}, |
| 153 |
"post": { |
| 154 |
"operationId": "create_item", |
| 155 |
"requestBody": { |
| 156 |
"content": { |
| 157 |
"application/json": { |
| 158 |
"schema": { |
| 159 |
"$ref": "#/components/schemas/Item", |
| 160 |
}, |
| 161 |
}, |
| 162 |
}, |
| 163 |
"required": True, |
| 164 |
}, |
| 165 |
"responses": { |
| 166 |
"200": { |
| 167 |
"content": { |
| 168 |
"application/json": { |
| 169 |
"schema": { |
| 170 |
"$ref": "#/components/schemas/ResponseMessage", |
| 171 |
}, |
| 172 |
}, |
| 173 |
}, |
| 174 |
"description": "Successful Response", |
| 175 |
}, |
| 176 |
"422": { |
| 177 |
"content": { |
| 178 |
"application/json": { |
| 179 |
"schema": { |
| 180 |
"$ref": "#/components/schemas/HTTPValidationError", |
| 181 |
}, |
| 182 |
}, |
| 183 |
}, |
| 184 |
"description": "Validation Error", |
| 185 |
}, |
| 186 |
}, |
| 187 |
"summary": "Create Item", |
| 188 |
"tags": [ |
| 189 |
"items", |
| 190 |
], |
| 191 |
}, |
| 192 |
}, |
| 193 |
"/users/": { |
| 194 |
"post": { |
| 195 |
"operationId": "create_user", |
| 196 |
"requestBody": { |
| 197 |
"content": { |
| 198 |
"application/json": { |
| 199 |
"schema": { |
| 200 |
"$ref": "#/components/schemas/User", |
| 201 |
}, |
| 202 |
}, |
| 203 |
}, |
| 204 |
"required": True, |
| 205 |
}, |
| 206 |
"responses": { |
| 207 |
"200": { |
| 208 |
"content": { |
| 209 |
"application/json": { |
| 210 |
"schema": { |
| 211 |
"$ref": "#/components/schemas/ResponseMessage", |
| 212 |
}, |
| 213 |
}, |
| 214 |
}, |
| 215 |
"description": "Successful Response", |
| 216 |
}, |
| 217 |
"422": { |
| 218 |
"content": { |
| 219 |
"application/json": { |
| 220 |
"schema": { |
| 221 |
"$ref": "#/components/schemas/HTTPValidationError", |
| 222 |
}, |
| 223 |
}, |
| 224 |
}, |
| 225 |
"description": "Validation Error", |
| 226 |
}, |
| 227 |
}, |
| 228 |
"summary": "Create User", |
| 229 |
"tags": [ |
| 230 |
"users", |
| 231 |
], |
| 232 |
}, |
| 233 |
}, |
| 234 |
}, |
| 235 |
} |
| 236 |
) |