Skip to content

Commit fe31fa6

Browse files
committed
Add JSON Schema documentation to README
1 parent d181b42 commit fe31fa6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The validation on files are different to the others, but file input can still be
6666
* datetime.datetime
6767
* datetime.date
6868
* datetime.time
69+
* dict
6970

7071
### Validation
7172
All parameters can have default values, and automatic validation.
@@ -84,6 +85,7 @@ All parameters can have default values, and automatic validation.
8485
* datetime_format: str, datetime format string ([datetime format codes](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes))
8586
* comment: str, A string to display as the argument description in generated documentation (if used)
8687
* alias: str, An expected parameter name instead of the function name. See `access_type` example for clarification.
88+
* json_schema: dict, An expected [JSON Schema](https://json-schema.org) which the dict input must conform to
8789

8890
`File` has the following options:
8991
* content_types: array of strings, an array of allowed content types.
@@ -221,6 +223,29 @@ This method returns an object with the following structure:
221223
]
222224
```
223225

226+
### JSON Schema Validation
227+
An example of the [JSON Schema](https://json-schema.org) validation is provided below:
228+
```python
229+
json_schema = {
230+
"type": "object",
231+
"required": ["user_id", "first_name", "last_name", "tags"],
232+
"properties": {
233+
"user_id": {"type": "integer"},
234+
"first_name": {"type": "string"},
235+
"last_name": {"type": "string"},
236+
"tags": {
237+
"type": "array",
238+
"items": {"type": "string"}
239+
}
240+
}
241+
}
242+
243+
@api.get("/json_schema_example")
244+
@ValidateParameters()
245+
def json_schema(data: dict = Json(json_schema=json_schema)):
246+
return jsonify({"data": data})
247+
```
248+
224249
## Contributions
225250
Many thanks to all those who have made contributions to the project:
226251
* [d3-steichman](https://github.com/d3-steichman): API documentation, custom error handling, datetime validation and bug fixes

0 commit comments

Comments
 (0)