Skip to content

Commit e80c5ad

Browse files
committed
Markdown documentation
1 parent e5d2559 commit e80c5ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1670
-1489
lines changed

.readthedocs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
33
version: 2
44

5-
# Build documentation in the docs/ directory with Sphinx
6-
sphinx:
7-
configuration: docs/conf.py
5+
# Build documentation with Mkdocs
6+
mkdocs:
7+
configuration: mkdocs.yml
88

99
# Optionally build your docs in additional formats such as PDF and ePub
1010
formats: all

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"sphinx.ext.coverage",
4040
"sphinx.ext.viewcode",
4141
"sphinx_immaterial",
42+
"myst_parser",
4243
]
4344

4445
# Add any paths that contain templates here, relative to this directory.
@@ -103,3 +104,8 @@
103104
# If False, expand all TOC entries
104105
"globaltoc_collapse": False,
105106
}
107+
108+
myst_enable_extensions = [
109+
"deflist",
110+
"colon_fence",
111+
]

docs/contributing.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Contributing
2+
3+
Firstly, thank you all for taking the time to contribute.
4+
5+
The following section describes how you can contribute to the openapi-core project on GitHub.
6+
7+
## Reporting bugs
8+
9+
### Before you report
10+
11+
- Check whether your issue does not already exist in the [Issue tracker](https://github.com/python-openapi/openapi-core/issues).
12+
- Make sure it is not a support request or question better suited for [Discussion board](https://github.com/python-openapi/openapi-core/discussions).
13+
14+
### How to submit a report
15+
16+
- Include clear title.
17+
- Describe your runtime environment with exact versions you use.
18+
- Describe the exact steps which reproduce the problem, including minimal code snippets.
19+
- Describe the behavior you observed after following the steps, pasting console outputs.
20+
- Describe expected behavior to see and why, including links to documentations.
21+
22+
## Code contribution
23+
24+
### Prerequisites
25+
26+
Install [Poetry](https://python-poetry.org) by following the [official installation instructions](https://python-poetry.org/docs/#installation). Optionally (but recommended), configure Poetry to create a virtual environment in a folder named `.venv` within the root directory of the project:
27+
28+
```console
29+
poetry config virtualenvs.in-project true
30+
```
31+
32+
### Setup
33+
34+
To create a development environment and install the runtime and development dependencies, run:
35+
36+
```console
37+
poetry install
38+
```
39+
40+
Then enter the virtual environment created by Poetry:
41+
42+
```console
43+
poetry shell
44+
```
45+
46+
### Static checks
47+
48+
The project uses static checks using fantastic [pre-commit](https://pre-commit.com/). Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit.
49+
50+
To turn on pre-commit checks for commit operations in git, enter:
51+
52+
```console
53+
pre-commit install
54+
```
55+
56+
To run all checks on your staged files, enter:
57+
58+
```console
59+
pre-commit run
60+
```
61+
62+
To run all checks on all files, enter:
63+
64+
```console
65+
pre-commit run --all-files
66+
```
67+
68+
Pre-commit check results are also attached to your PR through integration with Github Action.

docs/contributing.rst

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Format unmarshallers
2+
3+
Based on `format` keyword, openapi-core can also unmarshal values to specific formats.
4+
5+
Openapi-core comes with a set of built-in format unmarshallers, but it's also possible to add custom ones.
6+
7+
Here's an example with the `usdate` format that converts a value to date object:
8+
9+
```{code-block} python
10+
:emphasize-lines: 11
11+
12+
from datetime import datetime
13+
14+
def unmarshal_usdate(value):
15+
return datetime.strptime(value, "%m/%d/%y").date
16+
17+
extra_format_unmarshallers = {
18+
'usdate': unmarshal_usdate,
19+
}
20+
21+
config = Config(
22+
extra_format_unmarshallers=extra_format_unmarshallers,
23+
)
24+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
25+
26+
result = openapi.unmarshal_response(request, response)
27+
```

docs/customizations/extra_format_unmarshallers.rst

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Format validators
2+
3+
OpenAPI defines a `format` keyword that hints at how a value should be interpreted, e.g. a `string` with the type `date` should conform to the RFC 3339 date format.
4+
5+
OpenAPI comes with a set of built-in format validators, but it's also possible to add custom ones.
6+
7+
Here's how you could add support for a `usdate` format that handles dates of the form MM/DD/YYYY:
8+
9+
```{code-block} python
10+
:emphasize-lines: 11
11+
12+
import re
13+
14+
def validate_usdate(value):
15+
return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value))
16+
17+
extra_format_validators = {
18+
'usdate': validate_usdate,
19+
}
20+
21+
config = Config(
22+
extra_format_validators=extra_format_validators,
23+
)
24+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
25+
26+
openapi.validate_response(request, response)
27+
```

docs/customizations/extra_format_validators.rst

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Media type deserializers
2+
3+
OpenAPI comes with a set of built-in media type deserializers such as: `application/json`, `application/xml`, `application/x-www-form-urlencoded` or `multipart/form-data`.
4+
5+
You can also define your own ones. Pass custom defined media type deserializers dictionary with supported mimetypes as a key to `unmarshal_response` function:
6+
7+
```{code-block} python
8+
:emphasize-lines: 11
9+
10+
def protobuf_deserializer(message):
11+
feature = route_guide_pb2.Feature()
12+
feature.ParseFromString(message)
13+
return feature
14+
15+
extra_media_type_deserializers = {
16+
'application/protobuf': protobuf_deserializer,
17+
}
18+
19+
config = Config(
20+
extra_media_type_deserializers=extra_media_type_deserializers,
21+
)
22+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
23+
24+
result = openapi.unmarshal_response(request, response)
25+
```

docs/customizations/extra_media_type_deserializers.rst

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/customizations/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Customizations
2+
3+
OpenAPI accepts `Config` object that allows users to customize the behavior validation and unmarshalling processes.
4+
5+
```{toctree}
6+
:maxdepth: 1
7+
8+
spec_validator_cls
9+
request_validator_cls
10+
response_validator_cls
11+
request_unmarshaller_cls
12+
response_unmarshaller_cls
13+
extra_media_type_deserializers
14+
extra_format_validators
15+
extra_format_unmarshallers
16+
```

docs/customizations/index.rst

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Request unmarshaller
2+
3+
By default, request unmarshaller is selected based on detected specification version.
4+
5+
In order to explicitly validate and unmarshal a:
6+
7+
- OpenAPI 3.0 spec, import `V30RequestUnmarshaller`
8+
- OpenAPI 3.1 spec, import `V31RequestUnmarshaller` or `V31WebhookRequestUnmarshaller`
9+
10+
```{code-block} python
11+
:emphasize-lines: 1,4
12+
13+
from openapi_core import V31RequestUnmarshaller
14+
15+
config = Config(
16+
request_unmarshaller_cls=V31RequestUnmarshaller,
17+
)
18+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
19+
result = openapi.unmarshal_request(request)
20+
```
21+
22+
You can also explicitly import `V3RequestUnmarshaller` which is a shortcut to the latest OpenAPI v3 version.

0 commit comments

Comments
 (0)