From 616021eb915e69565c86ac67dc865246aeaaf129 Mon Sep 17 00:00:00 2001 From: weiyang Date: Wed, 31 Mar 2021 07:37:55 +0800 Subject: [PATCH 01/14] Refine 'RefTo' and 'ContentTypeFormat' (#21) --- openapi_type/custom_types.py | 41 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/openapi_type/custom_types.py b/openapi_type/custom_types.py index a482818..0332b84 100644 --- a/openapi_type/custom_types.py +++ b/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 @@ -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) @@ -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()] @@ -68,7 +53,7 @@ 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]) @@ -76,11 +61,15 @@ def serialize(self, node, appstruct: ContentTypeTag) -> str: 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): @@ -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: From 6e3f2b4ced8bc8b48e984da03fe83df7736dc68b Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:38:43 +0100 Subject: [PATCH 02/14] Release 0.1.0 --- CHANGELOG.rst | 6 ++++++ LICENSE.txt | 2 +- docs/conf.py | 6 +++--- setup.py | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f394fba..ad03d89 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ====== diff --git a/LICENSE.txt b/LICENSE.txt index e055780..fd51c85 100644 --- a/LICENSE.txt +++ b/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 diff --git a/docs/conf.py b/docs/conf.py index e21b4a8..26fa57f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -43,7 +43,7 @@ # 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 @@ -51,9 +51,9 @@ # 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. diff --git a/setup.py b/setup.py index 390e404..6c82d63 100644 --- a/setup.py +++ b/setup.py @@ -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=[ From d8335279b03481da0487d7985d15f730880aa95c Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:47:16 +0100 Subject: [PATCH 03/14] add Python 3.9 to test matrix --- .github/workflows/ci.yml | 2 +- shell.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b181903..29e4530 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/shell.nix b/shell.nix index ad78b44..25d8483 100644 --- a/shell.nix +++ b/shell.nix @@ -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 ` - sha256 = "0bjcdml9vbrx0r0kz9ic48lpnj4ah1cjhqsw7p0ydmz7dvrq702y"; + sha256 = "192bnsjrccvix9kd1cg895alghpdd73hdpis2s03b1p2rn1y2pkp"; }) {} , pyVersion ? "39" , isDevEnv ? true From 92fcfb46e76295d4316c32fa677a0f3526879448 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:49:47 +0100 Subject: [PATCH 04/14] bump test deps versions --- requirements/test.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/test.txt b/requirements/test.txt index f252723..4342918 100644 --- a/requirements/test.txt +++ b/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 From 7068585ba749baa5974455ad379643df7d02f131 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:56:02 +0100 Subject: [PATCH 05/14] replace coveralls setup --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29e4530..74dbdb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,8 @@ jobs: "pip install -e . && pip install -r requirements/test.txt && pip install -r requirements/extras/third_party.txt && make test" - name: Coveralls - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls" + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: python${{ matrix.python-version }} + parallel: true From 58a60e36804615c0f08f3fd965ac0f2b80063d7c Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:58:35 +0100 Subject: [PATCH 06/14] replace coveralls setup --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74dbdb5..0dd188e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,3 +30,4 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: python${{ matrix.python-version }} parallel: true + path-to-lcov: ./.coverage From 350f1c7237887c57d142ee68c0e4e15c26b5ac49 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 21:59:20 +0100 Subject: [PATCH 07/14] replace coveralls setup --- shell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index 25d8483..9a57382 100644 --- a/shell.nix +++ b/shell.nix @@ -15,7 +15,7 @@ let python = pkgs."python${pyVersion}Full"; pythonPkgs = pkgs."python${pyVersion}Packages"; - devLibs = if isDevEnv then [ pythonPkgs.twine pythonPkgs.wheel ] else [ pythonPkgs.coveralls ]; + devLibs = if isDevEnv then [ pythonPkgs.twine pythonPkgs.wheel ] else [ ]; in # Make a new "derivation" that represents our shell From ba227874a13b54e0b6d1005215f9e458f8fb9b8c Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:08:35 +0100 Subject: [PATCH 08/14] try xml format --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dd188e..8fdf4c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: python${{ matrix.python-version }} parallel: true - path-to-lcov: ./.coverage + path-to-lcov: ./coverage.xml diff --git a/Makefile b/Makefile index 7761485..d88ef20 100644 --- a/Makefile +++ b/Makefile @@ -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) From 5b62c47b8e41eb0276ca9264c6098c1fce9d7ebc Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:22:16 +0100 Subject: [PATCH 09/14] revert --- .github/workflows/ci.yml | 25 ++++++++++++++++++------- shell.nix | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fdf4c0..a9d9326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,21 @@ 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 - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - flag-name: python${{ matrix.python-version }} - parallel: true - path-to-lcov: ./coverage.xml + - 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" + + coveralls: + name: Coveralls [finalize] + needs: tests + runs-on: ubuntu-latest + steps: + - name: Coveralls [finalize] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls --finish" diff --git a/shell.nix b/shell.nix index 9a57382..25d8483 100644 --- a/shell.nix +++ b/shell.nix @@ -15,7 +15,7 @@ let python = pkgs."python${pyVersion}Full"; pythonPkgs = pkgs."python${pyVersion}Packages"; - devLibs = if isDevEnv then [ pythonPkgs.twine pythonPkgs.wheel ] else [ ]; + devLibs = if isDevEnv then [ pythonPkgs.twine pythonPkgs.wheel ] else [ pythonPkgs.coveralls ]; in # Make a new "derivation" that represents our shell From 4ca8bc600539a963051e92bef127ccb3b9ca8fb0 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:24:45 +0100 Subject: [PATCH 10/14] revert --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d9326..24a60f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: 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] @@ -41,4 +41,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls --finish" + nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls --service=github --finish" From e36dccebe1b2d6fd78cb0f784a510663f8fadc28 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:27:14 +0100 Subject: [PATCH 11/14] revert --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24a60f5..1a22d3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,10 @@ jobs: needs: tests runs-on: ubuntu-latest steps: + - 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 }} From 7f9956bb0602d6a2b559909126162e21fff3b4e5 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:30:01 +0100 Subject: [PATCH 12/14] revert --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a22d3c..02c1044 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,4 +45,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - nix-shell --argstr pyVersion ${{ matrix.python-version }} --arg isDevEnv false --run "coveralls --service=github --finish" + nix-shell --arg isDevEnv false --run "coveralls --service=github --finish" From 8032506e23ecd8e0f9feb2f433f06b11f3b36e9d Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:33:34 +0100 Subject: [PATCH 13/14] revert --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02c1044..95e5c09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: 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 From f0635d1c574118dfda5c769b9c8a6ae8ea6c000e Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Thu, 29 Apr 2021 22:34:37 +0100 Subject: [PATCH 14/14] revert --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95e5c09..8e50370 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,8 +38,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.4 - with: - submodules: recursive + with: + submodules: recursive - uses: cachix/install-nix-action@v12 with: install_url: https://releases.nixos.org/nix/nix-2.3.10/install