@@ -106,7 +106,7 @@ def _replace_const(d):
106
106
107
107
108
108
def _patch_dict (d , key , transform , filter_null = False ):
109
- if isinstance (d , dict ):
109
+ if isinstance (d , dict ): # noqa:PLR1702 (too-many-nested-blocks)
110
110
for k , v in list (d .items ()): # so we can pop
111
111
if isinstance (v , (dict , list )):
112
112
_patch_dict (v , key , transform )
@@ -156,6 +156,13 @@ class endpoint:
156
156
Allows for almost seamless integration of pydantic models with OpenAPI,
157
157
generating YAML for the endpoint from type hints.
158
158
159
+ # Parameters
160
+
161
+ - method: HTTP verb, defaults to "get"
162
+ - path_prefix: The optional prefix, to support multiple APIs (e.g. internal vs. external).
163
+ - security: A custom security, defaults to basic auth
164
+ - response_model_exclude_none: Whether to remove Nones from the response (defaults to False)
165
+ - deprecated: Whether to mark this endpoint as deprecated
159
166
160
167
# Collecting Endpoint Information
161
168
@@ -247,16 +254,19 @@ def create_app():
247
254
def __init__ (
248
255
self ,
249
256
path ,
257
+ * ,
250
258
method = "get" ,
251
259
path_prefix = "default" ,
252
260
security = None ,
253
261
response_model_exclude_none = False ,
262
+ deprecated = False ,
254
263
):
255
264
self .path = path
256
265
self .method = method .lower ()
257
266
self .path_prefix = path_prefix
258
267
self .security = security if security is not None else endpoint .SECURITY_BASIC
259
268
self .response_model_exclude_none = response_model_exclude_none
269
+ self .deprecated = deprecated
260
270
261
271
def __call__ (self , fn ):
262
272
parameters = []
@@ -322,9 +332,7 @@ def __call__(self, fn):
322
332
request_body ["content" ]["multipart/form-data" ]["schema" ]["properties" ][arg ] = {"description" : docs ["param" ][arg ], ** param ["schema" ]}
323
333
else :
324
334
parameters .append (param )
325
- PATHS .setdefault (self .path_prefix , {}).setdefault (self .path , {})[
326
- self .method
327
- ] = {
335
+ endpoint_config = {
328
336
"parameters" : parameters ,
329
337
"summary" : summary ,
330
338
"description" : description ,
@@ -342,6 +350,11 @@ def __call__(self, fn):
342
350
** self .security ,
343
351
** ({"requestBody" : request_body } if request_body else {}),
344
352
}
353
+ if self .deprecated :
354
+ endpoint_config ["deprecated" ] = True
355
+ PATHS .setdefault (self .path_prefix , {}).setdefault (self .path , {})[
356
+ self .method
357
+ ] = endpoint_config
345
358
346
359
@functools .wraps (fn )
347
360
def wrapper (* args , ** kwargs ):
@@ -355,7 +368,7 @@ def wrapper(*args, **kwargs):
355
368
356
369
return wrapper
357
370
358
- def _get_schema (self , annotation , default , in_ , name = None , example = None ):
371
+ def _get_schema (self , annotation , default , in_ , name = None , example = None ): # noqa:PLR0912 (too-many-branches)
359
372
constraints = None
360
373
origin = typing .get_origin (annotation )
361
374
if str (annotation ).startswith ("typing.Optional" ):
0 commit comments