Skip to content

Commit

Permalink
Merge f0635d1 into 5bacb1b
Browse files Browse the repository at this point in the history
  • Loading branch information
avanov committed Apr 29, 2021
2 parents 5bacb1b + f0635d1 commit a6dae28
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 40 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
tests:
strategy:
matrix:
python-version: [ 38 ]
python-version: [ 38, 39 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
Expand All @@ -24,8 +24,28 @@ jobs:
nix-shell --argstr pyVersion ${{ matrix.python-version }} --run \
"pip install -e . && pip install -r requirements/test.txt && pip install -r requirements/extras/third_party.txt && make test"
- name: Coveralls
- name: Coveralls [upload]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: python${{ matrix.python-version }}
COVERALLS_PARALLEL: true
run: |
nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls"
nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls --service=github"
coveralls:
name: Coveralls [finalize]
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
with:
submodules: recursive
- uses: cachix/install-nix-action@v12
with:
install_url: https://releases.nixos.org/nix/nix-2.3.10/install
extra_nix_config: "system-features = benchmark kvm"
- name: Coveralls [finalize]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
nix-shell --arg isDevEnv false --run "coveralls --service=github --finish"
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,12 @@
CHANGELOG
=========

0.1.0
======

* ``ContentTypeFormat`` is redefined as a new type of ``str`` (used to be a strict Enum)
for allowing non-common yet valid type representations.

0.0.19
======

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Maxim Avanov
Copyright (c) 2021 Maxim Avanov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -12,7 +12,7 @@ DIST_DIR := $(PROJECT_ROOT)/dist
PROJECT=openapi_type

test: typecheck
pytest -s --cov=openapi_type $(PROJECT_ROOT)/tests
pytest -s --cov=openapi_type --cov-report xml $(PROJECT_ROOT)/tests

typecheck:
mypy --config-file setup.cfg --package $(PROJECT_NAME)
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Expand Up @@ -43,17 +43,17 @@

# General information about the project.
project = 'openapi-type'
copyright = '2020, Maxim Avanov'
copyright = '2021, Maxim Avanov'
author = 'Maxim Avanov'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.0'
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.0.21'
release = '0.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
41 changes: 17 additions & 24 deletions openapi_type/custom_types.py
@@ -1,5 +1,5 @@
from enum import Enum
from typing import NewType, NamedTuple, Optional, Mapping, Sequence, Any
from typing import NewType, NamedTuple, Optional, Mapping, Sequence, Any, List

import typeit
from inflection import camelize
Expand All @@ -9,24 +9,12 @@
__all__ = (
'TypeGenerator',
'ContentTypeTag',
'ContentTypeFormat',
'Ref',
'EmptyValue',
)


class ContentTypeFormat(Enum):
JSON = 'application/json'
XML = 'application/xml'
TEXT = 'text/plain'
FORM_URLENCODED = 'application/x-www-form-urlencoded'
BINARY_STREAM = 'application/octet-stream'
EVENT_STREAM = 'text/event-stream'
""" server-side events
"""
ANYTHING = '*/*'


ContentTypeFormat = NewType('ContentTypeFormat', str)
MediaTypeCharset = NewType('MediaTypeCharset', str)


Expand All @@ -47,10 +35,7 @@ def deserialize(self, node, cstruct: str) -> ContentTypeTag:
raise error

media_format, *param = tag_str.split(';')
try:
typed_format = ContentTypeFormat(media_format)
except ValueError:
raise Invalid(node, f"Unsupported Media Type format: {media_format}", media_format)
typed_format = ContentTypeFormat(media_format)

if param:
param = [x for x in param[0].split('charset=') if x.strip()]
Expand All @@ -68,19 +53,23 @@ def deserialize(self, node, cstruct: str) -> ContentTypeTag:
def serialize(self, node, appstruct: ContentTypeTag) -> str:
""" Converts ``ContentTypeTag`` back to string value suitable for JSON/YAML
"""
rv = [appstruct.format.value]
rv: List = [appstruct.format]
if appstruct.charset:
rv.extend([';', "charset=", appstruct.charset])

return super().serialize(node, ''.join(rv))


class RefTo(Enum):
SCHEMAS = '#/components/schemas/'
LINKS = '#/components/links/'
PARAMS = '#/components/parameters/'
RESPONSES = '#/components/responses/'
HEADERS = '#/components/headers/'
SCHEMAS = '#/components/schemas/'
LINKS = '#/components/links/'
PARAMS = '#/components/parameters/'
RESPONSES = '#/components/responses/'
HEADERS = '#/components/headers/'
EXAMPLES = '#/components/examples/'
REQUEST_BODIES = '#/components/requestBodies/'
SECURITY_SCHEMES = '#/components/securitySchemes/'
CALLBACKS = '#/components/callbacks/'


class Ref(NamedTuple):
Expand All @@ -96,6 +85,10 @@ class RefSchema(typeit.schema.primitives.Str):
'parameters': RefTo.PARAMS,
'responses': RefTo.RESPONSES,
'headers': RefTo.HEADERS,
'examples': RefTo.EXAMPLES,
'requestBodies': RefTo.REQUEST_BODIES,
'securitySchemes': RefTo.SECURITY_SCHEMES,
'callbacks': RefTo.CALLBACKS,
}

def deserialize(self, node, cstruct: str) -> Ref:
Expand Down
8 changes: 4 additions & 4 deletions requirements/test.txt
@@ -1,6 +1,6 @@
-r ./minimal.txt
pytest>=5.4.1,<6.3
coverage>=5.1,<5.4
pytest-cov>=2.8.1,<2.11
mypy==0.790
PyYAML>=5.3.1,<5.4
coverage>=5.1,<5.6
pytest-cov>=2.8.1,<2.12
mypy==0.812
PyYAML>=5.3.1,<5.5
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -38,7 +38,7 @@ def requirements(at_path: Path):
# ----------------------------

setup(name='openapi-type',
version='0.0.21',
version='0.1.0',
description='OpenAPI Type',
long_description=README,
classifiers=[
Expand Down
6 changes: 3 additions & 3 deletions shell.nix
Expand Up @@ -2,10 +2,10 @@
pkgs ? import (builtins.fetchTarball {
# Descriptive name to make the store path easier to identify
name = "openapi-type-nixpkgs";
# Commit hash for nixos-unstable as of 2019-10-27
url = https://github.com/NixOS/nixpkgs/archive/b67ba0bfcc714453cdeb8d713e35751eb8b4c8f4.tar.gz;
# Commit hash for nixos-unstable as of 2021-04-29
url = https://github.com/NixOS/nixpkgs/archive/f4c4ddae041241dc0c9d5628038826103958fdfc.tar.gz;
# Hash obtained using `nix-prefetch-url --unpack <url>`
sha256 = "0bjcdml9vbrx0r0kz9ic48lpnj4ah1cjhqsw7p0ydmz7dvrq702y";
sha256 = "192bnsjrccvix9kd1cg895alghpdd73hdpis2s03b1p2rn1y2pkp";
}) {}
, pyVersion ? "39"
, isDevEnv ? true
Expand Down

0 comments on commit a6dae28

Please sign in to comment.