Skip to content

APIScaffold

APIScaffold ⚓︎

Bases: Scaffold, ABC

Source code in flask_openapi3/scaffold.py
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
class APIScaffold(Scaffold, ABC):
    def _collect_openapi_info(
            self,
            rule: str,
            func: Callable,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            method: str = HTTPMethod.GET
    ) -> ParametersTuple:
        raise NotImplementedError

    def register_api(self, api) -> None:
        raise NotImplementedError

    @staticmethod
    def create_view_func(
            func,
            header,
            cookie,
            path,
            query,
            form,
            body,
            view_class=None,
            view_kwargs=None
    ):
        is_coroutine_function = iscoroutinefunction(func)
        if is_coroutine_function:
            @wraps(func)
            async def view_func(**kwargs) -> FlaskResponse:
                func_kwargs = _validate_request(
                    header=header,
                    cookie=cookie,
                    path=path,
                    query=query,
                    form=form,
                    body=body,
                    path_kwargs=kwargs
                )

                # handle async request
                if view_class:
                    signature = inspect.signature(view_class.__init__)
                    parameters = signature.parameters
                    if parameters.get("view_kwargs"):
                        view_object = view_class(view_kwargs=view_kwargs)
                    else:
                        view_object = view_class()
                    response = await func(view_object, **func_kwargs)
                else:
                    response = await func(**func_kwargs)
                return response
        else:
            @wraps(func)
            def view_func(**kwargs) -> FlaskResponse:
                func_kwargs = _validate_request(
                    header=header,
                    cookie=cookie,
                    path=path,
                    query=query,
                    form=form,
                    body=body,
                    path_kwargs=kwargs
                )

                # handle request
                if view_class:
                    signature = inspect.signature(view_class.__init__)
                    parameters = signature.parameters
                    if parameters.get("view_kwargs"):
                        view_object = view_class(view_kwargs=view_kwargs)
                    else:
                        view_object = view_class()
                    response = func(view_object, **func_kwargs)
                else:
                    response = func(**func_kwargs)
                return response

        if not hasattr(func, "view"):
            func.view = view_func

        return func.view

    def get(
            self,
            rule: str,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            **options: Any
    ) -> Callable:
        """
        Decorator for defining a REST API endpoint with the HTTP GET method.
        More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

        Arguments:
            rule: The URL rule string.
            tags: Adds metadata to a single tag.
            summary: A short summary of what the operation does.
            description: A verbose explanation of the operation behavior.
            external_docs: Additional external documentation for this operation.
            operation_id: Unique string used to identify the operation.
            extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
            extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
            responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
            extra_responses: **Deprecated in v3.x**. Extra information for responses.
            deprecated: Declares this operation to be deprecated.
            security: A declaration of which security mechanisms can be used for this operation.
            servers: An alternative server array to service this operation.
            openapi_extensions: Allows extensions to the OpenAPI Schema.
            doc_ui: Declares this operation to be shown. Default to True.
        """

        if extra_form is not None:
            warnings.warn(
                """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_body is not None:
            warnings.warn(
                """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_responses is not None:
            warnings.warn(
                """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
                DeprecationWarning)

        def decorator(func) -> Callable:
            header, cookie, path, query, form, body = \
                self._collect_openapi_info(
                    rule,
                    func,
                    tags=tags,
                    summary=summary,
                    description=description,
                    external_docs=external_docs,
                    operation_id=operation_id,
                    extra_form=extra_form,
                    extra_body=extra_body,
                    responses=responses,
                    extra_responses=extra_responses,
                    deprecated=deprecated,
                    security=security,
                    servers=servers,
                    openapi_extensions=openapi_extensions,
                    doc_ui=doc_ui,
                    method=HTTPMethod.GET
                )

            view_func = self.create_view_func(func, header, cookie, path, query, form, body)
            options.update({"methods": [HTTPMethod.GET]})
            self.add_url_rule(rule, view_func=view_func, **options)

            return func

        return decorator

    def post(
            self,
            rule: str,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            **options: Any
    ) -> Callable:
        """
        Decorator for defining a REST API endpoint with the HTTP POST method.
        More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

        Arguments:
            rule: The URL rule string.
            tags: Adds metadata to a single tag.
            summary: A short summary of what the operation does.
            description: A verbose explanation of the operation behavior.
            external_docs: Additional external documentation for this operation.
            operation_id: Unique string used to identify the operation.
            extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
            extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
            responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
            extra_responses: **Deprecated in v3.x**. Extra information for responses.
            deprecated: Declares this operation to be deprecated.
            security: A declaration of which security mechanisms can be used for this operation.
            servers: An alternative server array to service this operation.
            openapi_extensions: Allows extensions to the OpenAPI Schema.
            doc_ui: Declares this operation to be shown. Default to True.
        """
        if extra_form is not None:
            warnings.warn(
                """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_body is not None:
            warnings.warn(
                """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_responses is not None:
            warnings.warn(
                """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
                DeprecationWarning)

        def decorator(func) -> Callable:
            header, cookie, path, query, form, body = \
                self._collect_openapi_info(
                    rule,
                    func,
                    tags=tags,
                    summary=summary,
                    description=description,
                    external_docs=external_docs,
                    operation_id=operation_id,
                    extra_form=extra_form,
                    extra_body=extra_body,
                    responses=responses,
                    extra_responses=extra_responses,
                    deprecated=deprecated,
                    security=security,
                    servers=servers,
                    openapi_extensions=openapi_extensions,
                    doc_ui=doc_ui,
                    method=HTTPMethod.POST
                )

            view_func = self.create_view_func(func, header, cookie, path, query, form, body)
            options.update({"methods": [HTTPMethod.POST]})
            self.add_url_rule(rule, view_func=view_func, **options)

            return func

        return decorator

    def put(
            self,
            rule: str,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            **options: Any
    ) -> Callable:
        """
        Decorator for defining a REST API endpoint with the HTTP PUT method.
        More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

        Arguments:
            rule: The URL rule string.
            tags: Adds metadata to a single tag.
            summary: A short summary of what the operation does.
            description: A verbose explanation of the operation behavior.
            external_docs: Additional external documentation for this operation.
            operation_id: Unique string used to identify the operation.
            extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
            extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
            responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
            extra_responses: **Deprecated in v3.x**. Extra information for responses.
            deprecated: Declares this operation to be deprecated.
            security: A declaration of which security mechanisms can be used for this operation.
            servers: An alternative server array to service this operation.
            openapi_extensions: Allows extensions to the OpenAPI Schema.
            doc_ui: Declares this operation to be shown. Default to True.
        """
        if extra_form is not None:
            warnings.warn(
                """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_body is not None:
            warnings.warn(
                """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_responses is not None:
            warnings.warn(
                """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
                DeprecationWarning)

        def decorator(func) -> Callable:
            header, cookie, path, query, form, body = \
                self._collect_openapi_info(
                    rule,
                    func,
                    tags=tags,
                    summary=summary,
                    description=description,
                    external_docs=external_docs,
                    operation_id=operation_id,
                    extra_form=extra_form,
                    extra_body=extra_body,
                    responses=responses,
                    extra_responses=extra_responses,
                    deprecated=deprecated,
                    security=security,
                    servers=servers,
                    openapi_extensions=openapi_extensions,
                    doc_ui=doc_ui,
                    method=HTTPMethod.PUT
                )

            view_func = self.create_view_func(func, header, cookie, path, query, form, body)
            options.update({"methods": [HTTPMethod.PUT]})
            self.add_url_rule(rule, view_func=view_func, **options)

            return func

        return decorator

    def delete(
            self,
            rule: str,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            **options: Any
    ) -> Callable:
        """
        Decorator for defining a REST API endpoint with the HTTP DELETE method.
        More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

        Arguments:
            rule: The URL rule string.
            tags: Adds metadata to a single tag.
            summary: A short summary of what the operation does.
            description: A verbose explanation of the operation behavior.
            external_docs: Additional external documentation for this operation.
            operation_id: Unique string used to identify the operation.
            extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
            extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
            responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
            extra_responses: **Deprecated in v3.x**. Extra information for responses.
            deprecated: Declares this operation to be deprecated.
            security: A declaration of which security mechanisms can be used for this operation.
            servers: An alternative server array to service this operation.
            openapi_extensions: Allows extensions to the OpenAPI Schema.
            doc_ui: Declares this operation to be shown. Default to True.
        """
        if extra_form is not None:
            warnings.warn(
                """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_body is not None:
            warnings.warn(
                """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_responses is not None:
            warnings.warn(
                """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
                DeprecationWarning)

        def decorator(func) -> Callable:
            header, cookie, path, query, form, body = \
                self._collect_openapi_info(
                    rule,
                    func,
                    tags=tags,
                    summary=summary,
                    description=description,
                    external_docs=external_docs,
                    operation_id=operation_id,
                    extra_form=extra_form,
                    extra_body=extra_body,
                    responses=responses,
                    extra_responses=extra_responses,
                    deprecated=deprecated,
                    security=security,
                    servers=servers,
                    openapi_extensions=openapi_extensions,
                    doc_ui=doc_ui,
                    method=HTTPMethod.DELETE
                )

            view_func = self.create_view_func(func, header, cookie, path, query, form, body)
            options.update({"methods": [HTTPMethod.DELETE]})
            self.add_url_rule(rule, view_func=view_func, **options)

            return func

        return decorator

    def patch(
            self,
            rule: str,
            *,
            tags: Optional[List[Tag]] = None,
            summary: Optional[str] = None,
            description: Optional[str] = None,
            external_docs: Optional[ExternalDocumentation] = None,
            operation_id: Optional[str] = None,
            extra_form: Optional[ExtraRequestBody] = None,
            extra_body: Optional[ExtraRequestBody] = None,
            responses: Optional[ResponseDict] = None,
            extra_responses: Optional[Dict[str, dict]] = None,
            deprecated: Optional[bool] = None,
            security: Optional[List[Dict[str, List[Any]]]] = None,
            servers: Optional[List[Server]] = None,
            openapi_extensions: Optional[Dict[str, Any]] = None,
            doc_ui: bool = True,
            **options: Any
    ) -> Callable:
        """
        Decorator for defining a REST API endpoint with the HTTP PATCH method.
        More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

        Arguments:
            rule: The URL rule string.
            tags: Adds metadata to a single tag.
            summary: A short summary of what the operation does.
            description: A verbose explanation of the operation behavior.
            external_docs: Additional external documentation for this operation.
            operation_id: Unique string used to identify the operation.
            extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
            extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
            responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
            extra_responses: **Deprecated in v3.x**. Extra information for responses.
            deprecated: Declares this operation to be deprecated.
            security: A declaration of which security mechanisms can be used for this operation.
            servers: An alternative server array to service this operation.
            openapi_extensions: Allows extensions to the OpenAPI Schema.
            doc_ui: Declares this operation to be shown. Default to True.
        """
        if extra_form is not None:
            warnings.warn(
                """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_body is not None:
            warnings.warn(
                """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
                DeprecationWarning)
        if extra_responses is not None:
            warnings.warn(
                """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
                DeprecationWarning)

        def decorator(func) -> Callable:
            header, cookie, path, query, form, body = \
                self._collect_openapi_info(
                    rule,
                    func,
                    tags=tags,
                    summary=summary,
                    description=description,
                    external_docs=external_docs,
                    operation_id=operation_id,
                    extra_form=extra_form,
                    extra_body=extra_body,
                    responses=responses,
                    extra_responses=extra_responses,
                    deprecated=deprecated,
                    security=security,
                    servers=servers,
                    openapi_extensions=openapi_extensions,
                    doc_ui=doc_ui,
                    method=HTTPMethod.PATCH
                )

            view_func = self.create_view_func(func, header, cookie, path, query, form, body)
            options.update({"methods": [HTTPMethod.PATCH]})
            self.add_url_rule(rule, view_func=view_func, **options)

            return func

        return decorator

delete(rule, *, tags=None, summary=None, description=None, external_docs=None, operation_id=None, extra_form=None, extra_body=None, responses=None, extra_responses=None, deprecated=None, security=None, servers=None, openapi_extensions=None, doc_ui=True, **options) ⚓︎

Decorator for defining a REST API endpoint with the HTTP DELETE method. More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

Parameters:

Name Type Description Default
rule str

The URL rule string.

required
tags Optional[List[Tag]]

Adds metadata to a single tag.

None
summary Optional[str]

A short summary of what the operation does.

None
description Optional[str]

A verbose explanation of the operation behavior.

None
external_docs Optional[ExternalDocumentation]

Additional external documentation for this operation.

None
operation_id Optional[str]

Unique string used to identify the operation.

None
extra_form Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/form).

None
extra_body Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/json).

None
responses Optional[ResponseDict]

API responses should be either a subclass of BaseModel, a dictionary, or None.

None
extra_responses Optional[Dict[str, dict]]

Deprecated in v3.x. Extra information for responses.

None
deprecated Optional[bool]

Declares this operation to be deprecated.

None
security Optional[List[Dict[str, List[Any]]]]

A declaration of which security mechanisms can be used for this operation.

None
servers Optional[List[Server]]

An alternative server array to service this operation.

None
openapi_extensions Optional[Dict[str, Any]]

Allows extensions to the OpenAPI Schema.

None
doc_ui bool

Declares this operation to be shown. Default to True.

True
Source code in flask_openapi3/scaffold.py
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
def delete(
        self,
        rule: str,
        *,
        tags: Optional[List[Tag]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        external_docs: Optional[ExternalDocumentation] = None,
        operation_id: Optional[str] = None,
        extra_form: Optional[ExtraRequestBody] = None,
        extra_body: Optional[ExtraRequestBody] = None,
        responses: Optional[ResponseDict] = None,
        extra_responses: Optional[Dict[str, dict]] = None,
        deprecated: Optional[bool] = None,
        security: Optional[List[Dict[str, List[Any]]]] = None,
        servers: Optional[List[Server]] = None,
        openapi_extensions: Optional[Dict[str, Any]] = None,
        doc_ui: bool = True,
        **options: Any
) -> Callable:
    """
    Decorator for defining a REST API endpoint with the HTTP DELETE method.
    More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

    Arguments:
        rule: The URL rule string.
        tags: Adds metadata to a single tag.
        summary: A short summary of what the operation does.
        description: A verbose explanation of the operation behavior.
        external_docs: Additional external documentation for this operation.
        operation_id: Unique string used to identify the operation.
        extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
        extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
        responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
        extra_responses: **Deprecated in v3.x**. Extra information for responses.
        deprecated: Declares this operation to be deprecated.
        security: A declaration of which security mechanisms can be used for this operation.
        servers: An alternative server array to service this operation.
        openapi_extensions: Allows extensions to the OpenAPI Schema.
        doc_ui: Declares this operation to be shown. Default to True.
    """
    if extra_form is not None:
        warnings.warn(
            """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_body is not None:
        warnings.warn(
            """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_responses is not None:
        warnings.warn(
            """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
            DeprecationWarning)

    def decorator(func) -> Callable:
        header, cookie, path, query, form, body = \
            self._collect_openapi_info(
                rule,
                func,
                tags=tags,
                summary=summary,
                description=description,
                external_docs=external_docs,
                operation_id=operation_id,
                extra_form=extra_form,
                extra_body=extra_body,
                responses=responses,
                extra_responses=extra_responses,
                deprecated=deprecated,
                security=security,
                servers=servers,
                openapi_extensions=openapi_extensions,
                doc_ui=doc_ui,
                method=HTTPMethod.DELETE
            )

        view_func = self.create_view_func(func, header, cookie, path, query, form, body)
        options.update({"methods": [HTTPMethod.DELETE]})
        self.add_url_rule(rule, view_func=view_func, **options)

        return func

    return decorator

get(rule, *, tags=None, summary=None, description=None, external_docs=None, operation_id=None, extra_form=None, extra_body=None, responses=None, extra_responses=None, deprecated=None, security=None, servers=None, openapi_extensions=None, doc_ui=True, **options) ⚓︎

Decorator for defining a REST API endpoint with the HTTP GET method. More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

Parameters:

Name Type Description Default
rule str

The URL rule string.

required
tags Optional[List[Tag]]

Adds metadata to a single tag.

None
summary Optional[str]

A short summary of what the operation does.

None
description Optional[str]

A verbose explanation of the operation behavior.

None
external_docs Optional[ExternalDocumentation]

Additional external documentation for this operation.

None
operation_id Optional[str]

Unique string used to identify the operation.

None
extra_form Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/form).

None
extra_body Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/json).

None
responses Optional[ResponseDict]

API responses should be either a subclass of BaseModel, a dictionary, or None.

None
extra_responses Optional[Dict[str, dict]]

Deprecated in v3.x. Extra information for responses.

None
deprecated Optional[bool]

Declares this operation to be deprecated.

None
security Optional[List[Dict[str, List[Any]]]]

A declaration of which security mechanisms can be used for this operation.

None
servers Optional[List[Server]]

An alternative server array to service this operation.

None
openapi_extensions Optional[Dict[str, Any]]

Allows extensions to the OpenAPI Schema.

None
doc_ui bool

Declares this operation to be shown. Default to True.

True
Source code in flask_openapi3/scaffold.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def get(
        self,
        rule: str,
        *,
        tags: Optional[List[Tag]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        external_docs: Optional[ExternalDocumentation] = None,
        operation_id: Optional[str] = None,
        extra_form: Optional[ExtraRequestBody] = None,
        extra_body: Optional[ExtraRequestBody] = None,
        responses: Optional[ResponseDict] = None,
        extra_responses: Optional[Dict[str, dict]] = None,
        deprecated: Optional[bool] = None,
        security: Optional[List[Dict[str, List[Any]]]] = None,
        servers: Optional[List[Server]] = None,
        openapi_extensions: Optional[Dict[str, Any]] = None,
        doc_ui: bool = True,
        **options: Any
) -> Callable:
    """
    Decorator for defining a REST API endpoint with the HTTP GET method.
    More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

    Arguments:
        rule: The URL rule string.
        tags: Adds metadata to a single tag.
        summary: A short summary of what the operation does.
        description: A verbose explanation of the operation behavior.
        external_docs: Additional external documentation for this operation.
        operation_id: Unique string used to identify the operation.
        extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
        extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
        responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
        extra_responses: **Deprecated in v3.x**. Extra information for responses.
        deprecated: Declares this operation to be deprecated.
        security: A declaration of which security mechanisms can be used for this operation.
        servers: An alternative server array to service this operation.
        openapi_extensions: Allows extensions to the OpenAPI Schema.
        doc_ui: Declares this operation to be shown. Default to True.
    """

    if extra_form is not None:
        warnings.warn(
            """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_body is not None:
        warnings.warn(
            """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_responses is not None:
        warnings.warn(
            """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
            DeprecationWarning)

    def decorator(func) -> Callable:
        header, cookie, path, query, form, body = \
            self._collect_openapi_info(
                rule,
                func,
                tags=tags,
                summary=summary,
                description=description,
                external_docs=external_docs,
                operation_id=operation_id,
                extra_form=extra_form,
                extra_body=extra_body,
                responses=responses,
                extra_responses=extra_responses,
                deprecated=deprecated,
                security=security,
                servers=servers,
                openapi_extensions=openapi_extensions,
                doc_ui=doc_ui,
                method=HTTPMethod.GET
            )

        view_func = self.create_view_func(func, header, cookie, path, query, form, body)
        options.update({"methods": [HTTPMethod.GET]})
        self.add_url_rule(rule, view_func=view_func, **options)

        return func

    return decorator

patch(rule, *, tags=None, summary=None, description=None, external_docs=None, operation_id=None, extra_form=None, extra_body=None, responses=None, extra_responses=None, deprecated=None, security=None, servers=None, openapi_extensions=None, doc_ui=True, **options) ⚓︎

Decorator for defining a REST API endpoint with the HTTP PATCH method. More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

Parameters:

Name Type Description Default
rule str

The URL rule string.

required
tags Optional[List[Tag]]

Adds metadata to a single tag.

None
summary Optional[str]

A short summary of what the operation does.

None
description Optional[str]

A verbose explanation of the operation behavior.

None
external_docs Optional[ExternalDocumentation]

Additional external documentation for this operation.

None
operation_id Optional[str]

Unique string used to identify the operation.

None
extra_form Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/form).

None
extra_body Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/json).

None
responses Optional[ResponseDict]

API responses should be either a subclass of BaseModel, a dictionary, or None.

None
extra_responses Optional[Dict[str, dict]]

Deprecated in v3.x. Extra information for responses.

None
deprecated Optional[bool]

Declares this operation to be deprecated.

None
security Optional[List[Dict[str, List[Any]]]]

A declaration of which security mechanisms can be used for this operation.

None
servers Optional[List[Server]]

An alternative server array to service this operation.

None
openapi_extensions Optional[Dict[str, Any]]

Allows extensions to the OpenAPI Schema.

None
doc_ui bool

Declares this operation to be shown. Default to True.

True
Source code in flask_openapi3/scaffold.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
def patch(
        self,
        rule: str,
        *,
        tags: Optional[List[Tag]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        external_docs: Optional[ExternalDocumentation] = None,
        operation_id: Optional[str] = None,
        extra_form: Optional[ExtraRequestBody] = None,
        extra_body: Optional[ExtraRequestBody] = None,
        responses: Optional[ResponseDict] = None,
        extra_responses: Optional[Dict[str, dict]] = None,
        deprecated: Optional[bool] = None,
        security: Optional[List[Dict[str, List[Any]]]] = None,
        servers: Optional[List[Server]] = None,
        openapi_extensions: Optional[Dict[str, Any]] = None,
        doc_ui: bool = True,
        **options: Any
) -> Callable:
    """
    Decorator for defining a REST API endpoint with the HTTP PATCH method.
    More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

    Arguments:
        rule: The URL rule string.
        tags: Adds metadata to a single tag.
        summary: A short summary of what the operation does.
        description: A verbose explanation of the operation behavior.
        external_docs: Additional external documentation for this operation.
        operation_id: Unique string used to identify the operation.
        extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
        extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
        responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
        extra_responses: **Deprecated in v3.x**. Extra information for responses.
        deprecated: Declares this operation to be deprecated.
        security: A declaration of which security mechanisms can be used for this operation.
        servers: An alternative server array to service this operation.
        openapi_extensions: Allows extensions to the OpenAPI Schema.
        doc_ui: Declares this operation to be shown. Default to True.
    """
    if extra_form is not None:
        warnings.warn(
            """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_body is not None:
        warnings.warn(
            """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_responses is not None:
        warnings.warn(
            """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
            DeprecationWarning)

    def decorator(func) -> Callable:
        header, cookie, path, query, form, body = \
            self._collect_openapi_info(
                rule,
                func,
                tags=tags,
                summary=summary,
                description=description,
                external_docs=external_docs,
                operation_id=operation_id,
                extra_form=extra_form,
                extra_body=extra_body,
                responses=responses,
                extra_responses=extra_responses,
                deprecated=deprecated,
                security=security,
                servers=servers,
                openapi_extensions=openapi_extensions,
                doc_ui=doc_ui,
                method=HTTPMethod.PATCH
            )

        view_func = self.create_view_func(func, header, cookie, path, query, form, body)
        options.update({"methods": [HTTPMethod.PATCH]})
        self.add_url_rule(rule, view_func=view_func, **options)

        return func

    return decorator

post(rule, *, tags=None, summary=None, description=None, external_docs=None, operation_id=None, extra_form=None, extra_body=None, responses=None, extra_responses=None, deprecated=None, security=None, servers=None, openapi_extensions=None, doc_ui=True, **options) ⚓︎

Decorator for defining a REST API endpoint with the HTTP POST method. More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

Parameters:

Name Type Description Default
rule str

The URL rule string.

required
tags Optional[List[Tag]]

Adds metadata to a single tag.

None
summary Optional[str]

A short summary of what the operation does.

None
description Optional[str]

A verbose explanation of the operation behavior.

None
external_docs Optional[ExternalDocumentation]

Additional external documentation for this operation.

None
operation_id Optional[str]

Unique string used to identify the operation.

None
extra_form Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/form).

None
extra_body Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/json).

None
responses Optional[ResponseDict]

API responses should be either a subclass of BaseModel, a dictionary, or None.

None
extra_responses Optional[Dict[str, dict]]

Deprecated in v3.x. Extra information for responses.

None
deprecated Optional[bool]

Declares this operation to be deprecated.

None
security Optional[List[Dict[str, List[Any]]]]

A declaration of which security mechanisms can be used for this operation.

None
servers Optional[List[Server]]

An alternative server array to service this operation.

None
openapi_extensions Optional[Dict[str, Any]]

Allows extensions to the OpenAPI Schema.

None
doc_ui bool

Declares this operation to be shown. Default to True.

True
Source code in flask_openapi3/scaffold.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def post(
        self,
        rule: str,
        *,
        tags: Optional[List[Tag]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        external_docs: Optional[ExternalDocumentation] = None,
        operation_id: Optional[str] = None,
        extra_form: Optional[ExtraRequestBody] = None,
        extra_body: Optional[ExtraRequestBody] = None,
        responses: Optional[ResponseDict] = None,
        extra_responses: Optional[Dict[str, dict]] = None,
        deprecated: Optional[bool] = None,
        security: Optional[List[Dict[str, List[Any]]]] = None,
        servers: Optional[List[Server]] = None,
        openapi_extensions: Optional[Dict[str, Any]] = None,
        doc_ui: bool = True,
        **options: Any
) -> Callable:
    """
    Decorator for defining a REST API endpoint with the HTTP POST method.
    More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

    Arguments:
        rule: The URL rule string.
        tags: Adds metadata to a single tag.
        summary: A short summary of what the operation does.
        description: A verbose explanation of the operation behavior.
        external_docs: Additional external documentation for this operation.
        operation_id: Unique string used to identify the operation.
        extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
        extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
        responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
        extra_responses: **Deprecated in v3.x**. Extra information for responses.
        deprecated: Declares this operation to be deprecated.
        security: A declaration of which security mechanisms can be used for this operation.
        servers: An alternative server array to service this operation.
        openapi_extensions: Allows extensions to the OpenAPI Schema.
        doc_ui: Declares this operation to be shown. Default to True.
    """
    if extra_form is not None:
        warnings.warn(
            """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_body is not None:
        warnings.warn(
            """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_responses is not None:
        warnings.warn(
            """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
            DeprecationWarning)

    def decorator(func) -> Callable:
        header, cookie, path, query, form, body = \
            self._collect_openapi_info(
                rule,
                func,
                tags=tags,
                summary=summary,
                description=description,
                external_docs=external_docs,
                operation_id=operation_id,
                extra_form=extra_form,
                extra_body=extra_body,
                responses=responses,
                extra_responses=extra_responses,
                deprecated=deprecated,
                security=security,
                servers=servers,
                openapi_extensions=openapi_extensions,
                doc_ui=doc_ui,
                method=HTTPMethod.POST
            )

        view_func = self.create_view_func(func, header, cookie, path, query, form, body)
        options.update({"methods": [HTTPMethod.POST]})
        self.add_url_rule(rule, view_func=view_func, **options)

        return func

    return decorator

put(rule, *, tags=None, summary=None, description=None, external_docs=None, operation_id=None, extra_form=None, extra_body=None, responses=None, extra_responses=None, deprecated=None, security=None, servers=None, openapi_extensions=None, doc_ui=True, **options) ⚓︎

Decorator for defining a REST API endpoint with the HTTP PUT method. More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

Parameters:

Name Type Description Default
rule str

The URL rule string.

required
tags Optional[List[Tag]]

Adds metadata to a single tag.

None
summary Optional[str]

A short summary of what the operation does.

None
description Optional[str]

A verbose explanation of the operation behavior.

None
external_docs Optional[ExternalDocumentation]

Additional external documentation for this operation.

None
operation_id Optional[str]

Unique string used to identify the operation.

None
extra_form Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/form).

None
extra_body Optional[ExtraRequestBody]

Deprecated in v3.x. Extra information describing the request body(application/json).

None
responses Optional[ResponseDict]

API responses should be either a subclass of BaseModel, a dictionary, or None.

None
extra_responses Optional[Dict[str, dict]]

Deprecated in v3.x. Extra information for responses.

None
deprecated Optional[bool]

Declares this operation to be deprecated.

None
security Optional[List[Dict[str, List[Any]]]]

A declaration of which security mechanisms can be used for this operation.

None
servers Optional[List[Server]]

An alternative server array to service this operation.

None
openapi_extensions Optional[Dict[str, Any]]

Allows extensions to the OpenAPI Schema.

None
doc_ui bool

Declares this operation to be shown. Default to True.

True
Source code in flask_openapi3/scaffold.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
def put(
        self,
        rule: str,
        *,
        tags: Optional[List[Tag]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        external_docs: Optional[ExternalDocumentation] = None,
        operation_id: Optional[str] = None,
        extra_form: Optional[ExtraRequestBody] = None,
        extra_body: Optional[ExtraRequestBody] = None,
        responses: Optional[ResponseDict] = None,
        extra_responses: Optional[Dict[str, dict]] = None,
        deprecated: Optional[bool] = None,
        security: Optional[List[Dict[str, List[Any]]]] = None,
        servers: Optional[List[Server]] = None,
        openapi_extensions: Optional[Dict[str, Any]] = None,
        doc_ui: bool = True,
        **options: Any
) -> Callable:
    """
    Decorator for defining a REST API endpoint with the HTTP PUT method.
    More information goto https://spec.openapis.org/oas/v3.0.3#operation-object

    Arguments:
        rule: The URL rule string.
        tags: Adds metadata to a single tag.
        summary: A short summary of what the operation does.
        description: A verbose explanation of the operation behavior.
        external_docs: Additional external documentation for this operation.
        operation_id: Unique string used to identify the operation.
        extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
        extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
        responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
        extra_responses: **Deprecated in v3.x**. Extra information for responses.
        deprecated: Declares this operation to be deprecated.
        security: A declaration of which security mechanisms can be used for this operation.
        servers: An alternative server array to service this operation.
        openapi_extensions: Allows extensions to the OpenAPI Schema.
        doc_ui: Declares this operation to be shown. Default to True.
    """
    if extra_form is not None:
        warnings.warn(
            """`extra_form` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_body is not None:
        warnings.warn(
            """`extra_body` will be deprecated in v3.x, please use `openapi_extra` instead.""",
            DeprecationWarning)
    if extra_responses is not None:
        warnings.warn(
            """`extra_responses` will be deprecated in v3.x, please use `responses` instead.""",
            DeprecationWarning)

    def decorator(func) -> Callable:
        header, cookie, path, query, form, body = \
            self._collect_openapi_info(
                rule,
                func,
                tags=tags,
                summary=summary,
                description=description,
                external_docs=external_docs,
                operation_id=operation_id,
                extra_form=extra_form,
                extra_body=extra_body,
                responses=responses,
                extra_responses=extra_responses,
                deprecated=deprecated,
                security=security,
                servers=servers,
                openapi_extensions=openapi_extensions,
                doc_ui=doc_ui,
                method=HTTPMethod.PUT
            )

        view_func = self.create_view_func(func, header, cookie, path, query, form, body)
        options.update({"methods": [HTTPMethod.PUT]})
        self.add_url_rule(rule, view_func=view_func, **options)

        return func

    return decorator