vedro-spec-validator-beta 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. vedro_spec_validator_beta-0.4.0/LICENSE +201 -0
  2. vedro_spec_validator_beta-0.4.0/PKG-INFO +208 -0
  3. vedro_spec_validator_beta-0.4.0/README.md +176 -0
  4. vedro_spec_validator_beta-0.4.0/setup.cfg +17 -0
  5. vedro_spec_validator_beta-0.4.0/setup.py +34 -0
  6. vedro_spec_validator_beta-0.4.0/tests/__init__.py +1 -0
  7. vedro_spec_validator_beta-0.4.0/tests/unittest/__init__.py +1 -0
  8. vedro_spec_validator_beta-0.4.0/tests/unittest/jj_spec_validator/__init__.py +1 -0
  9. vedro_spec_validator_beta-0.4.0/tests/unittest/jj_spec_validator/test_output.py +106 -0
  10. vedro_spec_validator_beta-0.4.0/tests/unittest/jj_spec_validator/test_spec.py +638 -0
  11. vedro_spec_validator_beta-0.4.0/tests/unittest/jj_spec_validator/test_validate_spec.py +233 -0
  12. vedro_spec_validator_beta-0.4.0/tests/unittest/jj_spec_validator/test_validator.py +383 -0
  13. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/__init__.py +6 -0
  14. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/__version__.py +1 -0
  15. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/_spec_validator.py +23 -0
  16. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/_spec_validator_plugin.py +163 -0
  17. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/__init__.py +4 -0
  18. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/_config.py +22 -0
  19. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/cli.py +42 -0
  20. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/output.py +13 -0
  21. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/spec.py +145 -0
  22. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/utils/__init__.py +6 -0
  23. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/utils/_cacheir.py +45 -0
  24. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/utils/_common.py +31 -0
  25. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/utils/_refiner.py +99 -0
  26. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/utils/_spec_matcher.py +142 -0
  27. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/validate_spec.py +122 -0
  28. vedro_spec_validator_beta-0.4.0/vedro_spec_validator/jj_spec_validator/validator.py +132 -0
  29. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/PKG-INFO +208 -0
  30. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/SOURCES.txt +33 -0
  31. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/dependency_links.txt +1 -0
  32. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/entry_points.txt +2 -0
  33. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/requires.txt +6 -0
  34. vedro_spec_validator_beta-0.4.0/vedro_spec_validator_beta.egg-info/top_level.txt +2 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: vedro-spec-validator-beta
3
+ Version: 0.4.0
4
+ Summary: Vedro Spec Validator plugin
5
+ Home-page: https://github.com/Maestoz/vedro-spec-validator
6
+ Author: Sam Roz
7
+ Author-email: rolez777@gmail.com
8
+ License: Apache-2.0
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: vedro<2.0,>=1.10
16
+ Requires-Dist: httpx<1.0.0,>=0.27.0
17
+ Requires-Dist: jj<3.0.0,>=2.11.0
18
+ Requires-Dist: schemax<3.0.0,>=2.3.0
19
+ Requires-Dist: d42<3.0.0,>=2.0.0
20
+ Requires-Dist: click<9.0.0,>=8.0.0
21
+ Dynamic: author
22
+ Dynamic: author-email
23
+ Dynamic: classifier
24
+ Dynamic: description
25
+ Dynamic: description-content-type
26
+ Dynamic: home-page
27
+ Dynamic: license
28
+ Dynamic: license-file
29
+ Dynamic: requires-dist
30
+ Dynamic: requires-python
31
+ Dynamic: summary
32
+
33
+ [vedro-spec-validator](https://pypi.org/project/vedro-spec-validator/) is a [Vedro](https://vedro.io) plugin that allows to validate mocks via OpenAPI spec/docs.
34
+
35
+ ### Version Compatibility Notice
36
+
37
+ - For versions of this package **0.1.0 and later**, only version 2 of the [`d42`](https://github.com/d42-schemas/d42) package is compatible.
38
+
39
+
40
+ ## Installation
41
+
42
+ <details open>
43
+ <summary>Quick</summary>
44
+ <p>
45
+
46
+ For a quick installation, you can use a plugin manager as follows:
47
+
48
+ ```shell
49
+ $ vedro plugin install vedro-spec-validator
50
+ ```
51
+
52
+ </p>
53
+ </details>
54
+
55
+ <details>
56
+ <summary>Manual</summary>
57
+ <p>
58
+
59
+ To install manually, follow these steps:
60
+
61
+ 1. Install the package using pip:
62
+
63
+ ```shell
64
+ $ pip3 install vedro-spec-validator
65
+ ```
66
+
67
+ 2. Next, activate the plugin in your `vedro.cfg.py` configuration file:
68
+
69
+ ```python
70
+ # ./vedro.cfg.py
71
+ import vedro
72
+ import vedro_spec_validator
73
+
74
+ class Config(vedro.Config):
75
+
76
+ class Plugins(vedro.Config.Plugins):
77
+
78
+ class SpecValidator(vedro_spec_validator.SpecValidator):
79
+ enabled = True
80
+ ```
81
+
82
+ </p>
83
+ </details>
84
+
85
+ ## Usage
86
+
87
+ Decorate your [mocked](https://pypi.org/project/jj/) function with `@validate_spec()`, providing a link to a YAML or JSON OpenAPI spec.
88
+ ```python
89
+ import jj
90
+ from jj.mock import mocked
91
+ from vedro_spec_validator import validate_spec
92
+
93
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml")
94
+ async def your_mocked_function():
95
+ matcher = jj.match("GET", "/users")
96
+ response = jj.Response(status=200, json=[])
97
+
98
+ mock = await mocked(matcher, response)
99
+ ```
100
+ ### Keys
101
+
102
+ 1. The `is_strict` key allows you to choose between strict and non-strict comparison. Non-strict comparison (`False` by default) allows you to mock only some fields from the spec, even if they are required. Strict validation (`True`) requires you to mock all required fields from the spec.
103
+
104
+ Example OpenAPI spec with required fields:
105
+ ```
106
+ openapi: 3.0.0
107
+ paths:
108
+ /user:
109
+ get:
110
+ ...
111
+ properties:
112
+ user_name:
113
+ type: string
114
+ email:
115
+ type: string
116
+ age:
117
+ type: integer
118
+ required:
119
+ - user_name
120
+ - email
121
+ - age
122
+ ```
123
+ With `is_strict=True`:
124
+ ```python
125
+ from vedro_spec_validator import validate_spec
126
+
127
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_strict=True)
128
+ async def your_mocked_function():
129
+ matcher = jj.match("GET", "/user")
130
+ payload = {
131
+ "user_name": "Foo",
132
+ "email": "test@test.com",
133
+ "age": 30 # All required fields from the spec must be present
134
+ }
135
+ response = jj.Response(json=payload)
136
+ return await mocked(matcher, response)
137
+ ```
138
+ With `is_strict=False`:
139
+ ```python
140
+ from vedro_spec_validator import validate_spec
141
+
142
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_strict=False)
143
+ async def your_mocked_function():
144
+ matcher = jj.match("GET", "/user")
145
+ payload = {
146
+ "user_name": "Foo" # Required fields like "email" and "age" can be omitted
147
+ }
148
+ response = jj.Response(json=payload)
149
+ return await mocked(matcher, response)
150
+ ```
151
+
152
+
153
+ 2. The `prefix` key allows you to specify a path prefix that should be removed from the mock function's paths before they are matched against the OpenAPI spec.
154
+ ```python
155
+ from vedro_spec_validator import validate_spec
156
+
157
+
158
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", prefix='/__mocked_api__') # Goes to validate `/user` instead of `/__mocked_api__/user`
159
+ async def your_mocked_function():
160
+ matcher = jj.match("GET", "/__mocked_api__/user")
161
+ # The prefix is removed, so the actual path matched against the OpenAPI spec is `/user`
162
+ ...
163
+ ```
164
+
165
+ 3. The `is_raise_error` key allows you to control whether an error should be raised when a validation mismatch occurs. By default (`False`), no exception is raised, but mismatches will be logged to a file.
166
+
167
+ With `is_raise_error=False`:
168
+ ```python
169
+ from vedro_spec_validator import validate_spec
170
+
171
+
172
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_raise_error=False)
173
+ async def your_mocked_function():
174
+ ...
175
+ ```
176
+ Output will be written to a file:
177
+ ```text
178
+ # /spec_validator/validation_results/your_mocked_function/scenarios/path/to/test/test_scenario.py.txt
179
+
180
+ subject: scenario subject
181
+ valera.ValidationException
182
+ - ... # missmatches
183
+ ```
184
+
185
+ With `is_raise_error=True`:
186
+ ```python
187
+ from vedro_spec_validator import validate_spec
188
+
189
+
190
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_raise_error=True)
191
+ async def your_mocked_function():
192
+ ...
193
+ ```
194
+
195
+ An exception will be raised on the first validation error, causing the test to fail with the following trace:
196
+ ```text
197
+ ValidationException: There are some mismatches in your_mocked_function:
198
+ valera.ValidationException
199
+ - ... # missmatches
200
+
201
+
202
+ # --seed ...
203
+ # 1 scenario, 0 passed, 1 failed, 0 skipped (2.35s)
204
+
205
+ Process finished with exit code 1
206
+ ```
207
+
208
+ 4. The `force_strict` key enforces strict validation against the OpenAPI spec, treating all fields as required, even if they are marked as optional in the spec. This is useful in cases where the specification accidentally marks all fields as optional. `False` by default.
@@ -0,0 +1,176 @@
1
+ [vedro-spec-validator](https://pypi.org/project/vedro-spec-validator/) is a [Vedro](https://vedro.io) plugin that allows to validate mocks via OpenAPI spec/docs.
2
+
3
+ ### Version Compatibility Notice
4
+
5
+ - For versions of this package **0.1.0 and later**, only version 2 of the [`d42`](https://github.com/d42-schemas/d42) package is compatible.
6
+
7
+
8
+ ## Installation
9
+
10
+ <details open>
11
+ <summary>Quick</summary>
12
+ <p>
13
+
14
+ For a quick installation, you can use a plugin manager as follows:
15
+
16
+ ```shell
17
+ $ vedro plugin install vedro-spec-validator
18
+ ```
19
+
20
+ </p>
21
+ </details>
22
+
23
+ <details>
24
+ <summary>Manual</summary>
25
+ <p>
26
+
27
+ To install manually, follow these steps:
28
+
29
+ 1. Install the package using pip:
30
+
31
+ ```shell
32
+ $ pip3 install vedro-spec-validator
33
+ ```
34
+
35
+ 2. Next, activate the plugin in your `vedro.cfg.py` configuration file:
36
+
37
+ ```python
38
+ # ./vedro.cfg.py
39
+ import vedro
40
+ import vedro_spec_validator
41
+
42
+ class Config(vedro.Config):
43
+
44
+ class Plugins(vedro.Config.Plugins):
45
+
46
+ class SpecValidator(vedro_spec_validator.SpecValidator):
47
+ enabled = True
48
+ ```
49
+
50
+ </p>
51
+ </details>
52
+
53
+ ## Usage
54
+
55
+ Decorate your [mocked](https://pypi.org/project/jj/) function with `@validate_spec()`, providing a link to a YAML or JSON OpenAPI spec.
56
+ ```python
57
+ import jj
58
+ from jj.mock import mocked
59
+ from vedro_spec_validator import validate_spec
60
+
61
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml")
62
+ async def your_mocked_function():
63
+ matcher = jj.match("GET", "/users")
64
+ response = jj.Response(status=200, json=[])
65
+
66
+ mock = await mocked(matcher, response)
67
+ ```
68
+ ### Keys
69
+
70
+ 1. The `is_strict` key allows you to choose between strict and non-strict comparison. Non-strict comparison (`False` by default) allows you to mock only some fields from the spec, even if they are required. Strict validation (`True`) requires you to mock all required fields from the spec.
71
+
72
+ Example OpenAPI spec with required fields:
73
+ ```
74
+ openapi: 3.0.0
75
+ paths:
76
+ /user:
77
+ get:
78
+ ...
79
+ properties:
80
+ user_name:
81
+ type: string
82
+ email:
83
+ type: string
84
+ age:
85
+ type: integer
86
+ required:
87
+ - user_name
88
+ - email
89
+ - age
90
+ ```
91
+ With `is_strict=True`:
92
+ ```python
93
+ from vedro_spec_validator import validate_spec
94
+
95
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_strict=True)
96
+ async def your_mocked_function():
97
+ matcher = jj.match("GET", "/user")
98
+ payload = {
99
+ "user_name": "Foo",
100
+ "email": "test@test.com",
101
+ "age": 30 # All required fields from the spec must be present
102
+ }
103
+ response = jj.Response(json=payload)
104
+ return await mocked(matcher, response)
105
+ ```
106
+ With `is_strict=False`:
107
+ ```python
108
+ from vedro_spec_validator import validate_spec
109
+
110
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_strict=False)
111
+ async def your_mocked_function():
112
+ matcher = jj.match("GET", "/user")
113
+ payload = {
114
+ "user_name": "Foo" # Required fields like "email" and "age" can be omitted
115
+ }
116
+ response = jj.Response(json=payload)
117
+ return await mocked(matcher, response)
118
+ ```
119
+
120
+
121
+ 2. The `prefix` key allows you to specify a path prefix that should be removed from the mock function's paths before they are matched against the OpenAPI spec.
122
+ ```python
123
+ from vedro_spec_validator import validate_spec
124
+
125
+
126
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", prefix='/__mocked_api__') # Goes to validate `/user` instead of `/__mocked_api__/user`
127
+ async def your_mocked_function():
128
+ matcher = jj.match("GET", "/__mocked_api__/user")
129
+ # The prefix is removed, so the actual path matched against the OpenAPI spec is `/user`
130
+ ...
131
+ ```
132
+
133
+ 3. The `is_raise_error` key allows you to control whether an error should be raised when a validation mismatch occurs. By default (`False`), no exception is raised, but mismatches will be logged to a file.
134
+
135
+ With `is_raise_error=False`:
136
+ ```python
137
+ from vedro_spec_validator import validate_spec
138
+
139
+
140
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_raise_error=False)
141
+ async def your_mocked_function():
142
+ ...
143
+ ```
144
+ Output will be written to a file:
145
+ ```text
146
+ # /spec_validator/validation_results/your_mocked_function/scenarios/path/to/test/test_scenario.py.txt
147
+
148
+ subject: scenario subject
149
+ valera.ValidationException
150
+ - ... # missmatches
151
+ ```
152
+
153
+ With `is_raise_error=True`:
154
+ ```python
155
+ from vedro_spec_validator import validate_spec
156
+
157
+
158
+ @validate_spec(spec_link="http://example.com/api/users/spec.yml", is_raise_error=True)
159
+ async def your_mocked_function():
160
+ ...
161
+ ```
162
+
163
+ An exception will be raised on the first validation error, causing the test to fail with the following trace:
164
+ ```text
165
+ ValidationException: There are some mismatches in your_mocked_function:
166
+ valera.ValidationException
167
+ - ... # missmatches
168
+
169
+
170
+ # --seed ...
171
+ # 1 scenario, 0 passed, 1 failed, 0 skipped (2.35s)
172
+
173
+ Process finished with exit code 1
174
+ ```
175
+
176
+ 4. The `force_strict` key enforces strict validation against the OpenAPI spec, treating all fields as required, even if they are marked as optional in the spec. This is useful in cases where the specification accidentally marks all fields as optional. `False` by default.
@@ -0,0 +1,17 @@
1
+ [isort]
2
+ skip = .vedro,.venv,venv,__pycache__
3
+ multi_line_output = 3
4
+ include_trailing_comma = true
5
+ line_length = 119
6
+
7
+ [autoflake]
8
+ in_place = true
9
+ recursive = true
10
+ remove_all_unused_imports = true
11
+ ignore_init_module_imports = true
12
+ ignore_pass_after_docstring = true
13
+
14
+ [egg_info]
15
+ tag_build =
16
+ tag_date = 0
17
+
@@ -0,0 +1,34 @@
1
+ from setuptools import find_packages, setup
2
+
3
+ from vedro_spec_validator.__version__ import __version__
4
+
5
+
6
+ def find_required():
7
+ with open("requirements.txt") as f:
8
+ return f.read().splitlines()
9
+
10
+
11
+ setup(
12
+ name="vedro-spec-validator-beta",
13
+ version=__version__,
14
+ description="Vedro Spec Validator plugin",
15
+ long_description=open("README.md").read(),
16
+ long_description_content_type="text/markdown",
17
+ author="Sam Roz",
18
+ author_email="rolez777@gmail.com",
19
+ python_requires=">=3.10",
20
+ url="https://github.com/Maestoz/vedro-spec-validator",
21
+ license="Apache-2.0",
22
+ packages=find_packages(),
23
+ install_requires=find_required(),
24
+ entry_points={
25
+ 'console_scripts': [
26
+ 'vedro-spec-cache=vedro_spec_validator.jj_spec_validator.cli:cache_specs',
27
+ ],
28
+ },
29
+ classifiers=[
30
+ "License :: OSI Approved :: Apache Software License",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ ]
34
+ )
@@ -0,0 +1 @@
1
+ """Tests package."""
@@ -0,0 +1 @@
1
+ """Unittest package."""
@@ -0,0 +1 @@
1
+ """JJ Spec Validator unittest package."""