@@ -20,37 +20,32 @@ pip install drf-openapi-tester
20
20
21
21
## Usage
22
22
23
- First instantiate one or more instances of SchemaTester:
23
+ Instantiate one or more instances of ` SchemaTester ` :
24
24
25
25
``` python
26
26
from openapi_tester import SchemaTester
27
27
28
28
schema_tester = SchemaTester()
29
-
30
-
31
29
```
32
30
33
31
If you are using either [ drf-yasg] ( https://github.com/axnsan12/drf-yasg )
34
32
or [ drf-spectacular] ( https://github.com/tfranzel/drf-spectacular ) this will be auto-detected, and the schema will be
35
- loaded by the SchemaTester automatically. If you are using schema files though, you will need to pass the file path to
36
- the tester:
33
+ loaded by the ` SchemaTester ` automatically.
34
+
35
+ If you are using schema files, you will need to pass the file path:
37
36
38
37
``` python
39
38
from openapi_tester import SchemaTester
40
39
41
40
# path should be a string
42
41
schema_tester = SchemaTester(schema_file_path = " ./schemas/publishedSpecs.yaml" )
43
-
44
-
45
42
```
46
43
47
- Once you instantiate a tester, you can use it to test responses:
44
+ Once you've instantiated a tester, you can use it to test responses:
48
45
49
46
``` python
50
47
from openapi_tester.schema_tester import SchemaTester
51
48
52
- # you need to create at least one instance of SchemaTester.
53
- # you can pass kwargs to it
54
49
schema_tester = SchemaTester()
55
50
56
51
@@ -60,7 +55,7 @@ def test_response_documentation(client):
60
55
schema_tester.validate_response(response = response)
61
56
```
62
57
63
- If you are using the Django testing framework, you can create a base APITestCase that incorporates schema validation:
58
+ If you are using the Django testing framework, you can create a base ` APITestCase ` that incorporates schema validation:
64
59
65
60
``` python
66
61
from rest_framework.response import Response
@@ -131,7 +126,7 @@ def my_test(client):
131
126
132
127
### case_tester
133
128
134
- The case tester argument takes a callable that is used to validate the key casings of both schemas and responses. If
129
+ The case tester argument takes a callable that is used to validate the key case of both schemas and responses. If
135
130
nothing is passed, case validation is skipped.
136
131
137
132
The library currently has 4 built-in case testers:
@@ -141,11 +136,11 @@ The library currently has 4 built-in case testers:
141
136
- ` is_camel_case `
142
137
- ` is_kebab_case `
143
138
144
- You can of course pass your own custom case tester .
139
+ You can use one of these, or your own.
145
140
146
141
### ignore_case
147
142
148
- List of keys to ignore when testing key casing . This setting only applies when case_tester is not ` None ` .
143
+ List of keys to ignore when testing key case . This setting only applies when case_tester is not ` None ` .
149
144
150
145
### validators
151
146
@@ -171,7 +166,7 @@ def my_uuid_4_validator(schema_section: dict, data: Any) -> Optional[str]:
171
166
172
167
### field_key_map
173
168
174
- You can pass an optional dictionary that maps custom url parameter names into values, for cases where this cannot be
169
+ You can pass an optional dictionary that maps custom url parameter names into values, for situations where this cannot be
175
170
inferred by the DRF ` EndpointEnumerator ` . A concrete use case for this option is when
176
171
the [ django i18n locale prefixes] ( https://docs.djangoproject.com/en/3.1/topics/i18n/translation/#language-prefix-in-url-patterns ) .
177
172
@@ -185,10 +180,9 @@ schema_tester = SchemaTester(field_key_map={
185
180
186
181
## Schema Validation
187
182
188
- When the SchemaTester loads a schema, it runs it through
189
- [ OpenAPI Spec validator] ( https://github.com/p1c2u/openapi-spec-validator ) which validates that the schema passes without
190
- specification compliance issues. In case of issues with the schema itself, the validator will raise the appropriate
191
- error.
183
+ When the SchemaTester loads a schema, it parses it using an
184
+ [ OpenAPI spec validator] ( https://github.com/p1c2u/openapi-spec-validator ) . This validates the schema.
185
+ In case of issues with the schema itself, the validator will raise the appropriate error.
192
186
193
187
## Django testing client
194
188
0 commit comments