Skip to content

Commit bb502ed

Browse files
Merge branch 'master' into feature/licensing
2 parents 9f07296 + c86b093 commit bb502ed

File tree

12 files changed

+129
-22
lines changed

12 files changed

+129
-22
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.2
2+
current_version = 0.1.3
33
tag = True
44
tag_name = {new_version}
55
commit = True
@@ -9,4 +9,3 @@ serialize =
99
{major}.{minor}.{patch}
1010

1111
[bumpversion:file:openapi_schema_validator/__init__.py]
12-

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [p1c2u]

.github/workflows/python-publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Publish python packages
5+
6+
on:
7+
workflow_dispatch:
8+
release:
9+
types:
10+
- created
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: [2.7, 3.6]
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install setuptools wheel twine
28+
- name: Build
29+
run: python setup.py sdist bdist_wheel
30+
- name: Publish wheel
31+
env:
32+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
33+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
34+
run: twine upload dist/*.whl
35+
- name: Publish source
36+
env:
37+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
38+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
39+
run: twine upload dist/*.tar.gz || true

.github/workflows/python-test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Test python code
5+
6+
on:
7+
push:
8+
pull_request:
9+
types: [opened, synchronize]
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
17+
fail-fast: false
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
pip install -r requirements_dev.txt
29+
pip install -e .
30+
- name: Test
31+
run: python setup.py test
32+
- name: Upload coverage
33+
uses: codecov/codecov-action@v1

.travis.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ matrix:
66
- python: 3.5
77
- python: 3.6
88
- python: 3.7
9-
dist: xenial
10-
sudo: true
9+
- python: 3.8
10+
- python: 3.9
1111
- python: nightly
1212
- python: pypy3
1313
allow_failures:
@@ -23,11 +23,3 @@ script:
2323
- python setup.py test
2424
after_success:
2525
- codecov
26-
deploy:
27-
provider: pypi
28-
user: p1c2u
29-
password:
30-
secure: mQCKjaqTpkDhTRCSZtdt5d3tOs/d1vc8PDAna5Gr5prMbosq5stG3HdTK3qK5AbfNghclFYZH726zD2i4LdBWmHoA50TJn6mud3k0Byt+fEpnFIHgb8B2hhOQiiG/LxO1X+oRQI+2NL6TQagxJZzSArqaY4p83RAoLNjlf8LpgQu6qjERFkxMaSCrDfDWJ8MBFINMiZ5ZCq3NF8Rclaesv7HKAaYc8591grjouR8FBoVIPG7EWCZP8lp4CVEz6XlBZV8DDmUuhIhqWRkf6jS1zMbd0fUB7iKh2vHDHSWx9kGsxSRCqISDy3ywVUcee6O5M06RwzlpDSML+vuBHYvr8KX5LWSoaOcZfRNjGYIv437t+81Bl1d34GogI/Abm8WxG92KYt5+//6bKk7byck76ZLvuxV/lPtLjg0Caya9zVk/SE0GEa5N+Da04SHJqML88dS9ImbKchOnP1nUb/oUFA8SADFaMonxLbqe2k+PTLymZVTv0apPpiDXKpUF0K1+1WdggDRyr9WFhoBB7KYme6uQLLi78vmDo4gZzG+NvPYoux/VVsbm+upZdqRFL1jX8GGYMu/VbFwN3EHCAH3b6kFZFijZuTgCsIGvMfU2j/tJpLGUJLN8uLJlN88PqPxU4iz7lVKRU29hLwnCWY9yjPdTCZn0gdcZuosv6leNlc=
31-
distributions: sdist bdist_wheel
32-
on:
33-
tags: true

README.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Simple usage
4343

4444
.. code-block:: python
4545
46-
from openapi_schema_validator import OAS30Validator, oas30_format_checker
46+
from openapi_schema_validator import validate
4747
4848
# A sample schema
4949
schema = {
@@ -61,20 +61,36 @@ Simple usage
6161
"minimum": 0,
6262
"nullable": True,
6363
},
64+
"birth-date": {
65+
"type": "string",
66+
"format": "date",
67+
}
6468
},
6569
"additionalProperties": False,
6670
}
6771
68-
validator = OAS30Validator(schema)
6972
# If no exception is raised by validate(), the instance is valid.
70-
validator.validate({"name": "John", "age": 23})
73+
validate({"name": "John", "age": 23}, schema)
7174
72-
validator.validate({"name": "John", "city": "London"})
75+
validate({"name": "John", "city": "London"}, schema)
7376
7477
Traceback (most recent call last):
7578
...
7679
ValidationError: Additional properties are not allowed ('city' was unexpected)
7780
81+
You can also check format for primitive types
82+
83+
.. code-block:: python
84+
85+
from openapi_schema_validator import oas30_format_checker
86+
87+
validate({"name": "John", "birth-date": "-12"}, schema, format_checker=oas30_format_checker)
88+
89+
Traceback (most recent call last):
90+
...
91+
ValidationError: '-12' is not a 'date'
92+
93+
7894
Related projects
7995
################
8096
* `openapi-core <https://github.com/p1c2u/openapi-core>`__

openapi_schema_validator/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from openapi_schema_validator._format import oas30_format_checker
3+
from openapi_schema_validator.shortcuts import validate
34
from openapi_schema_validator.validators import OAS30Validator
45

56
__author__ = 'Artur Maciag'
67
__email__ = '[email protected]'
7-
__version__ = '0.1.2'
8+
__version__ = '0.1.3'
89
__url__ = 'https://github.com/p1c2u/openapi-schema-validator'
910
__license__ = 'BSD 3-Clause License'
1011

11-
__all__ = ['OAS30Validator', 'oas30_format_checker']
12+
__all__ = ['validate', 'OAS30Validator', 'oas30_format_checker']

openapi_schema_validator/_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def is_uuid(instance):
9090
if isinstance(instance, binary_type):
9191
instance = instance.decode()
9292

93-
return text_type(UUID(instance)) == instance
93+
return text_type(UUID(instance)).lower() == instance.lower()
9494

9595

9696
def is_password(instance):

openapi_schema_validator/_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ def readOnly(validator, ro, instance, schema):
7272
return
7373

7474
yield ValidationError(
75-
"Tried to write read-only proparty with %s" % (instance))
75+
"Tried to write read-only property with %s" % (instance))
7676

7777

7878
def writeOnly(validator, wo, instance, schema):
7979
if not validator.read or not wo:
8080
return
8181

8282
yield ValidationError(
83-
"Tried to read write-only proparty with %s" % (instance))
83+
"Tried to read write-only property with %s" % (instance))
8484

8585

8686
def not_implemented(validator, value, instance, schema):

openapi_schema_validator/shortcuts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from jsonschema.exceptions import best_match
2+
3+
from openapi_schema_validator.validators import OAS30Validator
4+
5+
6+
def validate(instance, schema, cls=OAS30Validator, *args, **kwargs):
7+
cls.check_schema(schema)
8+
validator = cls(schema, *args, **kwargs)
9+
error = best_match(validator.iter_errors(instance))
10+
if error is not None:
11+
raise error

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[metadata]
22
name = openapi-schema-validator
3+
description = OpenAPI schema validation for Python
34
long_description = file: README.rst
45
long-description-content-type = text/x-rst; charset=UTF-8
56
keywords = openapi, swagger, schema
@@ -12,6 +13,8 @@ classifiers =
1213
Programming Language :: Python :: 3.5
1314
Programming Language :: Python :: 3.6
1415
Programming Language :: Python :: 3.7
16+
Programming Language :: Python :: 3.8
17+
Programming Language :: Python :: 3.9
1518
Topic :: Software Development :: Libraries
1619

1720
[options]
@@ -24,7 +27,7 @@ setup_requires =
2427
setuptools
2528
install_requires =
2629
isodate
27-
jsonschema
30+
jsonschema>=3.0.0
2831
six
2932
strict_rfc3339
3033
tests_require =

tests/integration/test_validators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,15 @@ def test_string_format_datetime_isodate(self, value):
7272
result = validator.validate(value)
7373

7474
assert result is None
75+
76+
@pytest.mark.parametrize('value', [
77+
'f50ec0b7-f960-400d-91f0-c42a6d44e3d0',
78+
'F50EC0B7-F960-400D-91F0-C42A6D44E3D0',
79+
])
80+
def test_string_uuid(self, value):
81+
schema = {"type": 'string', "format": 'uuid'}
82+
validator = OAS30Validator(schema, format_checker=oas30_format_checker)
83+
84+
result = validator.validate(value)
85+
86+
assert result is None

0 commit comments

Comments
 (0)