Skip to content

Commit 87d9f4b

Browse files
committed
Update README to include OpenAPI info
1 parent 02287a3 commit 87d9f4b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ The `@ValidateParameters()` decorator takes parameters that alter route validati
4747
| Parameter | Type | Default | Description |
4848
|-------------------|----------------------|---------|------------------------------------------------------------------------------------------------------------------------------|
4949
| error_handler | `Optional[Response]` | `None` | Overwrite the output format of generated errors, see [Overwriting Default Errors](#overwriting-default-errors) for more |
50+
| route_deprecated | `bool` | `False` | Marks this Route as deprecated in any generated [API Documentation](#api-documentation) |
51+
| openapi_responses | `Optional[dict]` | `None` | The OpenAPI Responses Object for this route, as a `dict` to be used in any generated [API Documentation](#api-documentation) |
52+
| hide_from_docs | `bool` | `False` | Hide this Route from any generated [API Documentation](#api-documentation) |
5053

5154
#### Overwriting Default Errors
5255
By default, the error messages are returned as a JSON response, with the detailed error in the "error" field. However, this can be edited by passing a custom error function into the `ValidateParameters()` decorator. For example:
@@ -120,7 +123,7 @@ Validation beyond type-checking can be done by passing arguments into the constr
120123
| `datetime_format` | `str` | `datetime.datetime` | Python datetime format string datetime format string ([datetime format codes](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)) |
121124
| `comment` | `str` | All | A string to display as the argument description in any generated documentation |
122125
| `alias` | `str` | All but `FileStorage` | An expected parameter name to receive instead of the function name. |
123-
| `json_schema` | `dict` | `dict` | An expected [JSON Schema](https://json-schema.org) which the dict input must conform to |
126+
| `json_schema` | `dict` | All but `FileStorage` | An expected [JSON Schema](https://json-schema.org) which the dict input must conform to |
124127
| `content_types` | `list[str]` | `FileStorage` | Allowed `Content-Type`s |
125128
| `min_length` | `int` | `FileStorage` | Minimum `Content-Length` for a file |
126129
| `max_length` | `int` | `FileStorage` | Maximum `Content-Length` for a file |
@@ -148,8 +151,10 @@ def is_odd(val: int):
148151
### API Documentation
149152
Using the data provided through parameters, docstrings, and Flask route registrations, Flask Parameter Validation can generate API Documentation in various formats.
150153
To make this easy to use, it comes with a `Blueprint` and the output and configuration options below:
154+
#### OpenAPI 3.1.0
155+
* `FPV_OPENAPI_BASE: dict`: The base [OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object) that will be populated with a generated [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#paths-object). Must be set to enable the blueprints. Alternatively, the standalone Paths Object can be retrieved anytime through the `generate_openapi_paths_object()` method.
151156

152-
#### Format
157+
#### Non-standard Format
153158
* `FPV_DOCS_SITE_NAME: str`: Your site's name, to be displayed in the page title, default: `Site`
154159
* `FPV_DOCS_CUSTOM_BLOCKS: array`: An array of dicts to display as cards at the top of your documentation, with the (optional) keys:
155160
* `title: Optional[str]`: The title of the card
@@ -168,6 +173,7 @@ app.register_blueprint(docs_blueprint)
168173
The default blueprint adds two `GET` routes:
169174
* `/`: HTML Page with Bootstrap CSS and toggleable light/dark mode
170175
* `/json`: Non-standard Format JSON Representation of the generated documentation
176+
* `/openapi`: OpenAPI 3.1.0 (JSON) Representation of the generated documentation
171177

172178
The `/json` route yields a response with the following format:
173179
```json
@@ -224,8 +230,10 @@ Documentation Generated:
224230
If you would like to use your own blueprint, you can get the raw data from the following function:
225231
```py
226232
from flask_parameter_validation.docs_blueprint import get_route_docs
233+
from flask_parameter_validation.docs_blueprint import generate_openapi_paths_object
227234
...
228235
get_route_docs()
236+
generate_openapi_paths_object()
229237
```
230238

231239
###### get_route_docs() return value format
@@ -238,6 +246,10 @@ This method returns an object with the following structure:
238246
"methods": ["HTTPVerb"],
239247
"docstring": "String, unsanitized of HTML Tags",
240248
"decorators": ["@decorator1", "@decorator2(param)"],
249+
"responses": {
250+
"openapi": "3.1.0",
251+
"description": "See [OpenAPI Spec 3.1.0 Responses Object](https://swagger.io/specification/#response-object)"
252+
},
241253
"args": {
242254
"<Subclass of Parameter this route uses>": [
243255
{
@@ -246,7 +258,8 @@ This method returns an object with the following structure:
246258
"loc_args": {
247259
"<Name of argument passed to Parameter Subclass>": "Value passed to Argument",
248260
"<Name of another argument passed to Parameter Subclass>": 0
249-
}
261+
},
262+
"deprecated": "bool, whether this parameter is deprecated (only for Route and Query params)"
250263
}
251264
],
252265
"<Another Subclass of Parameter this route uses>": []

0 commit comments

Comments
 (0)