Skip to content

Commit f973769

Browse files
committed
Markdown documentation
1 parent 34372f7 commit f973769

Some content is hidden

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

59 files changed

+1686
-1493
lines changed

.github/workflows/build-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ jobs:
4242

4343
- name: Build documentation
4444
run: |
45-
poetry run python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs docs/_build/html -n -W
45+
poetry run python -m mkdocs build --clean --site-dir ./_build/html --config-file mkdocs.yml
4646
4747
- uses: actions/upload-artifact@v4
4848
name: Upload docs as artifact
4949
with:
5050
name: docs-html
51-
path: './docs/_build/html'
51+
path: './_build/html'
5252
if-no-files-found: error

.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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
hide:
3+
- navigation
4+
---
5+
6+
# Contributing
7+
8+
Firstly, thank you all for taking the time to contribute.
9+
10+
The following section describes how you can contribute to the openapi-core project on GitHub.
11+
12+
## Reporting bugs
13+
14+
### Before you report
15+
16+
- Check whether your issue does not already exist in the [Issue tracker](https://github.com/python-openapi/openapi-core/issues).
17+
- Make sure it is not a support request or question better suited for [Discussion board](https://github.com/python-openapi/openapi-core/discussions).
18+
19+
### How to submit a report
20+
21+
- Include clear title.
22+
- Describe your runtime environment with exact versions you use.
23+
- Describe the exact steps which reproduce the problem, including minimal code snippets.
24+
- Describe the behavior you observed after following the steps, pasting console outputs.
25+
- Describe expected behavior to see and why, including links to documentations.
26+
27+
## Code contribution
28+
29+
### Prerequisites
30+
31+
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:
32+
33+
```console
34+
poetry config virtualenvs.in-project true
35+
```
36+
37+
### Setup
38+
39+
To create a development environment and install the runtime and development dependencies, run:
40+
41+
```console
42+
poetry install
43+
```
44+
45+
Then enter the virtual environment created by Poetry:
46+
47+
```console
48+
poetry shell
49+
```
50+
51+
### Static checks
52+
53+
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.
54+
55+
To turn on pre-commit checks for commit operations in git, enter:
56+
57+
```console
58+
pre-commit install
59+
```
60+
61+
To run all checks on your staged files, enter:
62+
63+
```console
64+
pre-commit run
65+
```
66+
67+
To run all checks on all files, enter:
68+
69+
```console
70+
pre-commit run --all-files
71+
```
72+
73+
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
``` python hl_lines="11"
10+
11+
from datetime import datetime
12+
13+
def unmarshal_usdate(value):
14+
return datetime.strptime(value, "%m/%d/%y").date
15+
16+
extra_format_unmarshallers = {
17+
'usdate': unmarshal_usdate,
18+
}
19+
20+
config = Config(
21+
extra_format_unmarshallers=extra_format_unmarshallers,
22+
)
23+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
24+
25+
result = openapi.unmarshal_response(request, response)
26+
```

docs/customizations/extra_format_unmarshallers.rst

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
``` python hl_lines="11"
10+
11+
import re
12+
13+
def validate_usdate(value):
14+
return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value))
15+
16+
extra_format_validators = {
17+
'usdate': validate_usdate,
18+
}
19+
20+
config = Config(
21+
extra_format_validators=extra_format_validators,
22+
)
23+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
24+
25+
openapi.validate_response(request, response)
26+
```

docs/customizations/extra_format_validators.rst

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
``` python hl_lines="11"
8+
def protobuf_deserializer(message):
9+
feature = route_guide_pb2.Feature()
10+
feature.ParseFromString(message)
11+
return feature
12+
13+
extra_media_type_deserializers = {
14+
'application/protobuf': protobuf_deserializer,
15+
}
16+
17+
config = Config(
18+
extra_media_type_deserializers=extra_media_type_deserializers,
19+
)
20+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
21+
22+
result = openapi.unmarshal_response(request, response)
23+
```

docs/customizations/extra_media_type_deserializers.rst

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

docs/customizations/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Customizations
2+
3+
OpenAPI accepts `Config` object that allows users to customize the behavior validation and unmarshalling processes.

docs/customizations/index.rst

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
``` python hl_lines="1 4"
11+
from openapi_core import V31RequestUnmarshaller
12+
13+
config = Config(
14+
request_unmarshaller_cls=V31RequestUnmarshaller,
15+
)
16+
openapi = OpenAPI.from_file_path('openapi.json', config=config)
17+
result = openapi.unmarshal_request(request)
18+
```
19+
20+
You can also explicitly import `V3RequestUnmarshaller` which is a shortcut to the latest OpenAPI v3 version.

0 commit comments

Comments
 (0)