diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 20cddf5..ac1da0c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,12 +8,12 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set up Python 3.13 - uses: actions/setup-python@v4 + - name: Set up Python 3.14 + uses: actions/setup-python@v6 with: - python-version: '3.13' + python-version: '3.14' - name: Run pre-commit run: | @@ -24,14 +24,14 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} @@ -47,12 +47,12 @@ jobs: docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set up Python 3.13 - uses: actions/setup-python@v4 + - name: Set up Python 3.14 + uses: actions/setup-python@v6 with: - python-version: '3.13' + python-version: '3.14' - name: Run sphinx run: | @@ -63,12 +63,12 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - name: Set up Python 3.13 - uses: actions/setup-python@v4 + - name: Set up Python 3.14 + uses: actions/setup-python@v6 with: - python-version: '3.13' + python-version: '3.14' - name: Prepare artifacts run: | diff --git a/.gitmodules b/.gitmodules index f2756f8..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "OpenAPI-Specification"] - path = tests/OpenAPI-Specification - url = https://github.com/OAI/OpenAPI-Specification.git diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f714d24..93111ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,14 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace + exclude: 'tests/examples' - id: end-of-file-fixer exclude: > (?x)( - tests/renderers/httpdomain/rendered + tests/renderers/httpdomain/rendered | + tests/examples/ ) - id: check-docstring-first - id: check-json @@ -14,7 +16,7 @@ repos: - id: debug-statements - repo: https://github.com/psf/black - rev: 24.10.0 + rev: 26.1.0 hooks: - id: black args: [--line-length=88, --target-version=py35] @@ -46,6 +48,6 @@ repos: ) - repo: https://github.com/pycqa/flake8 - rev: 7.1.1 + rev: 7.3.0 hooks: - id: flake8 diff --git a/docs/conf.py b/docs/conf.py index 5797077..e948913 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,4 @@ pygments_style = "default" if not os.environ.get("READTHEDOCS") == "True": - import sphinx_rtd_theme - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a4f8b24 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,53 @@ +[build-system] +requires = ["setuptools>=64.0.0", "setuptools_scm>=8.0.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "sphinxcontrib-openapi" +description = "OpenAPI (fka Swagger) spec renderer for Sphinx" +readme = "README.rst" +license = "BSD-3-Clause" +authors = [ + {name = "Ihor Kalnytskyi", email = "ihor@kalnytskyi.com"}, +] +keywords = ["sphinx", "openapi", "swagger", "rest", "api", "renderer", "docs"] +classifiers = [ + "Topic :: Documentation", + "Topic :: Documentation :: Sphinx", + "Environment :: Console", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Framework :: Setuptools Plugin", + "Framework :: Sphinx", + "Framework :: Sphinx :: Extension", +] +requires-python = ">=3.10" +dependencies = [ + "sphinx >= 2.0", + "sphinxcontrib-httpdomain >= 1.5.0", + "PyYAML >= 3.12", + "jsonschema >= 2.5.1", + "sphinx-mdinclude >= 0.5.2", + "picobox >= 2.2", + "deepmerge >= 0.1", +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/sphinx-contrib/openapi" +Documentation = "https://sphinxcontrib-openapi.readthedocs.io/" +Source = "https://github.com/sphinx-contrib/openapi" +Bugs = "https://github.com/sphinx-contrib/openapi/issues" + +[tool.setuptools] +zip-safe = false +include-package-data = true + +[tool.setuptools.packages.find] +include = ["sphinxcontrib.*"] + +[tool.setuptools_scm] diff --git a/setup.py b/setup.py deleted file mode 100755 index d5bf738..0000000 --- a/setup.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python - -import os - -from setuptools import setup, find_namespace_packages - - -here = os.path.dirname(__file__) - -with open(os.path.join(here, "README.rst"), "r", encoding="utf-8") as f: - long_description = f.read() - - -setup( - name="sphinxcontrib-openapi", - description="OpenAPI (fka Swagger) spec renderer for Sphinx", - long_description=long_description, - license="BSD", - url="https://github.com/sphinx-contrib/openapi", - keywords="sphinx openapi swagger rest api renderer docs", - author="Ihor Kalnytskyi", - author_email="ihor@kalnytskyi.com", - packages=find_namespace_packages(include=["sphinxcontrib.*"]), - include_package_data=True, - zip_safe=False, - use_scm_version={"root": here}, - setup_requires=["setuptools_scm >= 1.15"], - install_requires=[ - "sphinx >= 2.0", - "sphinxcontrib-httpdomain >= 1.5.0", - "PyYAML >= 3.12", - "jsonschema >= 2.5.1", - "sphinx-mdinclude >= 0.5.2", - "picobox >= 2.2", - "deepmerge >= 0.1", - ], - project_urls={ - "Documentation": "https://sphinxcontrib-openapi.readthedocs.io/", - "Source": "https://github.com/sphinx-contrib/openapi", - "Bugs": "https://github.com/sphinx-contrib/openapi/issues", - }, - classifiers=[ - "Topic :: Documentation", - "Topic :: Documentation :: Sphinx", - "License :: OSI Approved :: BSD License", - "Environment :: Console", - "Intended Audience :: Developers", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: Implementation :: CPython", - "Framework :: Setuptools Plugin", - "Framework :: Sphinx", - "Framework :: Sphinx :: Extension", - ], - python_requires=">=3.9", -) diff --git a/sphinxcontrib/openapi/_lib2to3.py b/sphinxcontrib/openapi/_lib2to3.py index 80b79a6..273470f 100644 --- a/sphinxcontrib/openapi/_lib2to3.py +++ b/sphinxcontrib/openapi/_lib2to3.py @@ -5,7 +5,6 @@ import picobox - __all__ = [ "convert", ] diff --git a/sphinxcontrib/openapi/openapi31.py b/sphinxcontrib/openapi/openapi31.py index a565a6b..0e8cba7 100644 --- a/sphinxcontrib/openapi/openapi31.py +++ b/sphinxcontrib/openapi/openapi31.py @@ -1,11 +1,11 @@ """ - sphinxcontrib.openapi.openapi31 - ------------------------------- +sphinxcontrib.openapi.openapi31 +------------------------------- - The OpenAPI 3.1 spec renderer. Based on ``sphinxcontrib-httpdomain``. +The OpenAPI 3.1 spec renderer. Based on ``sphinxcontrib-httpdomain``. - :copyright: (c) 2016, Ihor Kalnytskyi. - :license: BSD, see LICENSE for details. +:copyright: (c) 2016, Ihor Kalnytskyi. +:license: BSD, see LICENSE for details. """ import copy @@ -24,7 +24,6 @@ from sphinxcontrib.openapi import utils - LOG = logging.getLogger(__name__) # Based on the spec: @@ -341,13 +340,21 @@ def _get_type_from_schema(schema): request_content = properties.get("requestBody", {}).get("content", {}) if request_content and "application/json" in request_content: schema = request_content["application/json"]["schema"] - req_properties = json.dumps( - schema["properties"], indent=2, separators=(",", ":") - ) + yield "{indent}**Request body:**".format(**locals()) yield "" yield "{indent}.. sourcecode:: json".format(**locals()) yield "" + + if schema["type"] == "object": + # if it's an object, focus on the properties of that object + req_properties = json.dumps( + schema["properties"], indent=2, separators=(",", ":") + ) + else: + # if it's another type, dump the whole thing + req_properties = json.dumps(schema, indent=2, separators=(",", ":")) + for line in req_properties.splitlines(): # yield indent + line yield "{indent}{indent}{line}".format(**locals()) diff --git a/sphinxcontrib/openapi/renderers/__init__.py b/sphinxcontrib/openapi/renderers/__init__.py index 4ad75e4..50ba599 100644 --- a/sphinxcontrib/openapi/renderers/__init__.py +++ b/sphinxcontrib/openapi/renderers/__init__.py @@ -4,7 +4,6 @@ from ._httpdomain_old import HttpdomainOldRenderer from ._httpdomain import HttpdomainRenderer - __all__ = [ "abc", "HttpdomainOldRenderer", diff --git a/sphinxcontrib/openapi/schema_utils.py b/sphinxcontrib/openapi/schema_utils.py index 2078244..eefb5b8 100644 --- a/sphinxcontrib/openapi/schema_utils.py +++ b/sphinxcontrib/openapi/schema_utils.py @@ -2,7 +2,6 @@ from io import StringIO - _DEFAULT_EXAMPLES = { "string": "string", "integer": 1, diff --git a/tests/OpenAPI-Specification b/tests/OpenAPI-Specification deleted file mode 160000 index 69d8b79..0000000 --- a/tests/OpenAPI-Specification +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 69d8b7953c3259e243cf746388a0951b89649763 diff --git a/tests/examples/.source b/tests/examples/.source new file mode 100644 index 0000000..f43a11f --- /dev/null +++ b/tests/examples/.source @@ -0,0 +1 @@ +https://github.com/OAI/learn.openapis.org/tree/b46517f32fb3f03595232b03c85de6e48a90abd5/examples diff --git a/tests/examples/README.rst b/tests/examples/README.rst new file mode 100644 index 0000000..e1463f5 --- /dev/null +++ b/tests/examples/README.rst @@ -0,0 +1,27 @@ +OpenAPI Examples +================ + +A copy of the examples taken from `github.com/OAI/learn.openapis.org`__ + +This can be updated like so: + +.. code-block:: bash + + # clone repo + git clone --depth 1 https://github.com/OAI/learn.openapis.org.git /tmp/learn-openapis + + # copy updates + rm -rf tests/examples + cp -r /tmp/learn-openapis/examples tests/examples + + # store commit + echo "https://github.com/OAI/learn.openapis.org/tree/$(git -C /tmp/learn-openapis rev-parse HEAD)/examples" > tests/examples/.source + + # restore README and remove unnecessary index file + git checkout -f HEAD -- tests/examples/README.rst + rm tests/examples/index.md + + # delete clone + rm -rf /tmp/learn-openapis + +.. __: https://github.com/OAI/learn.openapis.org.git diff --git a/tests/examples/index.md b/tests/examples/index.md new file mode 100644 index 0000000..032e604 --- /dev/null +++ b/tests/examples/index.md @@ -0,0 +1,9 @@ +--- +layout: default +title: Example API Descriptions +nav_order: 8 +has_children: true +has_toc: true +--- + +# Example API Descriptions diff --git a/tests/examples/v2.0/json/api-with-examples.json b/tests/examples/v2.0/json/api-with-examples.json new file mode 100644 index 0000000..e1b371a --- /dev/null +++ b/tests/examples/v2.0/json/api-with-examples.json @@ -0,0 +1,58 @@ +{ + "swagger": "2.0", + "info": { + "title": "Simple API overview", + "version": "v2" + }, + "paths": { + "/": { + "get": { + "operationId": "listVersionsv2", + "summary": "List API versions", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "200 300 response", + "examples": { + "application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}" + } + }, + "300": { + "description": "200 300 response", + "examples": { + "application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}" + } + } + } + } + }, + "/v2": { + "get": { + "operationId": "getVersionDetailsv2", + "summary": "Show API version details", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "200 203 response", + "examples": { + "application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}" + } + }, + "203": { + "description": "200 203 response", + "examples": { + "application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://23.253.228.211:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}" + } + } + } + } + } + }, + "consumes": [ + "application/json" + ] +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-expanded.json b/tests/examples/v2.0/json/petstore-expanded.json new file mode 100644 index 0000000..d5d8de8 --- /dev/null +++ b/tests/examples/v2.0/json/petstore-expanded.json @@ -0,0 +1,210 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + "operationId": "findPets", + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + }, + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "parameters": [ + { + "name": "pet", + "in": "body", + "description": "Pet to add to the store", + "required": true, + "schema": { + "$ref": "#/definitions/NewPet" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "find pet by id", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "Pet": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/NewPet" + }, + { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +} diff --git a/tests/examples/v2.0/json/petstore-minimal.json b/tests/examples/v2.0/json/petstore-minimal.json new file mode 100644 index 0000000..0c70bae --- /dev/null +++ b/tests/examples/v2.0/json/petstore-minimal.json @@ -0,0 +1,68 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team" + }, + "license": { + "name": "MIT" + } + }, + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + } + } + } + } + }, + "definitions": { + "Pet": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-separate/common/Error.json b/tests/examples/v2.0/json/petstore-separate/common/Error.json new file mode 100644 index 0000000..dd0e65a --- /dev/null +++ b/tests/examples/v2.0/json/petstore-separate/common/Error.json @@ -0,0 +1,16 @@ +{ + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-separate/spec/NewPet.json b/tests/examples/v2.0/json/petstore-separate/spec/NewPet.json new file mode 100644 index 0000000..9104f7f --- /dev/null +++ b/tests/examples/v2.0/json/petstore-separate/spec/NewPet.json @@ -0,0 +1,19 @@ +{ + "type": "object", + "allOf": [ + { + "$ref": "Pet.json" + }, + { + "required": [ + "name" + ], + "properties": { + "description": { + "type": "integer", + "format": "int64" + } + } + } + ] +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-separate/spec/Pet.json b/tests/examples/v2.0/json/petstore-separate/spec/Pet.json new file mode 100644 index 0000000..c7ee9fb --- /dev/null +++ b/tests/examples/v2.0/json/petstore-separate/spec/Pet.json @@ -0,0 +1,19 @@ +{ + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-separate/spec/parameters.json b/tests/examples/v2.0/json/petstore-separate/spec/parameters.json new file mode 100644 index 0000000..a7c11b0 --- /dev/null +++ b/tests/examples/v2.0/json/petstore-separate/spec/parameters.json @@ -0,0 +1,21 @@ +{ + "tagsParam": { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + }, + "limitsParam": { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-separate/spec/swagger.json b/tests/examples/v2.0/json/petstore-separate/spec/swagger.json new file mode 100644 index 0000000..7276990 --- /dev/null +++ b/tests/examples/v2.0/json/petstore-separate/spec/swagger.json @@ -0,0 +1,146 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + "operationId": "findPets", + "parameters": [ + { + "$ref": "parameters.json#/tagsParam" + }, + { + "$ref": "parameters.json#/limitsParam" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "Pet.json" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "../common/Error.json" + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "parameters": [ + { + "name": "pet", + "in": "body", + "description": "Pet to add to the store", + "required": true, + "schema": { + "$ref": "NewPet.json" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "Pet.json" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "../common/Error.json" + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "find pet by id", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "Pet.json" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "../common/Error.json" + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "../common/Error.json" + } + } + } + } + } + } +} diff --git a/tests/examples/v2.0/json/petstore-simple.json b/tests/examples/v2.0/json/petstore-simple.json new file mode 100644 index 0000000..306dc90 --- /dev/null +++ b/tests/examples/v2.0/json/petstore-simple.json @@ -0,0 +1,222 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team" + }, + "license": { + "name": "MIT" + } + }, + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to", + "operationId": "findPets", + "produces": [ + "application/json", + "application/xml", + "text/xml", + "text/html" + ], + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv" + }, + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "pet", + "in": "body", + "description": "Pet to add to the store", + "required": true, + "schema": { + "$ref": "#/definitions/NewPet" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "findPetById", + "produces": [ + "application/json", + "application/xml", + "text/xml", + "text/html" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + } + } + }, + "definitions": { + "Pet": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/NewPet" + }, + { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "ErrorModel": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/petstore-with-external-docs.json b/tests/examples/v2.0/json/petstore-with-external-docs.json new file mode 100644 index 0000000..e9d3f77 --- /dev/null +++ b/tests/examples/v2.0/json/petstore-with-external-docs.json @@ -0,0 +1,233 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "externalDocs": { + "description": "find more info here", + "url": "https://swagger.io/about" + }, + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to", + "operationId": "findPets", + "externalDocs": { + "description": "find more info here", + "url": "https://swagger.io/about" + }, + "produces": [ + "application/json", + "application/xml", + "text/xml", + "text/html" + ], + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv" + }, + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "pet", + "in": "body", + "description": "Pet to add to the store", + "required": true, + "schema": { + "$ref": "#/definitions/NewPet" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "findPetById", + "produces": [ + "application/json", + "application/xml", + "text/xml", + "text/html" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + } + } + }, + "definitions": { + "Pet": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/NewPet" + }, + { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "ErrorModel": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +} diff --git a/tests/examples/v2.0/json/petstore.json b/tests/examples/v2.0/json/petstore.json new file mode 100644 index 0000000..415eb3f --- /dev/null +++ b/tests/examples/v2.0/json/petstore.json @@ -0,0 +1,153 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "license": { + "name": "MIT" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v1", + "schemes": [ + "http" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/pets": { + "get": { + "summary": "List all pets", + "operationId": "listPets", + "tags": [ + "pets" + ], + "parameters": [ + { + "name": "limit", + "in": "query", + "description": "How many items to return at one time (max 100)", + "required": false, + "type": "integer", + "format": "int32" + } + ], + "responses": { + "200": { + "description": "An paged array of pets", + "headers": { + "x-next": { + "type": "string", + "description": "A link to the next page of responses" + } + }, + "schema": { + "$ref": "#/definitions/Pets" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "summary": "Create a pet", + "operationId": "createPets", + "tags": [ + "pets" + ], + "responses": { + "201": { + "description": "Null response" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/pets/{petId}": { + "get": { + "summary": "Info for a specific pet", + "operationId": "showPetById", + "tags": [ + "pets" + ], + "parameters": [ + { + "name": "petId", + "in": "path", + "required": true, + "description": "The id of the pet to retrieve", + "type": "string" + } + ], + "responses": { + "200": { + "description": "Expected response to a valid request", + "schema": { + "$ref": "#/definitions/Pets" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Pets": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + }, + "Error": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/json/uber.json b/tests/examples/v2.0/json/uber.json new file mode 100644 index 0000000..9577828 --- /dev/null +++ b/tests/examples/v2.0/json/uber.json @@ -0,0 +1,370 @@ +{ + "swagger": "2.0", + "info": { + "title": "Uber API", + "description": "Move your app forward with the Uber API", + "version": "1.0.0" + }, + "host": "api.uber.com", + "schemes": [ + "https" + ], + "basePath": "/v1", + "produces": [ + "application/json" + ], + "paths": { + "/products": { + "get": { + "summary": "Product Types", + "description": "The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.", + "parameters": [ + { + "name": "latitude", + "in": "query", + "description": "Latitude component of location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "longitude", + "in": "query", + "description": "Longitude component of location.", + "required": true, + "type": "number", + "format": "double" + } + ], + "tags": [ + "Products" + ], + "responses": { + "200": { + "description": "An array of products", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Product" + } + } + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/estimates/price": { + "get": { + "summary": "Price Estimates", + "description": "The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.

The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.", + "parameters": [ + { + "name": "start_latitude", + "in": "query", + "description": "Latitude component of start location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "start_longitude", + "in": "query", + "description": "Longitude component of start location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "end_latitude", + "in": "query", + "description": "Latitude component of end location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "end_longitude", + "in": "query", + "description": "Longitude component of end location.", + "required": true, + "type": "number", + "format": "double" + } + ], + "tags": [ + "Estimates" + ], + "responses": { + "200": { + "description": "An array of price estimates by product", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/PriceEstimate" + } + } + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/estimates/time": { + "get": { + "summary": "Time Estimates", + "description": "The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.", + "parameters": [ + { + "name": "start_latitude", + "in": "query", + "description": "Latitude component of start location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "start_longitude", + "in": "query", + "description": "Longitude component of start location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "customer_uuid", + "in": "query", + "type": "string", + "format": "uuid", + "description": "Unique customer identifier to be used for experience customization." + }, + { + "name": "product_id", + "in": "query", + "type": "string", + "description": "Unique identifier representing a specific product for a given latitude & longitude." + } + ], + "tags": [ + "Estimates" + ], + "responses": { + "200": { + "description": "An array of products", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Product" + } + } + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/me": { + "get": { + "summary": "User Profile", + "description": "The User Profile endpoint returns information about the Uber user that has authorized with the application.", + "tags": [ + "User" + ], + "responses": { + "200": { + "description": "Profile information for a user", + "schema": { + "$ref": "#/definitions/Profile" + } + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/history": { + "get": { + "summary": "User Activity", + "description": "The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.

The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.", + "parameters": [ + { + "name": "offset", + "in": "query", + "type": "integer", + "format": "int32", + "description": "Offset the list of returned results by this amount. Default is zero." + }, + { + "name": "limit", + "in": "query", + "type": "integer", + "format": "int32", + "description": "Number of items to retrieve. Default is 5, maximum is 100." + } + ], + "tags": [ + "User" + ], + "responses": { + "200": { + "description": "History information for the given user", + "schema": { + "$ref": "#/definitions/Activities" + } + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "Product": { + "properties": { + "product_id": { + "type": "string", + "description": "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles." + }, + "description": { + "type": "string", + "description": "Description of product." + }, + "display_name": { + "type": "string", + "description": "Display name of product." + }, + "capacity": { + "type": "string", + "description": "Capacity of product. For example, 4 people." + }, + "image": { + "type": "string", + "description": "Image URL representing the product." + } + } + }, + "PriceEstimate": { + "properties": { + "product_id": { + "type": "string", + "description": "Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles" + }, + "currency_code": { + "type": "string", + "description": "[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code." + }, + "display_name": { + "type": "string", + "description": "Display name of product." + }, + "estimate": { + "type": "string", + "description": "Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or \"Metered\" for TAXI." + }, + "low_estimate": { + "type": "number", + "description": "Lower bound of the estimated price." + }, + "high_estimate": { + "type": "number", + "description": "Upper bound of the estimated price." + }, + "surge_multiplier": { + "type": "number", + "description": "Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier." + } + } + }, + "Profile": { + "properties": { + "first_name": { + "type": "string", + "description": "First name of the Uber user." + }, + "last_name": { + "type": "string", + "description": "Last name of the Uber user." + }, + "email": { + "type": "string", + "description": "Email address of the Uber user" + }, + "picture": { + "type": "string", + "description": "Image URL of the Uber user." + }, + "promo_code": { + "type": "string", + "description": "Promo code of the Uber user." + } + } + }, + "Activity": { + "properties": { + "uuid": { + "type": "string", + "description": "Unique identifier for the activity" + } + } + }, + "Activities": { + "properties": { + "offset": { + "type": "integer", + "format": "int32", + "description": "Position in pagination." + }, + "limit": { + "type": "integer", + "format": "int32", + "description": "Number of items to retrieve (100 max)." + }, + "count": { + "type": "integer", + "format": "int32", + "description": "Total number of items available." + }, + "history": { + "type": "array", + "items": { + "$ref": "#/definitions/Activity" + } + } + } + }, + "Error": { + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "fields": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/tests/examples/v2.0/yaml/api-with-examples.yaml b/tests/examples/v2.0/yaml/api-with-examples.yaml new file mode 100644 index 0000000..2f4a1cc --- /dev/null +++ b/tests/examples/v2.0/yaml/api-with-examples.yaml @@ -0,0 +1,164 @@ +swagger: "2.0" +info: + title: Simple API overview + version: v2 +paths: + /: + get: + operationId: listVersionsv2 + summary: List API versions + produces: + - application/json + responses: + "200": + description: |- + 200 300 response + examples: + application/json: |- + { + "versions": [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + "300": + description: |- + 200 300 response + examples: + application/json: |- + { + "versions": [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + /v2: + get: + operationId: getVersionDetailsv2 + summary: Show API version details + produces: + - application/json + responses: + "200": + description: |- + 200 203 response + examples: + application/json: |- + { + "version": { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } + "203": + description: |- + 200 203 response + examples: + application/json: |- + { + "version": { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": [ + { + "href": "http://23.253.228.211:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } +consumes: +- application/json diff --git a/tests/examples/v2.0/yaml/petstore-expanded.yaml b/tests/examples/v2.0/yaml/petstore-expanded.yaml new file mode 100644 index 0000000..de93377 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-expanded.yaml @@ -0,0 +1,142 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +host: petstore.swagger.io +basePath: /api +schemes: + - http +consumes: + - application/json +produces: + - application/json +paths: + /pets: + get: + description: | + Returns all pets from the system that the user has access to + operationId: findPets + parameters: + - name: tags + in: query + description: tags to filter by + required: false + type: array + collectionFormat: csv + items: + type: string + - name: limit + in: query + description: maximum number of results to return + required: false + type: integer + format: int32 + responses: + "200": + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + post: + description: Creates a new pet in the store. Duplicates are allowed + operationId: addPet + parameters: + - name: pet + in: body + description: Pet to add to the store + required: true + schema: + $ref: '#/definitions/NewPet' + responses: + "200": + description: pet response + schema: + $ref: '#/definitions/Pet' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + /pets/{id}: + get: + description: Returns a user based on a single ID, if the user does not have access to the pet + operationId: find pet by id + parameters: + - name: id + in: path + description: ID of pet to fetch + required: true + type: integer + format: int64 + responses: + "200": + description: pet response + schema: + $ref: '#/definitions/Pet' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + delete: + description: deletes a single pet based on the ID supplied + operationId: deletePet + parameters: + - name: id + in: path + description: ID of pet to delete + required: true + type: integer + format: int64 + responses: + "204": + description: pet deleted + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' +definitions: + Pet: + allOf: + - $ref: '#/definitions/NewPet' + - required: + - id + type: "object" + properties: + id: + type: integer + format: int64 + + NewPet: + type: "object" + required: + - name + properties: + name: + type: string + tag: + type: string + + Error: + type: "object" + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/tests/examples/v2.0/yaml/petstore-minimal.yaml b/tests/examples/v2.0/yaml/petstore-minimal.yaml new file mode 100644 index 0000000..c3e06e9 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-minimal.yaml @@ -0,0 +1,47 @@ +--- + swagger: "2.0" + info: + version: "1.0.0" + title: "Swagger Petstore" + description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" + termsOfService: "http://swagger.io/terms/" + contact: + name: "Swagger API Team" + license: + name: "MIT" + host: "petstore.swagger.io" + basePath: "/api" + schemes: + - "http" + consumes: + - "application/json" + produces: + - "application/json" + paths: + /pets: + get: + description: "Returns all pets from the system that the user has access to" + produces: + - "application/json" + responses: + "200": + description: "A list of pets." + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + definitions: + Pet: + type: "object" + required: + - "id" + - "name" + properties: + id: + type: "integer" + format: "int64" + name: + type: "string" + tag: + type: "string" + diff --git a/tests/examples/v2.0/yaml/petstore-separate/common/Error.yaml b/tests/examples/v2.0/yaml/petstore-separate/common/Error.yaml new file mode 100644 index 0000000..2d87b74 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-separate/common/Error.yaml @@ -0,0 +1,10 @@ +type: object +required: + - code + - message +properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/tests/examples/v2.0/yaml/petstore-separate/spec/NewPet.yaml b/tests/examples/v2.0/yaml/petstore-separate/spec/NewPet.yaml new file mode 100644 index 0000000..35e6744 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-separate/spec/NewPet.yaml @@ -0,0 +1,9 @@ +type: object +allOf: + - $ref: 'Pet.yaml' + - required: + - name + properties: + description: + type: integer + format: int64 diff --git a/tests/examples/v2.0/yaml/petstore-separate/spec/Pet.yaml b/tests/examples/v2.0/yaml/petstore-separate/spec/Pet.yaml new file mode 100644 index 0000000..bb11319 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-separate/spec/Pet.yaml @@ -0,0 +1,12 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/tests/examples/v2.0/yaml/petstore-separate/spec/parameters.yaml b/tests/examples/v2.0/yaml/petstore-separate/spec/parameters.yaml new file mode 100644 index 0000000..18736ae --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-separate/spec/parameters.yaml @@ -0,0 +1,16 @@ +tagsParam: + name: tags + in: query + description: tags to filter by + required: false + type: array + collectionFormat: csv + items: + type: string +limitsParam: + name: limit + in: query + description: maximum number of results to return + required: false + type: integer + format: int32 diff --git a/tests/examples/v2.0/yaml/petstore-separate/spec/swagger.yaml b/tests/examples/v2.0/yaml/petstore-separate/spec/swagger.yaml new file mode 100644 index 0000000..b937b50 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-separate/spec/swagger.yaml @@ -0,0 +1,100 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +host: petstore.swagger.io +basePath: /api +schemes: + - http +consumes: + - application/json +produces: + - application/json +paths: + /pets: + get: + description: | + Returns all pets from the system that the user has access to + Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. + + Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. + operationId: findPets + parameters: + - $ref: 'parameters.yaml#/tagsParam' + - $ref: 'parameters.yaml#/limitsParam' + responses: + "200": + description: pet response + schema: + type: array + items: + $ref: 'Pet.yaml' + default: + description: unexpected error + schema: + $ref: '../common/Error.yaml' + post: + description: Creates a new pet in the store. Duplicates are allowed + operationId: addPet + parameters: + - name: pet + in: body + description: Pet to add to the store + required: true + schema: + $ref: 'NewPet.yaml' + responses: + "200": + description: pet response + schema: + $ref: 'Pet.yaml' + default: + description: unexpected error + schema: + $ref: '../common/Error.yaml' + /pets/{id}: + get: + description: Returns a user based on a single ID, if the user does not have access to the pet + operationId: find pet by id + parameters: + - name: id + in: path + description: ID of pet to fetch + required: true + type: integer + format: int64 + responses: + "200": + description: pet response + schema: + $ref: 'Pet.yaml' + default: + description: unexpected error + schema: + $ref: '../common/Error.yaml' + delete: + description: deletes a single pet based on the ID supplied + operationId: deletePet + parameters: + - name: id + in: path + description: ID of pet to delete + required: true + type: integer + format: int64 + responses: + "204": + description: pet deleted + default: + description: unexpected error + schema: + $ref: '../common/Error.yaml' diff --git a/tests/examples/v2.0/yaml/petstore-simple.yaml b/tests/examples/v2.0/yaml/petstore-simple.yaml new file mode 100644 index 0000000..d5fa07b --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-simple.yaml @@ -0,0 +1,157 @@ +--- + swagger: "2.0" + info: + version: "1.0.0" + title: "Swagger Petstore" + description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" + termsOfService: "http://swagger.io/terms/" + contact: + name: "Swagger API Team" + license: + name: "MIT" + host: "petstore.swagger.io" + basePath: "/api" + schemes: + - "http" + consumes: + - "application/json" + produces: + - "application/json" + paths: + /pets: + get: + description: "Returns all pets from the system that the user has access to" + operationId: "findPets" + produces: + - "application/json" + - "application/xml" + - "text/xml" + - "text/html" + parameters: + - + name: "tags" + in: "query" + description: "tags to filter by" + required: false + type: "array" + items: + type: "string" + collectionFormat: "csv" + - + name: "limit" + in: "query" + description: "maximum number of results to return" + required: false + type: "integer" + format: "int32" + responses: + "200": + description: "pet response" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + post: + description: "Creates a new pet in the store. Duplicates are allowed" + operationId: "addPet" + produces: + - "application/json" + parameters: + - + name: "pet" + in: "body" + description: "Pet to add to the store" + required: true + schema: + $ref: "#/definitions/NewPet" + responses: + "200": + description: "pet response" + schema: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + /pets/{id}: + get: + description: "Returns a user based on a single ID, if the user does not have access to the pet" + operationId: "findPetById" + produces: + - "application/json" + - "application/xml" + - "text/xml" + - "text/html" + parameters: + - + name: "id" + in: "path" + description: "ID of pet to fetch" + required: true + type: "integer" + format: "int64" + responses: + "200": + description: "pet response" + schema: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + delete: + description: "deletes a single pet based on the ID supplied" + operationId: "deletePet" + parameters: + - + name: "id" + in: "path" + description: "ID of pet to delete" + required: true + type: "integer" + format: "int64" + responses: + "204": + description: "pet deleted" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + definitions: + Pet: + type: "object" + allOf: + - + $ref: "#/definitions/NewPet" + - + required: + - "id" + properties: + id: + type: "integer" + format: "int64" + NewPet: + type: "object" + required: + - "name" + properties: + name: + type: "string" + tag: + type: "string" + ErrorModel: + type: "object" + required: + - "code" + - "message" + properties: + code: + type: "integer" + format: "int32" + message: + type: "string" + diff --git a/tests/examples/v2.0/yaml/petstore-with-external-docs.yaml b/tests/examples/v2.0/yaml/petstore-with-external-docs.yaml new file mode 100644 index 0000000..792864f --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore-with-external-docs.yaml @@ -0,0 +1,166 @@ +--- + swagger: "2.0" + info: + version: "1.0.0" + title: "Swagger Petstore" + description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" + termsOfService: "http://swagger.io/terms/" + contact: + name: "Swagger API Team" + email: "apiteam@swagger.io" + url: "http://swagger.io" + license: + name: "Apache 2.0" + url: "https://www.apache.org/licenses/LICENSE-2.0.html" + externalDocs: + description: "find more info here" + url: "https://swagger.io/about" + host: "petstore.swagger.io" + basePath: "/api" + schemes: + - "http" + consumes: + - "application/json" + produces: + - "application/json" + paths: + /pets: + get: + description: "Returns all pets from the system that the user has access to" + operationId: "findPets" + externalDocs: + description: "find more info here" + url: "https://swagger.io/about" + produces: + - "application/json" + - "application/xml" + - "text/xml" + - "text/html" + parameters: + - + name: "tags" + in: "query" + description: "tags to filter by" + required: false + type: "array" + items: + type: "string" + collectionFormat: "csv" + - + name: "limit" + in: "query" + description: "maximum number of results to return" + required: false + type: "integer" + format: "int32" + responses: + "200": + description: "pet response" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + post: + description: "Creates a new pet in the store. Duplicates are allowed" + operationId: "addPet" + produces: + - "application/json" + parameters: + - + name: "pet" + in: "body" + description: "Pet to add to the store" + required: true + schema: + $ref: "#/definitions/NewPet" + responses: + "200": + description: "pet response" + schema: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + /pets/{id}: + get: + description: "Returns a user based on a single ID, if the user does not have access to the pet" + operationId: "findPetById" + produces: + - "application/json" + - "application/xml" + - "text/xml" + - "text/html" + parameters: + - + name: "id" + in: "path" + description: "ID of pet to fetch" + required: true + type: "integer" + format: "int64" + responses: + "200": + description: "pet response" + schema: + $ref: "#/definitions/Pet" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + delete: + description: "deletes a single pet based on the ID supplied" + operationId: "deletePet" + parameters: + - + name: "id" + in: "path" + description: "ID of pet to delete" + required: true + type: "integer" + format: "int64" + responses: + "204": + description: "pet deleted" + default: + description: "unexpected error" + schema: + $ref: "#/definitions/ErrorModel" + definitions: + Pet: + type: "object" + allOf: + - + $ref: "#/definitions/NewPet" + - + required: + - "id" + properties: + id: + type: "integer" + format: "int64" + NewPet: + type: "object" + required: + - "name" + properties: + name: + type: "string" + tag: + type: "string" + ErrorModel: + type: "object" + required: + - "code" + - "message" + properties: + code: + type: "integer" + format: "int32" + message: + type: "string" + diff --git a/tests/examples/v2.0/yaml/petstore.yaml b/tests/examples/v2.0/yaml/petstore.yaml new file mode 100644 index 0000000..5f41fe0 --- /dev/null +++ b/tests/examples/v2.0/yaml/petstore.yaml @@ -0,0 +1,103 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +host: petstore.swagger.io +basePath: /v1 +schemes: + - http +consumes: + - application/json +produces: + - application/json +paths: + /pets: + get: + summary: List all pets + operationId: listPets + tags: + - pets + parameters: + - name: limit + in: query + description: How many items to return at one time (max 100) + required: false + type: integer + format: int32 + responses: + "200": + description: A paged array of pets + headers: + x-next: + type: string + description: A link to the next page of responses + schema: + $ref: '#/definitions/Pets' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + post: + summary: Create a pet + operationId: createPets + tags: + - pets + responses: + "201": + description: Null response + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + /pets/{petId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: petId + in: path + required: true + description: The id of the pet to retrieve + type: string + responses: + "200": + description: Expected response to a valid request + schema: + $ref: '#/definitions/Pets' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' +definitions: + Pet: + type: "object" + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + items: + $ref: '#/definitions/Pet' + Error: + type: "object" + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/tests/examples/v2.0/yaml/uber.yaml b/tests/examples/v2.0/yaml/uber.yaml new file mode 100644 index 0000000..12c14b0 --- /dev/null +++ b/tests/examples/v2.0/yaml/uber.yaml @@ -0,0 +1,273 @@ +# this is an example of the Uber API +# as a demonstration of an API spec in YAML +swagger: "2.0" +info: + title: Uber API + description: Move your app forward with the Uber API + version: "1.0.0" +# the domain of the service +host: api.uber.com +# array of all schemes that your API supports +schemes: + - https +# will be prefixed to all paths +basePath: /v1 +securityDefinitions: + apikey: + type: apiKey + name: server_token + in: query +produces: + - application/json +paths: + /products: + get: + summary: Product Types + description: The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order. + parameters: + - name: latitude + in: query + description: Latitude component of location. + required: true + type: number + format: double + - name: longitude + in: query + description: Longitude component of location. + required: true + type: number + format: double + security: + - apikey: [] + tags: + - Products + responses: + "200": + description: An array of products + schema: + type: array + items: + $ref: '#/definitions/Product' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /estimates/price: + get: + summary: Price Estimates + description: The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.

The response also includes low and high estimates, and the [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier. + parameters: + - name: start_latitude + in: query + description: Latitude component of start location. + required: true + type: number + format: double + - name: start_longitude + in: query + description: Longitude component of start location. + required: true + type: number + format: double + - name: end_latitude + in: query + description: Latitude component of end location. + required: true + type: number + format: double + - name: end_longitude + in: query + description: Longitude component of end location. + required: true + type: number + format: double + tags: + - Estimates + responses: + "200": + description: An array of price estimates by product + schema: + type: array + items: + $ref: '#/definitions/PriceEstimate' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /estimates/time: + get: + summary: Time Estimates + description: The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs. + parameters: + - name: start_latitude + in: query + description: Latitude component of start location. + required: true + type: number + format: double + - name: start_longitude + in: query + description: Longitude component of start location. + required: true + type: number + format: double + - name: customer_uuid + in: query + type: string + format: uuid + description: Unique customer identifier to be used for experience customization. + - name: product_id + in: query + type: string + description: Unique identifier representing a specific product for a given latitude & longitude. + tags: + - Estimates + responses: + "200": + description: An array of products + schema: + type: array + items: + $ref: '#/definitions/Product' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /me: + get: + summary: User Profile + description: The User Profile endpoint returns information about the Uber user that has authorized with the application. + tags: + - User + responses: + "200": + description: Profile information for a user + schema: + $ref: '#/definitions/Profile' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' + /history: + get: + summary: User Activity + description: The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.

The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary. + parameters: + - name: offset + in: query + type: integer + format: int32 + description: Offset the list of returned results by this amount. Default is zero. + - name: limit + in: query + type: integer + format: int32 + description: Number of items to retrieve. Default is 5, maximum is 100. + tags: + - User + responses: + "200": + description: History information for the given user + schema: + $ref: '#/definitions/Activities' + default: + description: Unexpected error + schema: + $ref: '#/definitions/Error' +definitions: + Product: + properties: + product_id: + type: string + description: Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. + description: + type: string + description: Description of product. + display_name: + type: string + description: Display name of product. + capacity: + type: integer + description: Capacity of product. For example, 4 people. + image: + type: string + description: Image URL representing the product. + ProductList: + properties: + products: + description: Contains the list of products + type: array + items: + $ref: "#/definitions/Product" + PriceEstimate: + properties: + product_id: + type: string + description: Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles + currency_code: + type: string + description: "[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code." + display_name: + type: string + description: Display name of product. + estimate: + type: string + description: Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI. + low_estimate: + type: number + description: Lower bound of the estimated price. + high_estimate: + type: number + description: Upper bound of the estimated price. + surge_multiplier: + type: number + description: Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier. + Profile: + properties: + first_name: + type: string + description: First name of the Uber user. + last_name: + type: string + description: Last name of the Uber user. + email: + type: string + description: Email address of the Uber user + picture: + type: string + description: Image URL of the Uber user. + promo_code: + type: string + description: Promo code of the Uber user. + Activity: + properties: + uuid: + type: string + description: Unique identifier for the activity + Activities: + properties: + offset: + type: integer + format: int32 + description: Position in pagination. + limit: + type: integer + format: int32 + description: Number of items to retrieve (100 max). + count: + type: integer + format: int32 + description: Total number of items available. + history: + type: array + items: + $ref: '#/definitions/Activity' + Error: + properties: + code: + type: integer + format: int32 + message: + type: string + fields: + type: string diff --git a/tests/examples/v3.0/api-with-examples.json b/tests/examples/v3.0/api-with-examples.json new file mode 100644 index 0000000..31d2e9b --- /dev/null +++ b/tests/examples/v3.0/api-with-examples.json @@ -0,0 +1,192 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Simple API overview", + "version": "2.0.0" + }, + "paths": { + "/": { + "get": { + "operationId": "listVersionsv2", + "summary": "List API versions", + "responses": { + "200": { + "description": "200 response", + "content": { + "application/json": { + "examples": { + "foo": { + "value": { + "versions": [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + } + } + } + } + }, + "300": { + "description": "300 response", + "content": { + "application/json": { + "examples": { + "foo": { + "value": { + "versions": [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + } + } + } + } + } + } + } + }, + "/v2": { + "get": { + "operationId": "getVersionDetailsv2", + "summary": "Show API version details", + "responses": { + "200": { + "description": "200 response", + "content": { + "application/json": { + "examples": { + "foo": { + "value": { + "version": { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } + } + } + } + } + }, + "203": { + "description": "203 response", + "content": { + "application/json": { + "examples": { + "foo": { + "value": { + "version": { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": [ + { + "href": "http://23.253.228.211:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/tests/examples/v3.0/api-with-examples.md b/tests/examples/v3.0/api-with-examples.md new file mode 100644 index 0000000..073e9a2 --- /dev/null +++ b/tests/examples/v3.0/api-with-examples.md @@ -0,0 +1,13 @@ +--- +layout: default +title: api-with-examples +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/api-with-examples.yaml b/tests/examples/v3.0/api-with-examples.yaml new file mode 100644 index 0000000..a94b294 --- /dev/null +++ b/tests/examples/v3.0/api-with-examples.yaml @@ -0,0 +1,178 @@ +openapi: 3.0.0 +info: + title: Simple API overview + version: 2.0.0 +paths: + /: + get: + operationId: listVersionsv2 + summary: List API versions + responses: + '200': + description: 200 response + content: + application/json: + examples: + foo: + value: + { + "versions": + [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": + [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": + [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + '300': + description: 300 response + content: + application/json: + examples: + foo: + value: + { + "versions": + [ + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "id": "v2.0", + "links": + [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + } + ] + }, + { + "status": "EXPERIMENTAL", + "updated": "2013-07-23T11:33:21Z", + "id": "v3.0", + "links": + [ + { + "href": "http://127.0.0.1:8774/v3/", + "rel": "self" + } + ] + } + ] + } + /v2: + get: + operationId: getVersionDetailsv2 + summary: Show API version details + responses: + "200": + description: 200 response + content: + application/json: + examples: + foo: + value: + { + "version": + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": + [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": + [ + { + "href": "http://127.0.0.1:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } + '203': + description: 203 response + content: + application/json: + examples: + foo: + value: + { + "version": + { + "status": "CURRENT", + "updated": "2011-01-21T11:33:21Z", + "media-types": + [ + { + "base": "application/xml", + "type": "application/vnd.openstack.compute+xml;version=2" + }, + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2" + } + ], + "id": "v2.0", + "links": + [ + { + "href": "http://23.253.228.211:8774/v2/", + "rel": "self" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", + "type": "application/pdf", + "rel": "describedby" + }, + { + "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", + "type": "application/vnd.sun.wadl+xml", + "rel": "describedby" + } + ] + } + } diff --git a/tests/examples/v3.0/callback-example.json b/tests/examples/v3.0/callback-example.json new file mode 100644 index 0000000..ebd2d3d --- /dev/null +++ b/tests/examples/v3.0/callback-example.json @@ -0,0 +1,83 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Callback Example", + "version": "1.0.0" + }, + "paths": { + "/streams": { + "post": { + "description": "subscribes a client to receive out-of-band data", + "parameters": [ + { + "name": "callbackUrl", + "in": "query", + "required": true, + "description": "the location where data will be sent. Must be network accessible\nby the source server\n", + "schema": { + "type": "string", + "format": "uri", + "example": "https://tonys-server.com" + } + } + ], + "responses": { + "201": { + "description": "subscription successfully created", + "content": { + "application/json": { + "schema": { + "type": "object", + "description": "subscription information", + "required": ["subscriptionId"], + "properties": { + "subscriptionId": { + "description": "this unique identifier allows management of the subscription", + "type": "string", + "example": "2531329f-fb09-4ef7-887e-84e648214436" + } + } + } + } + } + } + }, + "callbacks": { + "onData": { + "{$request.query.callbackUrl}/data": { + "post": { + "requestBody": { + "description": "subscription payload", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "timestamp": { + "type": "string", + "format": "date-time" + }, + "userData": { + "type": "string" + } + } + } + } + } + }, + "responses": { + "202": { + "description": "Your server implementation should return this HTTP status code\nif the data was received successfully\n" + }, + "204": { + "description": "Your server should return this HTTP status code if no longer interested\nin further updates\n" + } + } + } + } + } + } + } + } + } +} diff --git a/tests/examples/v3.0/callback-example.md b/tests/examples/v3.0/callback-example.md new file mode 100644 index 0000000..70deefd --- /dev/null +++ b/tests/examples/v3.0/callback-example.md @@ -0,0 +1,13 @@ +--- +layout: default +title: callback-example +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/callback-example.yaml b/tests/examples/v3.0/callback-example.yaml new file mode 100644 index 0000000..6cc8c38 --- /dev/null +++ b/tests/examples/v3.0/callback-example.yaml @@ -0,0 +1,62 @@ +openapi: 3.0.0 +info: + title: Callback Example + version: 1.0.0 +paths: + /streams: + post: + description: subscribes a client to receive out-of-band data + parameters: + - name: callbackUrl + in: query + required: true + description: | + the location where data will be sent. Must be network accessible + by the source server + schema: + type: string + format: uri + example: https://tonys-server.com + responses: + '201': + description: subscription successfully created + content: + application/json: + schema: + type: object + description: subscription information + required: + - subscriptionId + properties: + subscriptionId: + description: this unique identifier allows management of the subscription + type: string + example: 2531329f-fb09-4ef7-887e-84e648214436 + callbacks: + # the name `onData` is a convenience locator + onData: + # when data is sent, it will be sent to the `callbackUrl` provided + # when making the subscription PLUS the suffix `/data` + '{$request.query.callbackUrl}/data': + post: + requestBody: + description: subscription payload + content: + application/json: + schema: + type: object + properties: + timestamp: + type: string + format: date-time + userData: + type: string + responses: + '202': + description: | + Your server implementation should return this HTTP status code + if the data was received successfully + '204': + description: | + Your server should return this HTTP status code if no longer interested + in further updates diff --git a/tests/examples/v3.0/link-example.json b/tests/examples/v3.0/link-example.json new file mode 100644 index 0000000..e230387 --- /dev/null +++ b/tests/examples/v3.0/link-example.json @@ -0,0 +1,319 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Link Example", + "version": "1.0.0" + }, + "paths": { + "/2.0/users/{username}": { + "get": { + "operationId": "getUserByName", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The User", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/user" + } + } + }, + "links": { + "userRepositories": { + "$ref": "#/components/links/UserRepositories" + } + } + } + } + } + }, + "/2.0/repositories/{username}": { + "get": { + "operationId": "getRepositoriesByOwner", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "repositories owned by the supplied user", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/repository" + } + } + } + }, + "links": { + "userRepository": { + "$ref": "#/components/links/UserRepository" + } + } + } + } + } + }, + "/2.0/repositories/{username}/{slug}": { + "get": { + "operationId": "getRepository", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "slug", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The repository", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repository" + } + } + }, + "links": { + "repositoryPullRequests": { + "$ref": "#/components/links/RepositoryPullRequests" + } + } + } + } + } + }, + "/2.0/repositories/{username}/{slug}/pullrequests": { + "get": { + "operationId": "getPullRequestsByRepository", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "slug", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "state", + "in": "query", + "schema": { + "type": "string", + "enum": ["open", "merged", "declined"] + } + } + ], + "responses": { + "200": { + "description": "an array of pull request objects", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/pullrequest" + } + } + } + } + } + } + } + }, + "/2.0/repositories/{username}/{slug}/pullrequests/{pid}": { + "get": { + "operationId": "getPullRequestsById", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "slug", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "pid", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "a pull request object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/pullrequest" + } + } + }, + "links": { + "pullRequestMerge": { + "$ref": "#/components/links/PullRequestMerge" + } + } + } + } + } + }, + "/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": { + "post": { + "operationId": "mergePullRequest", + "parameters": [ + { + "name": "username", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "slug", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "pid", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "the PR was successfully merged" + } + } + } + } + }, + "components": { + "links": { + "UserRepositories": { + "operationId": "getRepositoriesByOwner", + "parameters": { + "username": "$response.body#/username" + } + }, + "UserRepository": { + "operationId": "getRepository", + "parameters": { + "username": "$response.body#/owner/username", + "slug": "$response.body#/slug" + } + }, + "RepositoryPullRequests": { + "operationId": "getPullRequestsByRepository", + "parameters": { + "username": "$response.body#/owner/username", + "slug": "$response.body#/slug" + } + }, + "PullRequestMerge": { + "operationId": "mergePullRequest", + "parameters": { + "username": "$response.body#/author/username", + "slug": "$response.body#/repository/slug", + "pid": "$response.body#/id" + } + } + }, + "schemas": { + "user": { + "type": "object", + "properties": { + "username": { + "type": "string" + }, + "uuid": { + "type": "string" + } + } + }, + "repository": { + "type": "object", + "properties": { + "slug": { + "type": "string" + }, + "owner": { + "$ref": "#/components/schemas/user" + } + } + }, + "pullrequest": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "repository": { + "$ref": "#/components/schemas/repository" + }, + "author": { + "$ref": "#/components/schemas/user" + } + } + } + } + } +} diff --git a/tests/examples/v3.0/link-example.md b/tests/examples/v3.0/link-example.md new file mode 100644 index 0000000..9881ccc --- /dev/null +++ b/tests/examples/v3.0/link-example.md @@ -0,0 +1,13 @@ +--- +layout: default +title: link-example +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/link-example.yaml b/tests/examples/v3.0/link-example.yaml new file mode 100644 index 0000000..ea90bdc --- /dev/null +++ b/tests/examples/v3.0/link-example.yaml @@ -0,0 +1,203 @@ +openapi: 3.0.0 +info: + title: Link Example + version: 1.0.0 +paths: + /2.0/users/{username}: + get: + operationId: getUserByName + parameters: + - name: username + in: path + required: true + schema: + type: string + responses: + '200': + description: The User + content: + application/json: + schema: + $ref: '#/components/schemas/user' + links: + userRepositories: + $ref: '#/components/links/UserRepositories' + /2.0/repositories/{username}: + get: + operationId: getRepositoriesByOwner + parameters: + - name: username + in: path + required: true + schema: + type: string + responses: + '200': + description: repositories owned by the supplied user + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/repository' + links: + userRepository: + $ref: '#/components/links/UserRepository' + /2.0/repositories/{username}/{slug}: + get: + operationId: getRepository + parameters: + - name: username + in: path + required: true + schema: + type: string + - name: slug + in: path + required: true + schema: + type: string + responses: + '200': + description: The repository + content: + application/json: + schema: + $ref: '#/components/schemas/repository' + links: + repositoryPullRequests: + $ref: '#/components/links/RepositoryPullRequests' + /2.0/repositories/{username}/{slug}/pullrequests: + get: + operationId: getPullRequestsByRepository + parameters: + - name: username + in: path + required: true + schema: + type: string + - name: slug + in: path + required: true + schema: + type: string + - name: state + in: query + schema: + type: string + enum: + - open + - merged + - declined + responses: + '200': + description: an array of pull request objects + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/pullrequest' + /2.0/repositories/{username}/{slug}/pullrequests/{pid}: + get: + operationId: getPullRequestsById + parameters: + - name: username + in: path + required: true + schema: + type: string + - name: slug + in: path + required: true + schema: + type: string + - name: pid + in: path + required: true + schema: + type: string + responses: + '200': + description: a pull request object + content: + application/json: + schema: + $ref: '#/components/schemas/pullrequest' + links: + pullRequestMerge: + $ref: '#/components/links/PullRequestMerge' + /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge: + post: + operationId: mergePullRequest + parameters: + - name: username + in: path + required: true + schema: + type: string + - name: slug + in: path + required: true + schema: + type: string + - name: pid + in: path + required: true + schema: + type: string + responses: + '204': + description: the PR was successfully merged +components: + links: + UserRepositories: + # returns array of '#/components/schemas/repository' + operationId: getRepositoriesByOwner + parameters: + username: $response.body#/username + UserRepository: + # returns '#/components/schemas/repository' + operationId: getRepository + parameters: + username: $response.body#/owner/username + slug: $response.body#/slug + RepositoryPullRequests: + # returns '#/components/schemas/pullrequest' + operationId: getPullRequestsByRepository + parameters: + username: $response.body#/owner/username + slug: $response.body#/slug + PullRequestMerge: + # executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge + operationId: mergePullRequest + parameters: + username: $response.body#/author/username + slug: $response.body#/repository/slug + pid: $response.body#/id + schemas: + user: + type: object + properties: + username: + type: string + uuid: + type: string + repository: + type: object + properties: + slug: + type: string + owner: + $ref: '#/components/schemas/user' + pullrequest: + type: object + properties: + id: + type: integer + title: + type: string + repository: + $ref: '#/components/schemas/repository' + author: + $ref: '#/components/schemas/user' diff --git a/tests/examples/v3.0/petstore-expanded.json b/tests/examples/v3.0/petstore-expanded.json new file mode 100644 index 0000000..7315872 --- /dev/null +++ b/tests/examples/v3.0/petstore-expanded.json @@ -0,0 +1,235 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "servers": [ + { + "url": "https://petstore.swagger.io/v2" + } + ], + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + "operationId": "findPets", + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "style": "form", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "requestBody": { + "description": "Pet to add to the store", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewPet" + } + } + } + }, + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "find pet by id", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "allOf": [ + { + "$ref": "#/components/schemas/NewPet" + }, + { + "type": "object", + "required": ["id"], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Error": { + "type": "object", + "required": ["code", "message"], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } +} diff --git a/tests/examples/v3.0/petstore-expanded.md b/tests/examples/v3.0/petstore-expanded.md new file mode 100644 index 0000000..62ef8e9 --- /dev/null +++ b/tests/examples/v3.0/petstore-expanded.md @@ -0,0 +1,13 @@ +--- +layout: default +title: petstore-expanded +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/petstore-expanded.yaml b/tests/examples/v3.0/petstore-expanded.yaml new file mode 100644 index 0000000..1b5a6ce --- /dev/null +++ b/tests/examples/v3.0/petstore-expanded.yaml @@ -0,0 +1,156 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +servers: + - url: https://petstore.swagger.io/v2 +paths: + /pets: + get: + description: | + Returns all pets from the system that the user has access to + Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. + + Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. + operationId: findPets + parameters: + - name: tags + in: query + description: tags to filter by + required: false + style: form + schema: + type: array + items: + type: string + - name: limit + in: query + description: maximum number of results to return + required: false + schema: + type: integer + format: int32 + responses: + '200': + description: pet response + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + post: + description: Creates a new pet in the store. Duplicates are allowed + operationId: addPet + requestBody: + description: Pet to add to the store + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/NewPet' + responses: + '200': + description: pet response + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /pets/{id}: + get: + description: Returns a user based on a single ID, if the user does not have access to the pet + operationId: find pet by id + parameters: + - name: id + in: path + description: ID of pet to fetch + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: pet response + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + delete: + description: deletes a single pet based on the ID supplied + operationId: deletePet + parameters: + - name: id + in: path + description: ID of pet to delete + required: true + schema: + type: integer + format: int64 + responses: + '204': + description: pet deleted + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' +components: + schemas: + Pet: + allOf: + - $ref: '#/components/schemas/NewPet' + - type: object + required: + - id + properties: + id: + type: integer + format: int64 + NewPet: + type: object + required: + - name + properties: + name: + type: string + tag: + type: string + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/tests/examples/v3.0/petstore.json b/tests/examples/v3.0/petstore.json new file mode 100644 index 0000000..9d717b6 --- /dev/null +++ b/tests/examples/v3.0/petstore.json @@ -0,0 +1,177 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "license": { + "name": "MIT" + } + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v1" + } + ], + "paths": { + "/pets": { + "get": { + "summary": "List all pets", + "operationId": "listPets", + "tags": ["pets"], + "parameters": [ + { + "name": "limit", + "in": "query", + "description": "How many items to return at one time (max 100)", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "A paged array of pets", + "headers": { + "x-next": { + "description": "A link to the next page of responses", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pets" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "post": { + "summary": "Create a pet", + "operationId": "createPets", + "tags": ["pets"], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "required": true + }, + "responses": { + "201": { + "description": "Null response" + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + }, + "/pets/{petId}": { + "get": { + "summary": "Info for a specific pet", + "operationId": "showPetById", + "tags": ["pets"], + "parameters": [ + { + "name": "petId", + "in": "path", + "required": true, + "description": "The id of the pet to retrieve", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Expected response to a valid request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Pets": { + "type": "array", + "maxItems": 100, + "items": { + "$ref": "#/components/schemas/Pet" + } + }, + "Error": { + "type": "object", + "required": ["code", "message"], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } +} diff --git a/tests/examples/v3.0/petstore.md b/tests/examples/v3.0/petstore.md new file mode 100644 index 0000000..e385167 --- /dev/null +++ b/tests/examples/v3.0/petstore.md @@ -0,0 +1,13 @@ +--- +layout: default +title: petstore +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/petstore.yaml b/tests/examples/v3.0/petstore.yaml new file mode 100644 index 0000000..98f62c1 --- /dev/null +++ b/tests/examples/v3.0/petstore.yaml @@ -0,0 +1,119 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT +servers: + - url: http://petstore.swagger.io/v1 +paths: + /pets: + get: + summary: List all pets + operationId: listPets + tags: + - pets + parameters: + - name: limit + in: query + description: How many items to return at one time (max 100) + required: false + schema: + type: integer + maximum: 100 + format: int32 + responses: + '200': + description: A paged array of pets + headers: + x-next: + description: A link to the next page of responses + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/Pets' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + post: + summary: Create a pet + operationId: createPets + tags: + - pets + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + required: true + responses: + '201': + description: Null response + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /pets/{petId}: + get: + summary: Info for a specific pet + operationId: showPetById + tags: + - pets + parameters: + - name: petId + in: path + required: true + description: The id of the pet to retrieve + schema: + type: string + responses: + '200': + description: Expected response to a valid request + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Pets: + type: array + maxItems: 100 + items: + $ref: '#/components/schemas/Pet' + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/tests/examples/v3.0/uspto.json b/tests/examples/v3.0/uspto.json new file mode 100644 index 0000000..81dfb0f --- /dev/null +++ b/tests/examples/v3.0/uspto.json @@ -0,0 +1,241 @@ +{ + "openapi": "3.0.1", + "servers": [ + { + "url": "{scheme}://developer.uspto.gov/ds-api", + "variables": { + "scheme": { + "description": "The Data Set API is accessible via https and http", + "enum": ["https", "http"], + "default": "https" + } + } + } + ], + "info": { + "description": "The Data Set API (DSAPI) allows the public users to discover and search USPTO exported data sets. This is a generic API that allows USPTO users to make any CSV based data files searchable through API. With the help of GET call, it returns the list of data fields that are searchable. With the help of POST call, data can be fetched based on the filters on the field names. Please note that POST call is used to search the actual data. The reason for the POST call is that it allows users to specify any complex search criteria without worry about the GET size limitations as well as encoding of the input parameters.", + "version": "1.0.0", + "title": "USPTO Data Set API", + "contact": { + "name": "Open Data Portal", + "url": "https://developer.uspto.gov", + "email": "developer@uspto.gov" + } + }, + "tags": [ + { + "name": "metadata", + "description": "Find out about the data sets" + }, + { + "name": "search", + "description": "Search a data set" + } + ], + "paths": { + "/": { + "get": { + "tags": ["metadata"], + "operationId": "list-data-sets", + "summary": "List available data sets", + "responses": { + "200": { + "description": "Returns a list of data sets", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/dataSetList" + }, + "example": { + "total": 2, + "apis": [ + { + "apiKey": "oa_citations", + "apiVersionNumber": "v1", + "apiUrl": "https://developer.uspto.gov/ds-api/oa_citations/v1/fields", + "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json" + }, + { + "apiKey": "cancer_moonshot", + "apiVersionNumber": "v1", + "apiUrl": "https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields", + "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json" + } + ] + } + } + } + } + } + } + }, + "/{dataset}/{version}/fields": { + "get": { + "tags": ["metadata"], + "summary": "Provides the general information about the API and the list of fields that can be used to query the dataset.", + "description": "This GET API returns the list of all the searchable field names that are in the oa_citations. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the syntax options shown below.", + "operationId": "list-searchable-fields", + "parameters": [ + { + "name": "dataset", + "in": "path", + "description": "Name of the dataset.", + "required": true, + "example": "oa_citations", + "schema": { + "type": "string" + } + }, + { + "name": "version", + "in": "path", + "description": "Version of the dataset.", + "required": true, + "example": "v1", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The dataset API for the given version is found and it is accessible to consume.", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + }, + "404": { + "description": "The combination of dataset name and version is not found in the system or it is not published yet to be consumed by public.", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/{dataset}/{version}/records": { + "post": { + "tags": ["search"], + "summary": "Provides search capability for the data set with the given search criteria.", + "description": "This API is based on Solr/Lucene Search. The data is indexed using SOLR. This GET API returns the list of all the searchable field names that are in the Solr Index. Please see the 'fields' attribute which returns an array of field names. Each field or a combination of fields can be searched using the Solr/Lucene Syntax. Please refer https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for the query syntax. List of field names that are searchable can be determined using above GET api.", + "operationId": "perform-search", + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Version of the dataset.", + "required": true, + "schema": { + "type": "string", + "default": "v1" + } + }, + { + "name": "dataset", + "in": "path", + "description": "Name of the dataset. In this case, the default value is oa_citations", + "required": true, + "schema": { + "type": "string", + "default": "oa_citations" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "404": { + "description": "No matching record found for the given criteria." + } + }, + "requestBody": { + "content": { + "application/x-www-form-urlencoded": { + "schema": { + "type": "object", + "properties": { + "criteria": { + "description": "Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.", + "type": "string", + "default": "*:*" + }, + "start": { + "description": "Starting record number. Default value is 0.", + "type": "integer", + "default": 0 + }, + "rows": { + "description": "Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.", + "type": "integer", + "default": 100 + } + }, + "required": ["criteria"] + } + } + } + } + } + } + }, + "components": { + "schemas": { + "dataSetList": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "apis": { + "type": "array", + "items": { + "type": "object", + "properties": { + "apiKey": { + "type": "string", + "description": "To be used as a dataset parameter value" + }, + "apiVersionNumber": { + "type": "string", + "description": "To be used as a version parameter value" + }, + "apiUrl": { + "type": "string", + "format": "uri-reference", + "description": "The URL describing the dataset's fields" + }, + "apiDocumentationUrl": { + "type": "string", + "format": "uri-reference", + "description": "A URL to the API console for each API" + } + } + } + } + } + } + } + } +} diff --git a/tests/examples/v3.0/uspto.md b/tests/examples/v3.0/uspto.md new file mode 100644 index 0000000..f5a5f50 --- /dev/null +++ b/tests/examples/v3.0/uspto.md @@ -0,0 +1,13 @@ +--- +layout: default +title: uspto +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.0/uspto.yaml b/tests/examples/v3.0/uspto.yaml new file mode 100644 index 0000000..ab87806 --- /dev/null +++ b/tests/examples/v3.0/uspto.yaml @@ -0,0 +1,210 @@ +openapi: 3.0.1 +servers: + - url: '{scheme}://developer.uspto.gov/ds-api' + variables: + scheme: + description: The Data Set API is accessible via https and http + enum: + - https + - http + default: https +info: + description: >- + The Data Set API (DSAPI) allows the public users to discover and search + USPTO exported data sets. This is a generic API that allows USPTO users to + make any CSV based data files searchable through API. With the help of GET + call, it returns the list of data fields that are searchable. With the help + of POST call, data can be fetched based on the filters on the field names. + Please note that POST call is used to search the actual data. The reason for + the POST call is that it allows users to specify any complex search criteria + without worry about the GET size limitations as well as encoding of the + input parameters. + version: 1.0.0 + title: USPTO Data Set API + contact: + name: Open Data Portal + url: https://developer.uspto.gov + email: developer@uspto.gov +tags: + - name: metadata + description: Find out about the data sets + - name: search + description: Search a data set +paths: + /: + get: + tags: + - metadata + operationId: list-data-sets + summary: List available data sets + responses: + '200': + description: Returns a list of data sets + content: + application/json: + schema: + $ref: '#/components/schemas/dataSetList' + example: + { + "total": 2, + "apis": [ + { + "apiKey": "oa_citations", + "apiVersionNumber": "v1", + "apiUrl": "https://developer.uspto.gov/ds-api/oa_citations/v1/fields", + "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json" + }, + { + "apiKey": "cancer_moonshot", + "apiVersionNumber": "v1", + "apiUrl": "https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields", + "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json" + } + ] + } + /{dataset}/{version}/fields: + get: + tags: + - metadata + summary: >- + Provides the general information about the API and the list of fields + that can be used to query the dataset. + description: >- + This GET API returns the list of all the searchable field names that are + in the oa_citations. Please see the 'fields' attribute which returns an + array of field names. Each field or a combination of fields can be + searched using the syntax options shown below. + operationId: list-searchable-fields + parameters: + - name: dataset + in: path + description: Name of the dataset. + required: true + example: oa_citations + schema: + type: string + - name: version + in: path + description: Version of the dataset. + required: true + example: v1 + schema: + type: string + responses: + '200': + description: >- + The dataset API for the given version is found and it is accessible + to consume. + content: + application/json: + schema: + type: string + '404': + description: >- + The combination of dataset name and version is not found in the + system or it is not published yet to be consumed by public. + content: + application/json: + schema: + type: string + /{dataset}/{version}/records: + post: + tags: + - search + summary: >- + Provides search capability for the data set with the given search + criteria. + description: >- + This API is based on Solr/Lucene Search. The data is indexed using + SOLR. This GET API returns the list of all the searchable field names + that are in the Solr Index. Please see the 'fields' attribute which + returns an array of field names. Each field or a combination of fields + can be searched using the Solr/Lucene Syntax. Please refer + https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for + the query syntax. List of field names that are searchable can be + determined using above GET api. + operationId: perform-search + parameters: + - name: version + in: path + description: Version of the dataset. + required: true + schema: + type: string + default: v1 + - name: dataset + in: path + description: Name of the dataset. In this case, the default value is oa_citations + required: true + schema: + type: string + default: oa_citations + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: array + items: + type: object + additionalProperties: + type: object + '404': + description: No matching record found for the given criteria. + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + criteria: + description: >- + Uses Lucene Query Syntax in the format of + propertyName:value, propertyName:[num1 TO num2] and date + range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the + response please see the 'docs' element which has the list of + record objects. Each record structure would consist of all + the fields and their corresponding values. + type: string + default: '*:*' + start: + description: Starting record number. Default value is 0. + type: integer + default: 0 + rows: + description: >- + Specify number of rows to be returned. If you run the search + with default values, in the response you will see 'numFound' + attribute which will tell the number of records available in + the dataset. + type: integer + default: 100 + required: + - criteria +components: + schemas: + dataSetList: + type: object + properties: + total: + type: integer + apis: + type: array + items: + type: object + properties: + apiKey: + type: string + description: To be used as a dataset parameter value + apiVersionNumber: + type: string + description: To be used as a version parameter value + apiUrl: + type: string + format: uri-reference + description: The URL describing the dataset's fields + apiDocumentationUrl: + type: string + format: uri-reference + description: A URL to the API console for each API diff --git a/tests/examples/v3.1/non-oauth-scopes.json b/tests/examples/v3.1/non-oauth-scopes.json new file mode 100644 index 0000000..6a39a72 --- /dev/null +++ b/tests/examples/v3.1/non-oauth-scopes.json @@ -0,0 +1,28 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Non-oAuth Scopes example", + "version": "1.0.0" + }, + "paths": { + "/users": { + "get": { + "security": [ + { + "bearerAuth": ["read:users", "public"] + } + ] + } + } + }, + "components": { + "securitySchemes": { + "bearerAuth": { + "type": "http", + "scheme": "bearer", + "bearerFormat": "jwt", + "description": "note: non-oauth scopes are not defined at the securityScheme level" + } + } + } +} diff --git a/tests/examples/v3.1/non-oauth-scopes.md b/tests/examples/v3.1/non-oauth-scopes.md new file mode 100644 index 0000000..7b1cd8c --- /dev/null +++ b/tests/examples/v3.1/non-oauth-scopes.md @@ -0,0 +1,13 @@ +--- +layout: default +title: non-oauth-scopes +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.1/non-oauth-scopes.yaml b/tests/examples/v3.1/non-oauth-scopes.yaml new file mode 100644 index 0000000..ac9fc8d --- /dev/null +++ b/tests/examples/v3.1/non-oauth-scopes.yaml @@ -0,0 +1,18 @@ +openapi: 3.1.0 +info: + title: Non-oAuth Scopes example + version: 1.0.0 +paths: + /users: + get: + security: + - bearerAuth: + - read:users + - public +components: + securitySchemes: + bearerAuth: + type: http + scheme: bearer + bearerFormat: jwt + description: 'note: non-oauth scopes are not defined at the securityScheme level' diff --git a/tests/examples/v3.1/tictactoe.json b/tests/examples/v3.1/tictactoe.json new file mode 100644 index 0000000..79f34cb --- /dev/null +++ b/tests/examples/v3.1/tictactoe.json @@ -0,0 +1,261 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Tic Tac Toe", + "description": "This API allows writing down marks on a Tic Tac Toe board\nand requesting the state of the board or of individual squares.\n", + "version": "1.0.0" + }, + "tags": [ + { + "name": "Gameplay" + } + ], + "paths": { + "/board": { + "get": { + "summary": "Get the whole board", + "description": "Retrieves the current state of the board and the winner.", + "tags": ["Gameplay"], + "operationId": "get-board", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/status" + } + } + } + } + }, + "security": [ + { + "defaultApiKey": [] + }, + { + "app2AppOauth": ["board:read"] + } + ] + } + }, + "/board/{row}/{column}": { + "parameters": [ + { + "$ref": "#/components/parameters/rowParam" + }, + { + "$ref": "#/components/parameters/columnParam" + } + ], + "get": { + "summary": "Get a single board square", + "description": "Retrieves the requested square.", + "tags": ["Gameplay"], + "operationId": "get-square", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/mark" + } + } + } + }, + "400": { + "description": "The provided parameters are incorrect", + "content": { + "text/html": { + "schema": { + "$ref": "#/components/schemas/errorMessage" + }, + "example": "Illegal coordinates" + } + } + } + }, + "security": [ + { + "bearerHttpAuthentication": [] + }, + { + "user2AppOauth": ["board:read"] + } + ] + }, + "put": { + "summary": "Set a single board square", + "description": "Places a mark on the board and retrieves the whole board and the winner (if any).", + "tags": ["Gameplay"], + "operationId": "put-square", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/mark" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/status" + } + } + } + }, + "400": { + "description": "The provided parameters are incorrect", + "content": { + "text/html": { + "schema": { + "$ref": "#/components/schemas/errorMessage" + }, + "examples": { + "illegalCoordinates": { + "value": "Illegal coordinates." + }, + "notEmpty": { + "value": "Square is not empty." + }, + "invalidMark": { + "value": "Invalid Mark (X or O)." + } + } + } + } + } + }, + "security": [ + { + "bearerHttpAuthentication": [] + }, + { + "user2AppOauth": ["board:write"] + } + ] + } + } + }, + "components": { + "parameters": { + "rowParam": { + "description": "Board row (vertical coordinate)", + "name": "row", + "in": "path", + "required": true, + "schema": { + "$ref": "#/components/schemas/coordinate" + } + }, + "columnParam": { + "description": "Board column (horizontal coordinate)", + "name": "column", + "in": "path", + "required": true, + "schema": { + "$ref": "#/components/schemas/coordinate" + } + } + }, + "schemas": { + "errorMessage": { + "type": "string", + "maxLength": 256, + "description": "A text message describing an error" + }, + "coordinate": { + "type": "integer", + "minimum": 1, + "maximum": 3, + "example": 1 + }, + "mark": { + "type": "string", + "enum": [".", "X", "O"], + "description": "Possible values for a board square. `.` means empty square.", + "example": "." + }, + "board": { + "type": "array", + "maxItems": 3, + "minItems": 3, + "items": { + "type": "array", + "maxItems": 3, + "minItems": 3, + "items": { + "$ref": "#/components/schemas/mark" + } + } + }, + "winner": { + "type": "string", + "enum": [".", "X", "O"], + "description": "Winner of the game. `.` means nobody has won yet.", + "example": "." + }, + "status": { + "type": "object", + "properties": { + "winner": { + "$ref": "#/components/schemas/winner" + }, + "board": { + "$ref": "#/components/schemas/board" + } + } + } + }, + "securitySchemes": { + "defaultApiKey": { + "description": "API key provided in console", + "type": "apiKey", + "name": "api-key", + "in": "header" + }, + "basicHttpAuthentication": { + "description": "Basic HTTP Authentication", + "type": "http", + "scheme": "Basic" + }, + "bearerHttpAuthentication": { + "description": "Bearer token using a JWT", + "type": "http", + "scheme": "Bearer", + "bearerFormat": "JWT" + }, + "app2AppOauth": { + "type": "oauth2", + "flows": { + "clientCredentials": { + "tokenUrl": "https://learn.openapis.org/oauth/2.0/token", + "scopes": { + "board:read": "Read the board" + } + } + } + }, + "user2AppOauth": { + "type": "oauth2", + "flows": { + "authorizationCode": { + "authorizationUrl": "https://learn.openapis.org/oauth/2.0/auth", + "tokenUrl": "https://learn.openapis.org/oauth/2.0/token", + "scopes": { + "board:read": "Read the board", + "board:write": "Write to the board" + } + } + } + } + } + } +} diff --git a/tests/examples/v3.1/tictactoe.md b/tests/examples/v3.1/tictactoe.md new file mode 100644 index 0000000..9d98f07 --- /dev/null +++ b/tests/examples/v3.1/tictactoe.md @@ -0,0 +1,13 @@ +--- +layout: default +title: tictactoe +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.1/tictactoe.yaml b/tests/examples/v3.1/tictactoe.yaml new file mode 100644 index 0000000..3753791 --- /dev/null +++ b/tests/examples/v3.1/tictactoe.yaml @@ -0,0 +1,186 @@ +openapi: 3.1.0 +info: + title: Tic Tac Toe + description: | + This API allows writing down marks on a Tic Tac Toe board + and requesting the state of the board or of individual squares. + version: 1.0.0 +tags: + - name: Gameplay +paths: + # Whole board operations + /board: + get: + summary: Get the whole board + description: Retrieves the current state of the board and the winner. + tags: + - Gameplay + operationId: get-board + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/status' + security: + - defaultApiKey: [] + - app2AppOauth: + - board:read + # Single square operations + /board/{row}/{column}: + parameters: + - $ref: '#/components/parameters/rowParam' + - $ref: '#/components/parameters/columnParam' + get: + summary: Get a single board square + description: Retrieves the requested square. + tags: + - Gameplay + operationId: get-square + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/mark' + '400': + description: The provided parameters are incorrect + content: + text/html: + schema: + $ref: '#/components/schemas/errorMessage' + example: Illegal coordinates + security: + - bearerHttpAuthentication: [] + - user2AppOauth: + - board:read + put: + summary: Set a single board square + description: Places a mark on the board and retrieves the whole board and the winner (if any). + tags: + - Gameplay + operationId: put-square + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/mark' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/status' + '400': + description: The provided parameters are incorrect + content: + text/html: + schema: + $ref: '#/components/schemas/errorMessage' + examples: + illegalCoordinates: + value: Illegal coordinates. + notEmpty: + value: Square is not empty. + invalidMark: + value: Invalid Mark (X or O). + security: + - bearerHttpAuthentication: [] + - user2AppOauth: + - board:write +components: + parameters: + rowParam: + description: Board row (vertical coordinate) + name: row + in: path + required: true + schema: + $ref: '#/components/schemas/coordinate' + columnParam: + description: Board column (horizontal coordinate) + name: column + in: path + required: true + schema: + $ref: '#/components/schemas/coordinate' + schemas: + errorMessage: + type: string + maxLength: 256 + description: A text message describing an error + coordinate: + type: integer + minimum: 1 + maximum: 3 + example: 1 + mark: + type: string + enum: + - . + - X + - O + description: Possible values for a board square. `.` means empty square. + example: . + board: + type: array + maxItems: 3 + minItems: 3 + items: + type: array + maxItems: 3 + minItems: 3 + items: + $ref: '#/components/schemas/mark' + winner: + type: string + enum: + - . + - X + - O + description: Winner of the game. `.` means nobody has won yet. + example: . + status: + type: object + properties: + winner: + $ref: '#/components/schemas/winner' + board: + $ref: '#/components/schemas/board' + securitySchemes: + defaultApiKey: + description: API key provided in console + type: apiKey + name: api-key + in: header + basicHttpAuthentication: + description: Basic HTTP Authentication + type: http + scheme: Basic + bearerHttpAuthentication: + description: Bearer token using a JWT + type: http + scheme: Bearer + bearerFormat: JWT + app2AppOauth: + type: oauth2 + flows: + clientCredentials: + tokenUrl: https://learn.openapis.org/oauth/2.0/token + scopes: + # Only reading the board allow with delegated access + board:read: Read the board + user2AppOauth: + type: oauth2 + flows: + authorizationCode: + authorizationUrl: https://learn.openapis.org/oauth/2.0/auth + tokenUrl: https://learn.openapis.org/oauth/2.0/token + scopes: + # Reads and writes permitted via authorization code flow + board:read: Read the board + board:write: Write to the board diff --git a/tests/examples/v3.1/webhook-example.json b/tests/examples/v3.1/webhook-example.json new file mode 100644 index 0000000..ad0dac9 --- /dev/null +++ b/tests/examples/v3.1/webhook-example.json @@ -0,0 +1,48 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Webhook Example", + "version": "1.0.0" + }, + "webhooks": { + "newPet": { + "post": { + "requestBody": { + "description": "Information about a new pet in the system", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "responses": { + "200": { + "description": "Return a 200 status to indicate that the data was received successfully" + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + } + } +} diff --git a/tests/examples/v3.1/webhook-example.md b/tests/examples/v3.1/webhook-example.md new file mode 100644 index 0000000..c3ce2ed --- /dev/null +++ b/tests/examples/v3.1/webhook-example.md @@ -0,0 +1,13 @@ +--- +layout: default +title: webhook-example +parent: Example API Descriptions +--- + +{% comment %} +{% capture description %} +Insert description here, then remove comment tag above and endcomment tag below +{% endcapture %} +{% endcomment %} + +{% include example-api-description.md name=page.title description=description %} diff --git a/tests/examples/v3.1/webhook-example.yaml b/tests/examples/v3.1/webhook-example.yaml new file mode 100644 index 0000000..4c08cf9 --- /dev/null +++ b/tests/examples/v3.1/webhook-example.yaml @@ -0,0 +1,34 @@ +openapi: 3.1.0 +info: + title: Webhook Example + version: 1.0.0 +# Since OAS 3.1.0 the paths element isn't necessary. Now a valid OpenAPI Document can describe only paths, webhooks, or even only reusable components +webhooks: + # Each webhook needs a name + newPet: + # This is a Path Item Object, the only difference is that the request is initiated by the API provider + post: + requestBody: + description: Information about a new pet in the system + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + responses: + '200': + description: Return a 200 status to indicate that the data was received successfully +components: + schemas: + Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/tests/lib2to3/test_convert.py b/tests/lib2to3/test_convert.py index 84b978b..c8e4950 100644 --- a/tests/lib2to3/test_convert.py +++ b/tests/lib2to3/test_convert.py @@ -4,9 +4,7 @@ def test_minimal(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -17,11 +15,8 @@ def test_minimal(oas_fragment): responses: '200': description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -32,14 +27,11 @@ def test_minimal(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_complete(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -53,11 +45,8 @@ def test_complete(oas_fragment): responses: '200': description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -71,14 +60,12 @@ def test_complete(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_servers_complete(oas_fragment): converted = lib2to3.convert( - oas_fragment( - """ + oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -93,11 +80,9 @@ def test_servers_complete(oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -110,14 +95,12 @@ def test_servers_complete(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_servers_host_only(oas_fragment): converted = lib2to3.convert( - oas_fragment( - """ + oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -129,11 +112,9 @@ def test_servers_host_only(oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -146,14 +127,12 @@ def test_servers_host_only(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_servers_basepath_only(oas_fragment): converted = lib2to3.convert( - oas_fragment( - """ + oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -165,11 +144,9 @@ def test_servers_basepath_only(oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -182,14 +159,12 @@ def test_servers_basepath_only(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_servers_schemes_multiple(oas_fragment): converted = lib2to3.convert( - oas_fragment( - """ + oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -204,11 +179,9 @@ def test_servers_schemes_multiple(oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -222,14 +195,12 @@ def test_servers_schemes_multiple(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_servers_schemes_from_operation(oas_fragment): converted = lib2to3.convert( - oas_fragment( - """ + oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -245,11 +216,9 @@ def test_servers_schemes_from_operation(oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -263,14 +232,11 @@ def test_servers_schemes_from_operation(oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_consumes(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -291,11 +257,8 @@ def test_consumes(oas_fragment): responses: '201': description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -316,14 +279,11 @@ def test_consumes(oas_fragment): responses: '201': description: a response description - """ - ) + """) def test_consumes_operation_override(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -346,11 +306,8 @@ def test_consumes_operation_override(oas_fragment): responses: '201': description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -371,14 +328,11 @@ def test_consumes_operation_override(oas_fragment): responses: '201': description: a response description - """ - ) + """) def test_produces(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -396,11 +350,8 @@ def test_produces(oas_fragment): type: integer type: array description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -418,14 +369,11 @@ def test_produces(oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_produces_operation_override(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -445,11 +393,8 @@ def test_produces_operation_override(oas_fragment): type: integer type: array description: a response description - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -467,14 +412,11 @@ def test_produces_operation_override(oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_vendor_extensions(oas_fragment): - converted = lib2to3.convert( - oas_fragment( - """ + converted = lib2to3.convert(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -486,11 +428,8 @@ def test_vendor_extensions(oas_fragment): '200': description: a response description x-vendor-ext: vendor-ext - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -502,5 +441,4 @@ def test_vendor_extensions(oas_fragment): '200': description: a response description x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_operation.py b/tests/lib2to3/test_convert_operation.py index 831d4ce..c69de84 100644 --- a/tests/lib2to3/test_convert_operation.py +++ b/tests/lib2to3/test_convert_operation.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_operation(oas_fragment): def _wrapper(operation): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(operation): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"] = operation oas3 = lib2to3.convert(oas2) @@ -32,27 +30,22 @@ def _wrapper(operation): def test_minimal(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" responses: '200': description: a response description - """ - ) + """) def test_complete(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" tags: - tag_a - tag_b @@ -82,11 +75,9 @@ def test_complete(convert_operation, oas_fragment): format: int32 type: integer type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" tags: - tag_a - tag_b @@ -119,14 +110,12 @@ def test_complete(convert_operation, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_request_body(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" description: an operation description consumes: - application/json @@ -146,11 +135,9 @@ def test_request_body(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: an operation description parameters: - in: path @@ -170,14 +157,12 @@ def test_request_body(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_request_body_formdata(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" description: an operation description consumes: - application/x-www-form-urlencoded @@ -192,11 +177,9 @@ def test_request_body_formdata(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: an operation description parameters: - in: path @@ -215,14 +198,12 @@ def test_request_body_formdata(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_only_request_body(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" description: an operation description consumes: - application/json @@ -238,11 +219,9 @@ def test_only_request_body(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: an operation description requestBody: content: @@ -256,26 +235,21 @@ def test_only_request_body(convert_operation, oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_vendor_extensions(convert_operation, oas_fragment): converted = convert_operation( - oas_fragment( - """ + oas_fragment(""" responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_parameter.py b/tests/lib2to3/test_convert_parameter.py index 0585832..3dd5188 100644 --- a/tests/lib2to3/test_convert_parameter.py +++ b/tests/lib2to3/test_convert_parameter.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_parameter(oas_fragment): def _wrapper(parameter): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(parameter): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"]["parameters"] = [parameter] oas3 = lib2to3.convert(oas2) @@ -31,9 +29,7 @@ def _wrapper(parameter): def test_in_header_complete(convert_parameter, oas_fragment): - converted = convert_parameter( - oas_fragment( - """ + converted = convert_parameter(oas_fragment(""" description: token to be passed as a header in: header items: @@ -42,11 +38,8 @@ def test_in_header_complete(convert_parameter, oas_fragment): name: token required: true type: array - """ - ) - ) - assert converted == oas_fragment( - """ + """)) + assert converted == oas_fragment(""" description: token to be passed as a header in: header name: token @@ -56,38 +49,32 @@ def test_in_header_complete(convert_parameter, oas_fragment): format: int64 type: integer type: array - """ - ) + """) def test_in_path_complete(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" description: username to fetch in: path name: username required: true type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: username to fetch in: path name: username required: true schema: type: string - """ - ) + """) def test_in_query_complete(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" description: ID of the object to fetch in: query items: @@ -95,11 +82,9 @@ def test_in_query_complete(convert_parameter, oas_fragment): name: id required: false type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: ID of the object to fetch in: query name: id @@ -108,76 +93,62 @@ def test_in_query_complete(convert_parameter, oas_fragment): items: type: string type: array - """ - ) + """) def test_in_header_minimal(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: header name: token type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: header name: token schema: type: string - """ - ) + """) def test_in_path_minimal(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: path name: username required: true type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: path name: username required: true schema: type: string - """ - ) + """) def test_in_query_minimal(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: query name: id type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: query name: id schema: type: string - """ - ) + """) def test_collectionFormat_is_csv_path(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: csv in: path items: @@ -185,11 +156,9 @@ def test_collectionFormat_is_csv_path(convert_parameter, oas_fragment): name: username required: true type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: path name: username required: true @@ -198,25 +167,21 @@ def test_collectionFormat_is_csv_path(convert_parameter, oas_fragment): type: string type: array style: simple - """ - ) + """) def test_collectionFormat_is_csv_header(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: csv in: header items: type: string name: username type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: header name: username schema: @@ -224,25 +189,21 @@ def test_collectionFormat_is_csv_header(convert_parameter, oas_fragment): type: string type: array style: simple - """ - ) + """) def test_collectionFormat_is_csv(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: csv in: query items: type: string name: id type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" explode: false in: query name: id @@ -251,25 +212,21 @@ def test_collectionFormat_is_csv(convert_parameter, oas_fragment): type: string type: array style: form - """ - ) + """) def test_collectionFormat_is_multi(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: multi in: query items: type: string name: id type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" explode: true in: query name: id @@ -278,25 +235,21 @@ def test_collectionFormat_is_multi(convert_parameter, oas_fragment): type: string type: array style: form - """ - ) + """) def test_collectionFormat_is_ssv(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: ssv in: query items: type: string name: id type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: query name: id schema: @@ -304,25 +257,21 @@ def test_collectionFormat_is_ssv(convert_parameter, oas_fragment): type: string type: array style: spaceDelimited - """ - ) + """) def test_collectionFormat_is_pipes(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: pipes in: query items: type: string name: id type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: query name: id schema: @@ -330,98 +279,81 @@ def test_collectionFormat_is_pipes(convert_parameter, oas_fragment): type: string type: array style: pipeDelimited - """ - ) + """) def test_collectionFormat_is_tsv(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" collectionFormat: tsv in: query items: type: string name: id type: array - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: query name: id schema: items: type: string type: array - """ - ) + """) def test_in_header_vendor_extensions(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: header name: token type: string x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: header name: token schema: type: string x-vendor-ext: vendor-ext - """ - ) + """) def test_in_path_vendor_extensions(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: path name: username required: true type: string x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: path name: username required: true schema: type: string x-vendor-ext: vendor-ext - """ - ) + """) def test_in_query_vendor_extensions(convert_parameter, oas_fragment): converted = convert_parameter( - oas_fragment( - """ + oas_fragment(""" in: query name: id type: string x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" in: query name: id schema: type: string x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_parameters.py b/tests/lib2to3/test_convert_parameters.py index 3351bf7..4d8563c 100644 --- a/tests/lib2to3/test_convert_parameters.py +++ b/tests/lib2to3/test_convert_parameters.py @@ -4,15 +4,13 @@ import sphinxcontrib.openapi._lib2to3 as lib2to3 - _MISSING = object() @pytest.fixture(scope="function") def convert_parameters(oas_fragment): def _wrapper(parameters): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -23,8 +21,7 @@ def _wrapper(parameters): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"]["parameters"] = parameters oas3 = lib2to3.convert(oas2) @@ -35,8 +32,7 @@ def _wrapper(parameters): def test_header_path_query(convert_parameters, oas_fragment): converted = convert_parameters( - oas_fragment( - """ + oas_fragment(""" - in: header name: token type: string @@ -47,11 +43,9 @@ def test_header_path_query(convert_parameters, oas_fragment): - in: query name: id type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" - in: header name: token schema: @@ -65,36 +59,31 @@ def test_header_path_query(convert_parameters, oas_fragment): name: id schema: type: string - """ - ) + """) def test_body_is_ignored(convert_parameters, oas_fragment): converted = convert_parameters( - oas_fragment( - """ + oas_fragment(""" - description: user to add to the system in: body name: user required: true schema: $ref: '#/definitions/User' - """ - ), + """), ) assert converted is _MISSING def test_formData_is_ignored(convert_parameters, oas_fragment): converted = convert_parameters( - oas_fragment( - """ + oas_fragment(""" - description: The avatar of the user in: formData name: avatar type: file - """ - ), + """), ) assert converted is _MISSING diff --git a/tests/lib2to3/test_convert_path.py b/tests/lib2to3/test_convert_path.py index 4d7e1cd..b0c184a 100644 --- a/tests/lib2to3/test_convert_path.py +++ b/tests/lib2to3/test_convert_path.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_path(oas_fragment): def _wrapper(path): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(path): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"] = path oas3 = lib2to3.convert(oas2) @@ -35,29 +33,24 @@ def _wrapper(path): ) def test_minimal(convert_path, oas_fragment, method): converted = convert_path( - oas_fragment( - f""" + oas_fragment(f""" {method}: responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - f""" + assert converted == oas_fragment(f""" {method}: responses: '200': description: a response description - """ - ) + """) def test_complete(convert_path, oas_fragment): converted = convert_path( - oas_fragment( - """ + oas_fragment(""" parameters: - in: path name: username @@ -88,11 +81,9 @@ def test_complete(convert_path, oas_fragment): type: integer type: array description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" parameters: - in: path name: username @@ -126,14 +117,12 @@ def test_complete(convert_path, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_shared_parameters(convert_path, oas_fragment): converted = convert_path( - oas_fragment( - """ + oas_fragment(""" parameters: - in: path name: username @@ -150,11 +139,9 @@ def test_shared_parameters(convert_path, oas_fragment): responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" parameters: - in: path name: username @@ -174,14 +161,12 @@ def test_shared_parameters(convert_path, oas_fragment): responses: '200': description: a response description - """ - ) + """) def test_multiple(convert_path, oas_fragment): converted = convert_path( - oas_fragment( - """ + oas_fragment(""" post: responses: '201': @@ -190,11 +175,9 @@ def test_multiple(convert_path, oas_fragment): responses: '200': description: a get response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" post: responses: '201': @@ -203,28 +186,23 @@ def test_multiple(convert_path, oas_fragment): responses: '200': description: a get response description - """ - ) + """) def test_vendor_extensions(convert_path, oas_fragment): converted = convert_path( - oas_fragment( - """ + oas_fragment(""" get: responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" get: responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_paths.py b/tests/lib2to3/test_convert_paths.py index 76efdb8..4b602d6 100644 --- a/tests/lib2to3/test_convert_paths.py +++ b/tests/lib2to3/test_convert_paths.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_paths(oas_fragment): def _wrapper(paths): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(paths): responses: '200': description: a response description - """ - ) + """) oas2["paths"] = paths oas3 = lib2to3.convert(oas2) @@ -32,32 +30,27 @@ def _wrapper(paths): def test_minimal(convert_paths, oas_fragment): converted = convert_paths( - oas_fragment( - """ + oas_fragment(""" /test: get: responses: '200': description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" /test: get: responses: '200': description: a response description - """ - ) + """) def test_complete(convert_paths, oas_fragment): pass converted = convert_paths( - oas_fragment( - """ + oas_fragment(""" /{username}: parameters: - in: path @@ -89,11 +82,9 @@ def test_complete(convert_paths, oas_fragment): type: integer type: array description: a response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" /{username}: parameters: - in: path @@ -128,14 +119,12 @@ def test_complete(convert_paths, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_multiple(convert_paths, oas_fragment): converted = convert_paths( - oas_fragment( - """ + oas_fragment(""" /test: get: responses: @@ -146,11 +135,9 @@ def test_multiple(convert_paths, oas_fragment): responses: '201': description: an eggs response description - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" /test: get: responses: @@ -161,30 +148,25 @@ def test_multiple(convert_paths, oas_fragment): responses: '201': description: an eggs response description - """ - ) + """) def test_vendor_extensions(convert_paths, oas_fragment): converted = convert_paths( - oas_fragment( - """ + oas_fragment(""" /test: get: responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" /test: get: responses: '200': description: a response description x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_request_body.py b/tests/lib2to3/test_convert_request_body.py index 60bca9f..0f52396 100644 --- a/tests/lib2to3/test_convert_request_body.py +++ b/tests/lib2to3/test_convert_request_body.py @@ -4,15 +4,13 @@ import sphinxcontrib.openapi._lib2to3 as lib2to3 - _MISSING = object() @pytest.fixture(scope="function") def convert_request_body(oas_fragment): def _wrapper(operation_fragment): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -23,8 +21,7 @@ def _wrapper(operation_fragment): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"].update(operation_fragment) oas3 = lib2to3.convert(oas2) @@ -35,8 +32,7 @@ def _wrapper(operation_fragment): def test_minimal(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/json parameters: @@ -44,23 +40,19 @@ def test_minimal(convert_request_body, oas_fragment): name: user schema: $ref: '#/definitions/User' - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: schema: $ref: '#/definitions/User' - """ - ) + """) def test_complete(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/json parameters: @@ -70,47 +62,39 @@ def test_complete(convert_request_body, oas_fragment): required: true schema: $ref: '#/definitions/User' - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: schema: $ref: '#/definitions/User' description: user to add to the system required: true - """ - ) + """) def test_no_consumes(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - in: body name: user schema: $ref: '#/definitions/User' - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: '*/*': schema: $ref: '#/definitions/User' - """ - ) + """) def test_header_path_query_are_ignored(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - in: header name: token @@ -122,16 +106,14 @@ def test_header_path_query_are_ignored(convert_request_body, oas_fragment): - in: query name: id type: string - """ - ), + """), ) assert converted is _MISSING def test_body_and_others(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - in: header name: token @@ -147,14 +129,11 @@ def test_body_and_others(convert_request_body, oas_fragment): - in: query name: id type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: '*/*': schema: $ref: '#/definitions/User' - """ - ) + """) diff --git a/tests/lib2to3/test_convert_request_body_formdata.py b/tests/lib2to3/test_convert_request_body_formdata.py index a0ce9ca..7ea8848 100644 --- a/tests/lib2to3/test_convert_request_body_formdata.py +++ b/tests/lib2to3/test_convert_request_body_formdata.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_request_body(oas_fragment): def _wrapper(operation_fragment): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(operation_fragment): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"].update(operation_fragment) oas3 = lib2to3.convert(oas2) @@ -32,17 +30,14 @@ def _wrapper(operation_fragment): def test_minimal(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -50,25 +45,21 @@ def test_minimal(convert_request_body, oas_fragment): user: type: string type: object - """ - ) + """) def test_complete(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - description: a name of the user in: formData name: user type: string required: true - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -78,14 +69,12 @@ def test_complete(convert_request_body, oas_fragment): description: a name of the user type: string required: [user] - """ - ) + """) def test_complex_schema(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - format: int32 in: formData @@ -93,11 +82,9 @@ def test_complex_schema(convert_request_body, oas_fragment): minimum: 5 name: age type: integer - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -108,14 +95,12 @@ def test_complex_schema(convert_request_body, oas_fragment): minimum: 5 type: integer type: object - """ - ) + """) def test_consumes_urlencoded(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/x-www-form-urlencoded parameters: @@ -123,11 +108,9 @@ def test_consumes_urlencoded(convert_request_body, oas_fragment): in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -136,14 +119,12 @@ def test_consumes_urlencoded(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) def test_consumes_form_data(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - multipart/form-data parameters: @@ -151,11 +132,9 @@ def test_consumes_form_data(convert_request_body, oas_fragment): in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: multipart/form-data: schema: @@ -164,14 +143,12 @@ def test_consumes_form_data(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) def test_consumes_urlencoded_and_form_data(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/x-www-form-urlencoded - multipart/form-data @@ -180,11 +157,9 @@ def test_consumes_urlencoded_and_form_data(convert_request_body, oas_fragment): in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -200,25 +175,21 @@ def test_consumes_urlencoded_and_form_data(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) def test_required(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - description: a name of the user in: formData name: user required: true type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -229,14 +200,12 @@ def test_required(convert_request_body, oas_fragment): required: - user type: object - """ - ) + """) def test_multiple(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - description: a name of the user in: formData @@ -246,11 +215,9 @@ def test_multiple(convert_request_body, oas_fragment): in: formData name: status type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -262,24 +229,20 @@ def test_multiple(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) def test_type_file_implicit_form_data(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" parameters: - description: a user pic in: formData name: userpic type: file - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: multipart/form-data: schema: @@ -288,14 +251,12 @@ def test_type_file_implicit_form_data(convert_request_body, oas_fragment): description: a user pic type: file type: object - """ - ) + """) def test_type_file_consumes_form_data(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - multipart/form-data parameters: @@ -303,11 +264,9 @@ def test_type_file_consumes_form_data(convert_request_body, oas_fragment): in: formData name: userpic type: file - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: multipart/form-data: schema: @@ -316,14 +275,12 @@ def test_type_file_consumes_form_data(convert_request_body, oas_fragment): description: a user pic type: file type: object - """ - ) + """) def test_consumes_json_and_urlencoded(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/json - application/x-www-form-urlencoded @@ -332,11 +289,9 @@ def test_consumes_json_and_urlencoded(convert_request_body, oas_fragment): in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/x-www-form-urlencoded: schema: @@ -345,14 +300,12 @@ def test_consumes_json_and_urlencoded(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) def test_consumes_json_and_form_data(convert_request_body, oas_fragment): converted = convert_request_body( - oas_fragment( - """ + oas_fragment(""" consumes: - application/json - multipart/form-data @@ -361,11 +314,9 @@ def test_consumes_json_and_form_data(convert_request_body, oas_fragment): in: formData name: user type: string - """ - ), + """), ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: multipart/form-data: schema: @@ -374,5 +325,4 @@ def test_consumes_json_and_form_data(convert_request_body, oas_fragment): description: a name of the user type: string type: object - """ - ) + """) diff --git a/tests/lib2to3/test_convert_response.py b/tests/lib2to3/test_convert_response.py index 640355f..aacad6b 100644 --- a/tests/lib2to3/test_convert_response.py +++ b/tests/lib2to3/test_convert_response.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_response(oas_fragment): def _wrapper(response, produces): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(response, produces): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"]["responses"]["200"] = response oas2["paths"]["/test"]["get"]["produces"] = produces @@ -33,36 +31,29 @@ def _wrapper(response, produces): def test_minimal(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description - """ - ) + """) def test_schema(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description schema: items: format: int32 type: integer type: array - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: schema: @@ -71,26 +62,22 @@ def test_schema(convert_response, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_schema_mimetypes(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description schema: items: format: int32 type: integer type: array - """ - ), + """), produces=["application/json", "text/plain"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: schema: @@ -105,26 +92,22 @@ def test_schema_mimetypes(convert_response, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_schema_no_mimetypes(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description schema: items: format: int32 type: integer type: array - """ - ), + """), produces=None, ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: '*/*': schema: @@ -133,69 +116,57 @@ def test_schema_no_mimetypes(convert_response, oas_fragment): type: integer type: array description: a response description - """ - ) + """) def test_examples(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: something: important - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: example: something: important description: a response description - """ - ) + """) def test_examples_any_type(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: '{"something": "important"}' - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: example: '{"something": "important"}' description: a response description - """ - ) + """) def test_examples_mimetypes(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: something: important text/plain: something=imporant - """ - ), + """), produces=["application/json", "text/plain"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" content: application/json: example: @@ -203,62 +174,52 @@ def test_examples_mimetypes(convert_response, oas_fragment): text/plain: example: something=imporant description: a response description - """ - ) + """) def test_headers_schema_only(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description headers: X-Test: type: string - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description headers: X-Test: schema: type: string - """ - ) + """) def test_headers_schema_extra(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description headers: X-Test: description: Is it a test? type: string - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description headers: X-Test: description: Is it a test? schema: type: string - """ - ) + """) def test_headers_multiple(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description headers: X-Bar: @@ -266,12 +227,10 @@ def test_headers_multiple(convert_response, oas_fragment): type: integer X-Foo: type: string - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description headers: X-Bar: @@ -281,14 +240,12 @@ def test_headers_multiple(convert_response, oas_fragment): X-Foo: schema: type: string - """ - ) + """) def test_schema_examples_headers(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: @@ -302,12 +259,10 @@ def test_schema_examples_headers(convert_response, oas_fragment): format: int32 type: integer type: array - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description content: application/json: @@ -323,14 +278,12 @@ def test_schema_examples_headers(convert_response, oas_fragment): description: Is it a test? schema: type: string - """ - ) + """) def test_complete(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: @@ -344,12 +297,10 @@ def test_complete(convert_response, oas_fragment): format: int32 type: integer type: array - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description content: application/json: @@ -365,14 +316,12 @@ def test_complete(convert_response, oas_fragment): description: Is it a test? schema: type: string - """ - ) + """) def test_vendor_extensions(convert_response, oas_fragment): converted = convert_response( - oas_fragment( - """ + oas_fragment(""" description: a response description examples: application/json: @@ -389,12 +338,10 @@ def test_vendor_extensions(convert_response, oas_fragment): type: array x-schema-ext: schema-ext x-response-ext: response-ext - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" description: a response description content: application/json: @@ -413,5 +360,4 @@ def test_vendor_extensions(convert_response, oas_fragment): type: string x-header-ext: header-ext x-response-ext: response-ext - """ - ) + """) diff --git a/tests/lib2to3/test_convert_responses.py b/tests/lib2to3/test_convert_responses.py index 7022b50..2630ac9 100644 --- a/tests/lib2to3/test_convert_responses.py +++ b/tests/lib2to3/test_convert_responses.py @@ -8,8 +8,7 @@ @pytest.fixture(scope="function") def convert_responses(oas_fragment): def _wrapper(responses, produces): - oas2 = oas_fragment( - """ + oas2 = oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -20,8 +19,7 @@ def _wrapper(responses, produces): responses: '200': description: a response description - """ - ) + """) oas2["paths"]["/test"]["get"]["responses"] = responses oas2["paths"]["/test"]["get"]["produces"] = produces @@ -33,26 +31,21 @@ def _wrapper(responses, produces): def test_minimal(convert_responses, oas_fragment): converted = convert_responses( - oas_fragment( - """ + oas_fragment(""" '200': description: a response description - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" '200': description: a response description - """ - ) + """) def test_complete(convert_responses, oas_fragment): converted = convert_responses( - oas_fragment( - """ + oas_fragment(""" '200': description: a response description examples: @@ -67,12 +60,10 @@ def test_complete(convert_responses, oas_fragment): format: int32 type: integer type: array - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" '200': description: a response description content: @@ -89,14 +80,12 @@ def test_complete(convert_responses, oas_fragment): description: Is it a test? schema: type: string - """ - ) + """) def test_multiple(convert_responses, oas_fragment): converted = convert_responses( - oas_fragment( - """ + oas_fragment(""" '200': description: OK schema: @@ -112,12 +101,10 @@ def test_multiple(convert_responses, oas_fragment): type: string default: description: Internal Server Error - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" '200': content: application/json: @@ -136,25 +123,20 @@ def test_multiple(convert_responses, oas_fragment): type: string default: description: Internal Server Error - """ - ) + """) def test_vendor_extensions(convert_responses, oas_fragment): converted = convert_responses( - oas_fragment( - """ + oas_fragment(""" '200': description: a response description x-vendor-ext: vendor-ext - """ - ), + """), produces=["application/json"], ) - assert converted == oas_fragment( - """ + assert converted == oas_fragment(""" '200': description: a response description x-vendor-ext: vendor-ext - """ - ) + """) diff --git a/tests/renderers/httpdomain/test_render_json_schema_description.py b/tests/renderers/httpdomain/test_render_json_schema_description.py index e25ca53..b9bc51c 100644 --- a/tests/renderers/httpdomain/test_render_json_schema_description.py +++ b/tests/renderers/httpdomain/test_render_json_schema_description.py @@ -25,8 +25,7 @@ def test_render_json_schema_description_root_object( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: prop_a: @@ -38,13 +37,11 @@ def test_render_json_schema_description_root_object( type: boolean prop_c: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop_a: :{typedirective} prop_a: string :{directive} prop_b: @@ -53,8 +50,7 @@ def test_render_json_schema_description_root_object( :{typedirective} prop_b.eggs: boolean :{directive} prop_c: :{typedirective} prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -71,25 +67,21 @@ def test_render_json_schema_description_root_array( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: array items: type: object properties: prop: type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop: :{typedirective} prop: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -116,18 +108,14 @@ def test_render_json_schema_description_root_unsupported( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - f""" + oas_fragment(f""" type: {schema_type} - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - """\ - """.rstrip() - ) + assert markup == textwrap.dedent("""\ + """.rstrip()) @pytest.mark.parametrize( @@ -144,8 +132,7 @@ def test_render_json_schema_description_root_any_of_object( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" anyOf: - type: object properties: @@ -160,19 +147,16 @@ def test_render_json_schema_description_root_any_of_object( properties: eggs: type: boolean - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop_a: :{typedirective} prop_a: string :{directive} prop_b: :{typedirective} prop_b: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -189,8 +173,7 @@ def test_render_json_schema_description_root_any_of_array( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" anyOf: - type: array items: @@ -204,17 +187,14 @@ def test_render_json_schema_description_root_any_of_array( properties: prop: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop: :{typedirective} prop: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -241,20 +221,16 @@ def test_render_json_schema_description_root_any_of_unsupported( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - f""" + oas_fragment(f""" anyOf: - type: {schema_type} - type: object - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - """\ - """.rstrip() - ) + assert markup == textwrap.dedent("""\ + """.rstrip()) @pytest.mark.parametrize( @@ -271,8 +247,7 @@ def test_render_json_schema_description_root_one_of_object( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" oneOf: - type: object properties: @@ -287,19 +262,16 @@ def test_render_json_schema_description_root_one_of_object( properties: eggs: type: boolean - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop_a: :{typedirective} prop_a: string :{directive} prop_b: :{typedirective} prop_b: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -316,8 +288,7 @@ def test_render_json_schema_description_root_one_of_array( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" oneOf: - type: array items: @@ -331,17 +302,14 @@ def test_render_json_schema_description_root_one_of_array( properties: prop: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} prop: :{typedirective} prop: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -368,20 +336,16 @@ def test_render_json_schema_description_root_one_of_unsupported( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - f""" + oas_fragment(f""" oneOf: - type: {schema_type} - type: object - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - """\ - """.rstrip() - ) + assert markup == textwrap.dedent("""\ + """.rstrip()) @pytest.mark.parametrize( @@ -398,8 +362,7 @@ def test_render_json_schema_description_root_all_of_object( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" allOf: - properties: name: @@ -413,13 +376,11 @@ def test_render_json_schema_description_root_all_of_object( properties: last: type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} name: :{typedirective} name: object :{directive} name.first: @@ -428,8 +389,7 @@ def test_render_json_schema_description_root_all_of_object( :{typedirective} name.last: string :{directive} age: :{typedirective} age: integer - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -456,23 +416,19 @@ def test_render_json_schema_description_primitive( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - f""" + oas_fragment(f""" type: object properties: some_key: type: "{schema_type}" - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: {schema_type} - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -489,8 +445,7 @@ def test_render_json_schema_description_object( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -505,13 +460,11 @@ def test_render_json_schema_description_object( type: boolean prop_c: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: object :{directive} root.prop_a: @@ -522,8 +475,7 @@ def test_render_json_schema_description_object( :{typedirective} root.prop_b.eggs: boolean :{directive} root.prop_c: :{typedirective} root.prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -540,8 +492,7 @@ def test_render_json_schema_description_object_implicit( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -554,13 +505,11 @@ def test_render_json_schema_description_object_implicit( type: boolean prop_c: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: object :{directive} root.prop_a: @@ -571,8 +520,7 @@ def test_render_json_schema_description_object_implicit( :{typedirective} root.prop_b.eggs: boolean :{directive} root.prop_c: :{typedirective} root.prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -589,8 +537,7 @@ def test_render_json_schema_description_array( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -606,13 +553,11 @@ def test_render_json_schema_description_array( type: number prop_c: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root[]: :{typedirective} root[]: object :{directive} root[].prop_a: @@ -621,8 +566,7 @@ def test_render_json_schema_description_array( :{typedirective} root[].prop_b[]: number :{directive} root[].prop_c: :{typedirective} root[].prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -639,8 +583,7 @@ def test_render_json_schema_description_array_implicit( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -654,13 +597,11 @@ def test_render_json_schema_description_array_implicit( type: number prop_c: type: number - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root[]: :{typedirective} root[]: object :{directive} root[].prop_a: @@ -669,8 +610,7 @@ def test_render_json_schema_description_array_implicit( :{typedirective} root[].prop_b[]: number :{directive} root[].prop_c: :{typedirective} root[].prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -687,24 +627,20 @@ def test_render_json_schema_description_format( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: created_at: type: string format: date-time - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: :{typedirective} created_at: string:date-time - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -721,24 +657,20 @@ def test_render_json_schema_description_deprecated( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: created_at: type: string deprecated: true - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: :{typedirective} created_at: string, deprecated - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -755,8 +687,7 @@ def test_render_json_schema_description_required( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -773,13 +704,11 @@ def test_render_json_schema_description_required( prop_c: type: number required: [prop_a] - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: object :{directive} root.prop_a: @@ -790,8 +719,7 @@ def test_render_json_schema_description_required( :{typedirective} root.prop_b.eggs: boolean, required :{directive} root.prop_c: :{typedirective} root.prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -808,8 +736,7 @@ def test_render_json_schema_description_deprecated_and_required( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -827,13 +754,11 @@ def test_render_json_schema_description_deprecated_and_required( prop_c: type: number required: [prop_a] - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: object :{directive} root.prop_a: @@ -844,8 +769,7 @@ def test_render_json_schema_description_deprecated_and_required( :{typedirective} root.prop_b.eggs: boolean, deprecated, required :{directive} root.prop_c: :{typedirective} root.prop_c: number - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -862,26 +786,22 @@ def test_render_json_schema_description_description( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object description: a resource representation properties: created_at: type: string description: a resource creation time - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: a resource creation time :{typedirective} created_at: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -898,26 +818,22 @@ def test_render_json_schema_description_description_commonmark_default( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object description: a resource representation properties: created_at: type: string description: a `resource` creation __time__ - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: a ``resource`` creation **time** :{typedirective} created_at: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -935,26 +851,22 @@ def test_render_json_schema_description_description_commonmark( testrenderer = renderers.HttpdomainRenderer(fakestate, {"markup": "commonmark"}) markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object description: a resource representation properties: created_at: type: string description: a `resource` creation __time__ - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: a ``resource`` creation **time** :{typedirective} created_at: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -974,26 +886,22 @@ def test_render_json_schema_description_description_restructuredtext( ) markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object description: a resource representation properties: created_at: type: string description: a `resource` creation __time__ - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} created_at: a `resource` creation __time__ :{typedirective} created_at: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1010,25 +918,21 @@ def test_render_json_schema_description_any_of( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - f""" + oas_fragment(f""" type: object properties: some_key: anyOf: - type: integer - type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: integer - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1045,25 +949,21 @@ def test_render_json_schema_description_one_of( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: some_key: oneOf: - type: integer - type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: integer - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1080,8 +980,7 @@ def test_render_json_schema_description_all_of( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: person: @@ -1098,13 +997,11 @@ def test_render_json_schema_description_all_of( properties: last: type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} person: :{typedirective} person: object :{directive} person.name: @@ -1115,8 +1012,7 @@ def test_render_json_schema_description_all_of( :{typedirective} person.name.last: string :{directive} person.age: :{typedirective} person.age: integer - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1133,25 +1029,21 @@ def test_render_json_schema_description_all_of_logical_impossible( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: some_key: allOf: - type: integer - type: string - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1168,8 +1060,7 @@ def test_render_json_schema_description_any_of_shared_type( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: some_key: @@ -1177,17 +1068,14 @@ def test_render_json_schema_description_any_of_shared_type( anyOf: - minLength: 3 - maxLength: 5 - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1204,8 +1092,7 @@ def test_render_json_schema_description_one_of_shared_type( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: some_key: @@ -1213,17 +1100,14 @@ def test_render_json_schema_description_one_of_shared_type( oneOf: - minLength: 3 - maxLength: 5 - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1240,8 +1124,7 @@ def test_render_json_schema_description_all_of_shared_type( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: some_key: @@ -1249,17 +1132,14 @@ def test_render_json_schema_description_all_of_shared_type( alOf: - minLength: 3 - maxLength: 5 - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} some_key: :{typedirective} some_key: string - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1276,23 +1156,19 @@ def test_render_json_schema_description_not( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: not: type: boolean - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1309,8 +1185,7 @@ def test_render_json_schema_description_enum( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: @@ -1318,17 +1193,14 @@ def test_render_json_schema_description_enum( enum: - foo - bar - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: string:enum - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -1345,22 +1217,18 @@ def test_render_json_schema_description_enum_wo_type( markup = textify( testrenderer.render_json_schema_description( - oas_fragment( - """ + oas_fragment(""" type: object properties: root: enum: - foo - bar - """ - ), + """), req_or_res, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :{directive} root: :{typedirective} root: enum - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_operation.py b/tests/renderers/httpdomain/test_render_operation.py index 0f68b0d..4855d00 100644 --- a/tests/renderers/httpdomain/test_render_operation.py +++ b/tests/renderers/httpdomain/test_render_operation.py @@ -18,8 +18,7 @@ def test_render_operation(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences/{evidenceId}", "get", - oas_fragment( - """ + oas_fragment(""" summary: Retrieve an evidence by ID. description: More verbose description... parameters: @@ -39,12 +38,10 @@ def test_render_operation(testrenderer, oas_fragment): description: An evidence. '404': description: An evidence not found. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId} **Retrieve an evidence by ID.** @@ -61,8 +58,7 @@ def test_render_operation(testrenderer, oas_fragment): An evidence. :statuscode 404: An evidence not found. - """.rstrip() - ) + """.rstrip()) def test_render_operation_minimal(testrenderer, oas_fragment): @@ -72,23 +68,19 @@ def test_render_operation_minimal(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_summary(testrenderer, oas_fragment): @@ -98,26 +90,22 @@ def test_render_operation_summary(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" summary: Create an evidence. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences **Create an evidence.** :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_description(testrenderer, oas_fragment): @@ -127,26 +115,22 @@ def test_render_operation_description(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" description: Create an evidence. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences Create an evidence. :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_description_multiline(testrenderer, oas_fragment): @@ -156,20 +140,17 @@ def test_render_operation_description_multiline(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" description: | Create an evidence. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences Create @@ -177,8 +158,7 @@ def test_render_operation_description_multiline(testrenderer, oas_fragment): :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_description_commonmark_default(testrenderer, oas_fragment): @@ -188,26 +168,22 @@ def test_render_operation_description_commonmark_default(testrenderer, oas_fragm testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" description: __Create__ an `evidence`. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences **Create** an ``evidence``. :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_description_commonmark(fakestate, oas_fragment): @@ -218,26 +194,22 @@ def test_render_operation_description_commonmark(fakestate, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" description: __Create__ an `evidence`. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences **Create** an ``evidence``. :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_description_commonmark_restructuredtext( @@ -252,26 +224,22 @@ def test_render_operation_description_commonmark_restructuredtext( testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" description: __Create__ an `evidence`. responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences __Create__ an `evidence`. :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_deprecated(testrenderer, oas_fragment): @@ -281,25 +249,21 @@ def test_render_operation_deprecated(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" responses: '201': description: An evidence created. deprecated: true - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences :deprecated: :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) def test_render_operation_w_requestbody(testrenderer, oas_fragment): @@ -309,8 +273,7 @@ def test_render_operation_w_requestbody(testrenderer, oas_fragment): testrenderer.render_operation( "/evidences", "post", - oas_fragment( - """ + oas_fragment(""" requestBody: content: application/json: @@ -320,12 +283,10 @@ def test_render_operation_w_requestbody(testrenderer, oas_fragment): responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. http:post:: /evidences .. sourcecode:: http @@ -340,8 +301,7 @@ def test_render_operation_w_requestbody(testrenderer, oas_fragment): :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -354,8 +314,7 @@ def test_render_operation_caseinsensitive_method(testrenderer, method, oas_fragm testrenderer.render_operation( "/evidences", method, - oas_fragment( - """ + oas_fragment(""" requestBody: content: application/json: @@ -365,12 +324,10 @@ def test_render_operation_caseinsensitive_method(testrenderer, method, oas_fragm responses: '201': description: An evidence created. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. http:{method}:: /evidences .. sourcecode:: http @@ -385,5 +342,4 @@ def test_render_operation_caseinsensitive_method(testrenderer, method, oas_fragm :statuscode 201: An evidence created. - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_parameter.py b/tests/renderers/httpdomain/test_render_parameter.py index a2c2877..64d7ae5 100644 --- a/tests/renderers/httpdomain/test_render_parameter.py +++ b/tests/renderers/httpdomain/test_render_parameter.py @@ -12,100 +12,68 @@ def textify(generator): def test_render_parameter_path(testrenderer, oas_fragment): """Usual path parameter's definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence identifier to query. :paramtype evidenceId: string, required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_minimal(testrenderer, oas_fragment): """Path parameter's minimal definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_description(testrenderer, oas_fragment): """Path parameter's 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: A unique evidence identifier to query. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence identifier to query. :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_multiline_description(testrenderer, oas_fragment): """Path parameter's multiline 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: | A unique evidence identifier to query. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence identifier to query. :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_description_commonmark_default( @@ -113,56 +81,40 @@ def test_render_parameter_path_description_commonmark_default( ): """Path parameter's 'description' must be in commonmark by default.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence ``identifier`` to **query**. :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_description_commonmark(fakestate, oas_fragment): """Path parameter's 'description' can be in commonmark.""" testrenderer = renderers.HttpdomainRenderer(fakestate, {"markup": "commonmark"}) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence ``identifier`` to **query**. :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_description_restructuredtext(fakestate, oas_fragment): @@ -171,238 +123,158 @@ def test_render_parameter_path_description_restructuredtext(fakestate, oas_fragm testrenderer = renderers.HttpdomainRenderer( fakestate, {"markup": "restructuredtext"} ) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence `identifier` to __query__. :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_deprecated(testrenderer, oas_fragment): """Path parameter's 'deprecated' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true deprecated: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: required, deprecated - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_deprecated_false(testrenderer, oas_fragment): """Path parameter's 'deprecated' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path required: true deprecated: false - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_type(testrenderer, oas_fragment): """Path parameter's type is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_type_with_format(testrenderer, oas_fragment): """Path parameter's type with format is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path schema: type: string format: uuid4 - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: string:uuid4 - """.rstrip() - ) + """.rstrip()) def test_render_parameter_path_type_from_content(testrenderer, oas_fragment): """Path parameter's type from content is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path content: text/plain: schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: :paramtype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query(testrenderer, oas_fragment): """Usual query parameter's definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence identifier to query. :paramtype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_minimal(testrenderer, oas_fragment): """Query parameter's minimal definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: path - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_description(testrenderer, oas_fragment): """Query parameter's 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query description: A unique evidence identifier to query. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: A unique evidence identifier to query. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_multiline_description(testrenderer, oas_fragment): """Query parameter's multiline 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query description: | A unique evidence identifier to query. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: A unique evidence identifier to query. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_description_commonmark_default( @@ -410,52 +282,36 @@ def test_render_parameter_query_description_commonmark_default( ): """Query parameter's 'description' must be in commonmark by default.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: A unique evidence ``identifier`` to **query**. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_description_commonmark(fakestate, oas_fragment): """Query parameter's 'description' can be in commonmark.""" testrenderer = renderers.HttpdomainRenderer(fakestate, {"markup": "commonmark"}) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: A unique evidence ``identifier`` to **query**. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_description_restructuredtext(fakestate, oas_fragment): @@ -464,299 +320,195 @@ def test_render_parameter_query_description_restructuredtext(fakestate, oas_frag testrenderer = renderers.HttpdomainRenderer( fakestate, {"markup": "restructuredtext"} ) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: A unique evidence `identifier` to __query__. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_required(testrenderer, oas_fragment): """Query parameter's 'required' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query required: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_required_false(testrenderer, oas_fragment): """Query parameter's 'required' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query required: false - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_deprecated(testrenderer, oas_fragment): """Query parameter's 'deprecated' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query deprecated: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: deprecated - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_deprecated_false(testrenderer, oas_fragment): """Query parameter's 'deprecated' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query deprecated: false - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_required_deprecated(testrenderer, oas_fragment): """Both query parameter's markers are rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query required: true deprecated: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: required, deprecated - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_type(testrenderer, oas_fragment): """Query parameter's type is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_type_with_format(testrenderer, oas_fragment): """Query parameter's type with format is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query schema: type: string format: uuid4 - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: string:uuid4 - """.rstrip() - ) + """.rstrip()) def test_render_parameter_query_type_from_content(testrenderer, oas_fragment): """Query parameter's type from content is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: query content: text/plain: schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam evidenceId: :queryparamtype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header(testrenderer, oas_fragment): """Usual header parameter's definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header description: A unique request identifier. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: A unique request identifier. :reqheadertype X-Request-Id: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_minimal(testrenderer, oas_fragment): """Header parameter's minimal definition is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_description(testrenderer, oas_fragment): """Header parameter's 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header description: A unique request identifier. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: A unique request identifier. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_multiline_description(testrenderer, oas_fragment): """Header parameter's multiline 'description' is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header description: | A unique request identifier. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: A unique request identifier. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_description_commonmark_default( @@ -764,52 +516,36 @@ def test_render_parameter_header_description_commonmark_default( ): """Header parameter's 'description' must be in commonmark by default.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: A unique evidence ``identifier`` to **query**. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_description_commonmark(fakestate, oas_fragment): """Header parameter's 'description' can be in commonmark.""" testrenderer = renderers.HttpdomainRenderer(fakestate, {"markup": "commonmark"}) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: A unique evidence ``identifier`` to **query**. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_description_restructuredtext(fakestate, oas_fragment): @@ -818,204 +554,132 @@ def test_render_parameter_header_description_restructuredtext(fakestate, oas_fra testrenderer = renderers.HttpdomainRenderer( fakestate, {"markup": "restructuredtext"} ) - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header description: | A unique evidence `identifier` to __query__. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: A unique evidence `identifier` to __query__. - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_required(testrenderer, oas_fragment): """Header parameter's 'required' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header required: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: :reqheadertype X-Request-Id: required - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_required_false(testrenderer, oas_fragment): """Header parameter's 'required' marker is not rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header required: false - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_deprecated(testrenderer, oas_fragment): """Header parameter's 'deprecated' marker is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header deprecated: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: :reqheadertype X-Request-Id: deprecated - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_deprecated_false(testrenderer, oas_fragment): """Header parameter's 'deprecated' marker is not rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header deprecated: false - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_required_deprecated(testrenderer, oas_fragment): """Both header parameter's markers are rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: X-Request-Id in: header required: true deprecated: true - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader X-Request-Id: :reqheadertype X-Request-Id: required, deprecated - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_type(testrenderer, oas_fragment): """Header parameter's type is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: :reqheadertype evidenceId: string - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_type_with_format(testrenderer, oas_fragment): """Header parameter's type with format is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header schema: type: string format: uuid4 - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: :reqheadertype evidenceId: string:uuid4 - """.rstrip() - ) + """.rstrip()) def test_render_parameter_header_type_from_content(testrenderer, oas_fragment): """Header parameter's type from content is rendered.""" - markup = textify( - testrenderer.render_parameter( - oas_fragment( - """ + markup = textify(testrenderer.render_parameter(oas_fragment(""" name: evidenceId in: header content: text/plain: schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader evidenceId: :reqheadertype evidenceId: string - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_parameters.py b/tests/renderers/httpdomain/test_render_parameters.py index a62515e..79701fe 100644 --- a/tests/renderers/httpdomain/test_render_parameters.py +++ b/tests/renderers/httpdomain/test_render_parameters.py @@ -15,51 +15,34 @@ def textify(generator): def test_render_parameters_no_items(testrenderer, oas_fragment): """No parameter definitions are rendered.""" - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" [] - """ - ) - ) - ) + """))) assert markup == "" def test_render_parameters_one_item(testrenderer, oas_fragment): """One usual parameter definition is rendered.""" - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: evidenceId in: path required: true description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :param evidenceId: A unique evidence identifier to query. :paramtype evidenceId: string, required - """.rstrip() - ) + """.rstrip()) def test_render_parameters_many_items(testrenderer, oas_fragment): """Many parameter definitions are rendered.""" - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: evidenceId in: path required: true @@ -77,12 +60,8 @@ def test_render_parameters_many_items(testrenderer, oas_fragment): description: API version to use for the request. schema: type: integer - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader Api-Version: API version to use for the request. :reqheadertype Api-Version: integer @@ -92,8 +71,7 @@ def test_render_parameters_many_items(testrenderer, oas_fragment): :queryparam details: If true, information w/ details is returned. :queryparamtype details: boolean - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize("permutation_seq", itertools.permutations(range(3))) @@ -102,8 +80,7 @@ def test_render_parameters_many_items_ordered( ): """Many parameter definitions are rendered and properly ordered.""" - parameters = oas_fragment( - """ + parameters = oas_fragment(""" - name: evidenceId in: path required: true @@ -122,8 +99,7 @@ def test_render_parameters_many_items_ordered( description: API version to use for the request. schema: type: integer - """ - ) + """) markup = textify( testrenderer.render_parameters( @@ -134,8 +110,7 @@ def test_render_parameters_many_items_ordered( ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :reqheader Api-Version: API version to use for the request. :reqheadertype Api-Version: integer @@ -145,17 +120,13 @@ def test_render_parameters_many_items_ordered( :queryparam details: If true, information w/ details is returned. :queryparamtype details: boolean - """.rstrip() - ) + """.rstrip()) def test_render_parameters_many_items_stable_order(testrenderer, oas_fragment): """Many parameter definitions are rendered w/ preserved order.""" - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: kind in: path required: true @@ -190,12 +161,8 @@ def test_render_parameters_many_items_stable_order(testrenderer, oas_fragment): description: A desired Content-Type of HTTP response. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :reqheader Api-Version: API version to use for the request. :reqheadertype Api-Version: integer @@ -214,8 +181,7 @@ def test_render_parameters_many_items_stable_order(testrenderer, oas_fragment): :queryparam related: If true, links to related evidences are returned. :queryparamtype related: boolean - """.rstrip() - ) + """.rstrip()) def test_render_parameters_custom_order(fakestate, oas_fragment): @@ -225,10 +191,7 @@ def test_render_parameters_custom_order(fakestate, oas_fragment): fakestate, {"request-parameters-order": ["query", "path", "header"]} ) - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: kind in: path required: true @@ -263,12 +226,8 @@ def test_render_parameters_custom_order(fakestate, oas_fragment): description: A desired Content-Type of HTTP response. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam details: If true, information w/ details is returned. :queryparamtype details: boolean @@ -287,8 +246,7 @@ def test_render_parameters_custom_order(fakestate, oas_fragment): :reqheader Accept: A desired Content-Type of HTTP response. :reqheadertype Accept: string - """.rstrip() - ) + """.rstrip()) def test_render_parameters_custom_order_partial(fakestate, oas_fragment): @@ -298,10 +256,7 @@ def test_render_parameters_custom_order_partial(fakestate, oas_fragment): fakestate, {"request-parameters-order": ["query", "path"]} ) - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: kind in: path required: true @@ -336,12 +291,8 @@ def test_render_parameters_custom_order_partial(fakestate, oas_fragment): description: A desired Content-Type of HTTP response. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam details: If true, information w/ details is returned. :queryparamtype details: boolean @@ -360,8 +311,7 @@ def test_render_parameters_custom_order_partial(fakestate, oas_fragment): :reqheader Accept: A desired Content-Type of HTTP response. :reqheadertype Accept: string - """.rstrip() - ) + """.rstrip()) def test_render_parameters_case_insensitive(fakestate, oas_fragment): @@ -371,10 +321,7 @@ def test_render_parameters_case_insensitive(fakestate, oas_fragment): fakestate, {"request-parameters-order": ["QUERY", "pAth", "Header"]} ) - markup = textify( - testrenderer.render_parameters( - oas_fragment( - """ + markup = textify(testrenderer.render_parameters(oas_fragment(""" - name: kind in: PATH required: true @@ -409,12 +356,8 @@ def test_render_parameters_case_insensitive(fakestate, oas_fragment): description: A desired Content-Type of HTTP response. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :queryparam details: If true, information w/ details is returned. :queryparamtype details: boolean @@ -433,5 +376,4 @@ def test_render_parameters_case_insensitive(fakestate, oas_fragment): :reqheader Accept: A desired Content-Type of HTTP response. :reqheadertype Accept: string - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_paths.py b/tests/renderers/httpdomain/test_render_paths.py index 44341d5..c4f727d 100644 --- a/tests/renderers/httpdomain/test_render_paths.py +++ b/tests/renderers/httpdomain/test_render_paths.py @@ -12,10 +12,7 @@ def textify(generator): def test_render_paths(testrenderer, oas_fragment): """Usual paths definition is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences/{evidenceId}: summary: Ignored description: Ignored @@ -42,12 +39,8 @@ def test_render_paths(testrenderer, oas_fragment): description: An evidence. '404': description: An evidence not found. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId} **Retrieve an evidence by ID.** @@ -64,43 +57,31 @@ def test_render_paths(testrenderer, oas_fragment): An evidence. :statuscode 404: An evidence not found. - """ - ) + """) def test_render_paths_minimal(testrenderer, oas_fragment): """Minimal paths definition is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences: get: responses: '200': description: A list of evidences. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences :statuscode 200: A list of evidences. - """ - ) + """) def test_render_paths_multiple(testrenderer, oas_fragment): """Paths definition with multiple paths is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences/{evidenceId}: get: summary: Retrieve an evidence by ID. @@ -128,12 +109,8 @@ def test_render_paths_multiple(testrenderer, oas_fragment): responses: '201': description: An evidence created. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId} **Retrieve an evidence by ID.** @@ -157,17 +134,13 @@ def test_render_paths_multiple(testrenderer, oas_fragment): :statuscode 201: An evidence created. - """ - ) + """) def test_render_paths_parameters_common(testrenderer, oas_fragment): """Paths definition with common parameters is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences/{evidenceId}: get: summary: Retrieve an evidence by ID. @@ -196,12 +169,8 @@ def test_render_paths_parameters_common(testrenderer, oas_fragment): description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId} **Retrieve an evidence by ID.** @@ -228,17 +197,13 @@ def test_render_paths_parameters_common(testrenderer, oas_fragment): An evidence. :statuscode 404: An evidence not found. - """ - ) + """) def test_render_paths_parameters_common_prepend(testrenderer, oas_fragment): """Paths definition with common parameters is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences/{evidenceId}/{evidenceSection}: get: summary: Retrieve an evidence by ID. @@ -260,12 +225,8 @@ def test_render_paths_parameters_common_prepend(testrenderer, oas_fragment): description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId}/{evidenceSection} **Retrieve an evidence by ID.** @@ -280,17 +241,13 @@ def test_render_paths_parameters_common_prepend(testrenderer, oas_fragment): An evidence. :statuscode 404: An evidence not found. - """ - ) + """) def test_render_paths_parameters_common_overwritten(testrenderer, oas_fragment): """Paths definition with common parameters is rendered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences/{evidenceId}: get: summary: Retrieve an evidence by ID. @@ -310,12 +267,8 @@ def test_render_paths_parameters_common_overwritten(testrenderer, oas_fragment): description: A unique evidence identifier to query. schema: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences/{evidenceId} **Retrieve an evidence by ID.** @@ -325,17 +278,13 @@ def test_render_paths_parameters_common_overwritten(testrenderer, oas_fragment): :paramtype evidenceId: string :statuscode 200: An evidence. - """ - ) + """) def test_render_paths_methods_order(testrenderer, oas_fragment): """Paths definition is rendered with HTTP methods ordered.""" - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences: post: responses: @@ -349,12 +298,8 @@ def test_render_paths_methods_order(testrenderer, oas_fragment): responses: '200': description: A list of evidences. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:post:: /evidences :statuscode 201: @@ -369,8 +314,7 @@ def test_render_paths_methods_order(testrenderer, oas_fragment): :statuscode 200: A list of evidences. - """ - ) + """) def test_render_paths_methods_order_custom(fakestate, oas_fragment): @@ -380,10 +324,7 @@ def test_render_paths_methods_order_custom(fakestate, oas_fragment): fakestate, {"http-methods-order": ["delete", "options", "get", "post"]} ) - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences: post: responses: @@ -397,12 +338,8 @@ def test_render_paths_methods_order_custom(fakestate, oas_fragment): responses: '200': description: A list of evidences. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:options:: /evidences :statuscode 200: @@ -417,8 +354,7 @@ def test_render_paths_methods_order_custom(fakestate, oas_fragment): :statuscode 201: An evidence created. - """ - ) + """) def test_render_paths_methods_order_insensitive(fakestate, oas_fragment): @@ -428,10 +364,7 @@ def test_render_paths_methods_order_insensitive(fakestate, oas_fragment): fakestate, {"http-methods-order": ["gEt", "post"]} ) - markup = textify( - testrenderer.render_paths( - oas_fragment( - """ + markup = textify(testrenderer.render_paths(oas_fragment(""" /evidences: post: responses: @@ -441,12 +374,8 @@ def test_render_paths_methods_order_insensitive(fakestate, oas_fragment): responses: '200': description: A list of evidences. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /evidences :statuscode 200: @@ -456,5 +385,4 @@ def test_render_paths_methods_order_insensitive(fakestate, oas_fragment): :statuscode 201: An evidence created. - """ - ) + """) diff --git a/tests/renderers/httpdomain/test_render_request_body.py b/tests/renderers/httpdomain/test_render_request_body.py index b45e9d5..8302b1d 100644 --- a/tests/renderers/httpdomain/test_render_request_body.py +++ b/tests/renderers/httpdomain/test_render_request_body.py @@ -21,8 +21,7 @@ def test_render_request_body_schema_description( markup = textify( testrenderer.render_request_body( - oas_fragment( - f""" + oas_fragment(f""" content: {content_type}: schema: @@ -31,21 +30,18 @@ def test_render_request_body_schema_description( type: string bar: type: integer - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :reqjson foo: :reqjsonobj foo: string :reqjson bar: :reqjsonobj bar: integer - """ - ) + """) def test_render_request_body_schema_description_non_json(testrenderer, oas_fragment): @@ -53,8 +49,7 @@ def test_render_request_body_schema_description_non_json(testrenderer, oas_fragm markup = textify( testrenderer.render_request_body( - oas_fragment( - """ + oas_fragment(""" content: text/csv: schema: @@ -63,16 +58,13 @@ def test_render_request_body_schema_description_non_json(testrenderer, oas_fragm type: string bar: type: integer - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ - """ - ) + assert markup == textwrap.dedent("""\ + """) def test_render_request_body_schema_description_turned_off(fakestate, oas_fragment): @@ -85,8 +77,7 @@ def test_render_request_body_schema_description_turned_off(fakestate, oas_fragme markup = textify( testrenderer.render_request_body( - oas_fragment( - """ + oas_fragment(""" content: application/json: schema: @@ -95,13 +86,10 @@ def test_render_request_body_schema_description_turned_off(fakestate, oas_fragme type: string bar: type: integer - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ - """ - ) + assert markup == textwrap.dedent("""\ + """) diff --git a/tests/renderers/httpdomain/test_render_request_body_example.py b/tests/renderers/httpdomain/test_render_request_body_example.py index b27eaf0..56aa59a 100644 --- a/tests/renderers/httpdomain/test_render_request_body_example.py +++ b/tests/renderers/httpdomain/test_render_request_body_example.py @@ -127,8 +127,7 @@ def test_render_request_body_example(testrenderer, content, oas_fragment): "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -138,8 +137,7 @@ def test_render_request_body_example(testrenderer, content, oas_fragment): "foo": "bar", "baz": 42 } - """.rstrip() - ) + """.rstrip()) def test_render_request_body_example_1st_from_examples(testrenderer, oas_fragment): @@ -147,8 +145,7 @@ def test_render_request_body_example_1st_from_examples(testrenderer, oas_fragmen markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: examples: @@ -159,14 +156,12 @@ def test_render_request_body_example_1st_from_examples(testrenderer, oas_fragmen bar: value: foobar: bazinga - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -176,8 +171,7 @@ def test_render_request_body_example_1st_from_examples(testrenderer, oas_fragmen "foo": "bar", "baz": 42 } - """.rstrip() - ) + """.rstrip()) def test_render_request_body_example_1st_from_media_type(testrenderer, oas_fragment): @@ -185,8 +179,7 @@ def test_render_request_body_example_1st_from_media_type(testrenderer, oas_fragm markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: text/plain: example: | @@ -195,15 +188,13 @@ def test_render_request_body_example_1st_from_media_type(testrenderer, oas_fragm application/json: schema: type: object - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -211,8 +202,7 @@ def test_render_request_body_example_1st_from_media_type(testrenderer, oas_fragm foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -230,8 +220,7 @@ def test_render_request_body_example_preference( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: example: @@ -241,15 +230,13 @@ def test_render_request_body_example_preference( example: | foo = "bar" baz = 42 - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -257,8 +244,7 @@ def test_render_request_body_example_preference( foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -276,8 +262,7 @@ def test_render_request_body_example_preference_complex( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: text/csv: example: | @@ -290,15 +275,13 @@ def test_render_request_body_example_preference_complex( application/json: schema: type: object - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -306,8 +289,7 @@ def test_render_request_body_example_preference_complex( foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) def test_render_request_body_example_preference_priority(fakestate, oas_fragment): @@ -323,8 +305,7 @@ def test_render_request_body_example_preference_priority(fakestate, oas_fragment markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: example: @@ -334,15 +315,13 @@ def test_render_request_body_example_preference_priority(fakestate, oas_fragment example: | foo = "bar" baz = 42 - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -350,8 +329,7 @@ def test_render_request_body_example_preference_priority(fakestate, oas_fragment foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -367,29 +345,25 @@ def test_render_request_body_example_external(testrenderer, oas_fragment): markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: examples: test: externalValue: https://example.com/json/examples/test.json - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 Content-Type: application/json {"foo": "bar", "baz": 42} - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -406,8 +380,7 @@ def test_render_request_body_example_external_errored_next_example( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: examples: @@ -415,22 +388,19 @@ def test_render_request_body_example_external_errored_next_example( externalValue: https://example.com/json/examples/test.json fallback: value: '{"spam": 42}' - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 Content-Type: application/json {"spam": 42} - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -449,8 +419,7 @@ def test_render_request_body_example_external_errored_next_media_type( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: examples: @@ -458,22 +427,19 @@ def test_render_request_body_example_external_errored_next_media_type( externalValue: https://example.com/json/examples/test.json text/csv: example: spam,42 - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 Content-Type: text/csv spam,42 - """.rstrip() - ) + """.rstrip()) def test_render_request_body_example_content_type(testrenderer, oas_fragment): @@ -481,21 +447,18 @@ def test_render_request_body_example_content_type(testrenderer, oas_fragment): markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: text/csv: example: | foo,baz bar,42 - """ - ), + """), "/evidences/{evidenceId}", "POST", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http POST /evidences/{evidenceId} HTTP/1.1 @@ -503,8 +466,7 @@ def test_render_request_body_example_content_type(testrenderer, oas_fragment): foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) def test_render_request_body_example_noop(testrenderer, oas_fragment): @@ -512,14 +474,12 @@ def test_render_request_body_example_noop(testrenderer, oas_fragment): markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: application/json: schema: type: object - """ - ), + """), "/evidences/{evidenceId}", "POST", ) @@ -540,22 +500,19 @@ def test_render_request_body_example_http_method( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: text/csv: example: | foo,baz bar,42 - """ - ), + """), "/evidences/{evidenceId}", http_method, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http {http_method} /evidences/{{evidenceId}} HTTP/1.1 @@ -563,8 +520,7 @@ def test_render_request_body_example_http_method( foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -580,22 +536,19 @@ def test_render_request_body_example_http_endpoint( markup = textify( testrenderer.render_request_body_example( - oas_fragment( - """ + oas_fragment(""" content: text/csv: example: | foo,baz bar,42 - """ - ), + """), http_endpoint, "POST", ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http POST {http_endpoint} HTTP/1.1 @@ -603,5 +556,4 @@ def test_render_request_body_example_http_endpoint( foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_response.py b/tests/renderers/httpdomain/test_render_response.py index 5a6b711..37d1af8 100644 --- a/tests/renderers/httpdomain/test_render_response.py +++ b/tests/renderers/httpdomain/test_render_response.py @@ -6,7 +6,6 @@ from sphinxcontrib.openapi import renderers - if sys.version_info[:2] >= (3, 13): http_422_description = "Unprocessable Content" else: @@ -26,20 +25,15 @@ def test_render_response_status_code(testrenderer, oas_fragment, statuscode): markup = textify( testrenderer.render_response( statuscode, - oas_fragment( - """ + oas_fragment(""" description: An evidence. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode %s: An evidence. - """.rstrip() - % statuscode - ) + """.rstrip() % statuscode) def test_render_response_minimal(testrenderer, oas_fragment): @@ -48,19 +42,15 @@ def test_render_response_minimal(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_response_description_commonmark_default(testrenderer, oas_fragment): @@ -69,22 +59,18 @@ def test_render_response_description_commonmark_default(testrenderer, oas_fragme markup = textify( testrenderer.render_response( "200", - oas_fragment( - """ + oas_fragment(""" description: | An __evidence__ that matches the `query`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An **evidence** that matches the ``query``. - """.rstrip() - ) + """.rstrip()) def test_render_response_description_commonmark(fakestate, oas_fragment): @@ -94,22 +80,18 @@ def test_render_response_description_commonmark(fakestate, oas_fragment): markup = textify( testrenderer.render_response( "200", - oas_fragment( - """ + oas_fragment(""" description: | An __evidence__ that matches the `query`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An **evidence** that matches the ``query``. - """.rstrip() - ) + """.rstrip()) def test_render_response_description_restructuredtext(fakestate, oas_fragment): @@ -121,22 +103,18 @@ def test_render_response_description_restructuredtext(fakestate, oas_fragment): markup = textify( testrenderer.render_response( "200", - oas_fragment( - """ + oas_fragment(""" description: | An __evidence__ that matches the `query`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An __evidence__ that matches the `query`. - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -153,20 +131,17 @@ def test_render_response_content_2xx(testrenderer, oas_fragment, status_code, st markup = textify( testrenderer.render_response( status_code, - oas_fragment( - """ + oas_fragment(""" description: An evidence. content: application/json: example: foo: bar baz: 42 - """ - ), + """), ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :statuscode {status_code}: An evidence. @@ -179,8 +154,7 @@ def test_render_response_content_2xx(testrenderer, oas_fragment, status_code, st "foo": "bar", "baz": 42 }} - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -199,24 +173,20 @@ def test_render_response_content_non_2xx(testrenderer, oas_fragment, status_code markup = textify( testrenderer.render_response( status_code, - oas_fragment( - """ + oas_fragment(""" description: An evidence. content: application/json: example: foo: bar baz: 42 - """ - ), + """), ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :statuscode {status_code}: An evidence. - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -238,20 +208,17 @@ def test_render_response_content_custom(fakestate, oas_fragment, status_code, st markup = textify( testrenderer.render_response( status_code, - oas_fragment( - """ + oas_fragment(""" description: An evidence. content: application/json: example: foo: bar baz: 42 - """ - ), + """), ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :statuscode {status_code}: An evidence. @@ -264,8 +231,7 @@ def test_render_response_content_custom(fakestate, oas_fragment, status_code, st "foo": "bar", "baz": 42 }} - """.rstrip() - ) + """.rstrip()) def test_render_response_content_custom_mismatch(fakestate, oas_fragment): @@ -278,24 +244,20 @@ def test_render_response_content_custom_mismatch(fakestate, oas_fragment): markup = textify( testrenderer.render_response( "200", - oas_fragment( - """ + oas_fragment(""" description: An evidence. content: application/json: example: foo: bar baz: 42 - """ - ), + """), ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ :statuscode 200: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_response_header(testrenderer, oas_fragment): @@ -304,28 +266,24 @@ def test_render_response_header(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( "200", - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: A unique request identifier. schema: type: string - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique request identifier. :resheadertype X-Request-Id: string - """.rstrip() - ) + """.rstrip()) def test_render_response_header_minimal(testrenderer, oas_fragment): @@ -334,23 +292,19 @@ def test_render_response_header_minimal(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: {} - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_response_header_description(testrenderer, oas_fragment): @@ -359,25 +313,21 @@ def test_render_response_header_description(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: A unique request identifier. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique request identifier. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_multiline_description(testrenderer, oas_fragment): @@ -386,28 +336,24 @@ def test_render_response_header_multiline_description(testrenderer, oas_fragment markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: | A unique request identifier. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique request identifier. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_description_commonmark_default( @@ -418,28 +364,24 @@ def test_render_response_header_description_commonmark_default( markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: | A unique __request__ `identifier`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique **request** ``identifier``. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_description_commonmark(fakestate, oas_fragment): @@ -449,28 +391,24 @@ def test_render_response_header_description_commonmark(fakestate, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: | A unique __request__ `identifier`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique **request** ``identifier``. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_description_restructuredtext(fakestate, oas_fragment): @@ -482,28 +420,24 @@ def test_render_response_header_description_restructuredtext(fakestate, oas_frag markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: description: | A unique __request__ `identifier`. - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: A unique __request__ `identifier`. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_content_type(testrenderer, oas_fragment): @@ -512,25 +446,21 @@ def test_render_response_header_content_type(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: Content-Type: {} - """ - ), + """), ) ) # There's an extra newline at the end of markup if there's at least one # response header defined. - assert markup.rstrip() == textwrap.dedent( - """\ + assert markup.rstrip() == textwrap.dedent("""\ :statuscode 200: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_response_header_required(testrenderer, oas_fragment): @@ -539,26 +469,22 @@ def test_render_response_header_required(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: required: true - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: required - """.rstrip() - ) + """.rstrip()) def test_render_response_header_required_false(testrenderer, oas_fragment): @@ -567,25 +493,21 @@ def test_render_response_header_required_false(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: required: false - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_response_header_deprecated(testrenderer, oas_fragment): @@ -594,26 +516,22 @@ def test_render_response_header_deprecated(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: deprecated: true - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: deprecated - """.rstrip() - ) + """.rstrip()) def test_render_response_header_deprecated_false(testrenderer, oas_fragment): @@ -622,25 +540,21 @@ def test_render_response_header_deprecated_false(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: deprecated: false - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: - """.rstrip() - ) + """.rstrip()) def test_render_response_header_required_deprecated(testrenderer, oas_fragment): @@ -649,27 +563,23 @@ def test_render_response_header_required_deprecated(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: required: true deprecated: true - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: required, deprecated - """.rstrip() - ) + """.rstrip()) def test_render_response_header_type(testrenderer, oas_fragment): @@ -678,27 +588,23 @@ def test_render_response_header_type(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: schema: type: string - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: string - """.rstrip() - ) + """.rstrip()) def test_render_response_header_type_with_format(testrenderer, oas_fragment): @@ -707,28 +613,24 @@ def test_render_response_header_type_with_format(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: schema: type: string format: uuid4 - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: string:uuid4 - """.rstrip() - ) + """.rstrip()) def test_render_response_header_type_from_content(testrenderer, oas_fragment): @@ -737,8 +639,7 @@ def test_render_response_header_type_from_content(testrenderer, oas_fragment): markup = textify( testrenderer.render_response( 200, - oas_fragment( - """ + oas_fragment(""" description: An evidence. headers: X-Request-Id: @@ -746,17 +647,14 @@ def test_render_response_header_type_from_content(testrenderer, oas_fragment): text/plain: schema: type: string - """ - ), + """), ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :resheader X-Request-Id: :resheadertype X-Request-Id: string - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_response_example.py b/tests/renderers/httpdomain/test_render_response_example.py index acd76a8..86cad42 100644 --- a/tests/renderers/httpdomain/test_render_response_example.py +++ b/tests/renderers/httpdomain/test_render_response_example.py @@ -8,7 +8,6 @@ from sphinxcontrib.openapi import renderers - if sys.version_info[:2] >= (3, 13): http_422_description = "Unprocessable Content" else: @@ -122,8 +121,7 @@ def test_render_response_example(testrenderer, oas_fragment, media_type): markup = textify( testrenderer.render_response_example(oas_fragment(media_type), "200") ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -133,8 +131,7 @@ def test_render_response_example(testrenderer, oas_fragment, media_type): "foo": "bar", "baz": 42 } - """.rstrip() - ) + """.rstrip()) def test_render_response_example_1st_from_examples(testrenderer, oas_fragment): @@ -142,8 +139,7 @@ def test_render_response_example_1st_from_examples(testrenderer, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: examples: foo: @@ -153,13 +149,11 @@ def test_render_response_example_1st_from_examples(testrenderer, oas_fragment): bar: value: foobar: bazinga - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -169,8 +163,7 @@ def test_render_response_example_1st_from_examples(testrenderer, oas_fragment): "foo": "bar", "baz": 42 } - """.rstrip() - ) + """.rstrip()) def test_render_response_example_1st_from_media_type(testrenderer, oas_fragment): @@ -178,8 +171,7 @@ def test_render_response_example_1st_from_media_type(testrenderer, oas_fragment) markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/plain: example: | foo = "bar" @@ -187,14 +179,12 @@ def test_render_response_example_1st_from_media_type(testrenderer, oas_fragment) application/json: schema: type: object - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -202,8 +192,7 @@ def test_render_response_example_1st_from_media_type(testrenderer, oas_fragment) foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -221,8 +210,7 @@ def test_render_response_example_preference( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: example: foo: bar @@ -231,14 +219,12 @@ def test_render_response_example_preference( example: | foo = "bar" baz = 42 - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -246,8 +232,7 @@ def test_render_response_example_preference( foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -265,8 +250,7 @@ def test_render_response_example_preference_complex( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz @@ -278,14 +262,12 @@ def test_render_response_example_preference_complex( application/json: schema: type: object - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -293,8 +275,7 @@ def test_render_response_example_preference_complex( foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) def test_render_response_example_preference_priority(fakestate, oas_fragment): @@ -310,8 +291,7 @@ def test_render_response_example_preference_priority(fakestate, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: example: foo: bar @@ -320,14 +300,12 @@ def test_render_response_example_preference_priority(fakestate, oas_fragment): example: | foo = "bar" baz = 42 - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -335,8 +313,7 @@ def test_render_response_example_preference_priority(fakestate, oas_fragment): foo = "bar" baz = 42 - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -352,27 +329,23 @@ def test_render_response_example_external(testrenderer, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: examples: test: externalValue: https://example.com/json/examples/test.json - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json {"foo": "bar", "baz": 42} - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -389,29 +362,25 @@ def test_render_response_example_external_errored_next_example( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: examples: test: externalValue: https://example.com/json/examples/test.json fallback: value: '{"spam": 42}' - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json {"spam": 42} - """.rstrip() - ) + """.rstrip()) @responses.activate @@ -428,29 +397,25 @@ def test_render_response_example_external_errored_next_media_type( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: examples: test: externalValue: https://example.com/json/examples/test.json text/csv: example: spam,42 - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK Content-Type: text/csv spam,42 - """.rstrip() - ) + """.rstrip()) def test_render_response_example_content_type(testrenderer, oas_fragment): @@ -458,19 +423,16 @@ def test_render_response_example_content_type(testrenderer, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz bar,42 - """ - ), + """), "200", ) ) - assert markup == textwrap.dedent( - """\ + assert markup == textwrap.dedent("""\ .. sourcecode:: http HTTP/1.1 200 OK @@ -478,8 +440,7 @@ def test_render_response_example_content_type(testrenderer, oas_fragment): foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) def test_render_response_example_noop(testrenderer, oas_fragment): @@ -487,13 +448,11 @@ def test_render_response_example_noop(testrenderer, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" application/json: schema: type: object - """ - ), + """), "200", ) ) @@ -516,19 +475,16 @@ def test_render_response_status_code( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz bar,42 - """ - ), + """), status_code, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http HTTP/1.1 {status_code} {status_text} @@ -536,8 +492,7 @@ def test_render_response_status_code( foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -555,19 +510,16 @@ def test_render_response_status_code_range( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz bar,42 - """ - ), + """), status_range, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http HTTP/1.1 {status_code} {status_text} @@ -575,8 +527,7 @@ def test_render_response_status_code_range( foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) @pytest.mark.parametrize( @@ -594,19 +545,16 @@ def test_render_response_status_code_int( markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz bar,42 - """ - ), + """), status_code, ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http HTTP/1.1 {status_code} {status_text} @@ -614,8 +562,7 @@ def test_render_response_status_code_int( foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) def test_render_response_status_code_default(testrenderer, oas_fragment): @@ -623,19 +570,16 @@ def test_render_response_status_code_default(testrenderer, oas_fragment): markup = textify( testrenderer.render_response_example( - oas_fragment( - """ + oas_fragment(""" text/csv: example: | foo,baz bar,42 - """ - ), + """), "default", ) ) - assert markup == textwrap.dedent( - f"""\ + assert markup == textwrap.dedent(f"""\ .. sourcecode:: http HTTP/1.1 000 Reason-Phrase @@ -643,5 +587,4 @@ def test_render_response_status_code_default(testrenderer, oas_fragment): foo,baz bar,42 - """.rstrip() - ) + """.rstrip()) diff --git a/tests/renderers/httpdomain/test_render_responses.py b/tests/renderers/httpdomain/test_render_responses.py index 0c72e30..6b4460f 100644 --- a/tests/renderers/httpdomain/test_render_responses.py +++ b/tests/renderers/httpdomain/test_render_responses.py @@ -12,92 +12,59 @@ def textify(generator): def test_render_responses_no_items(testrenderer, oas_fragment): """No response definitions are rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" {} - """ - ) - ) - ) + """))) assert markup == "" def test_render_responses_one_item(testrenderer, oas_fragment): """One usual response definition is rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '200': description: An evidence. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_responses_one_item_status_code_int(testrenderer, oas_fragment): """One usual response definition is rendered even if status code is integer.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" 200: description: An evidence. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_responses_many_items(testrenderer, oas_fragment): """Many response definitions are rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '200': description: An evidence. '404': description: An evidence not found. - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. :statuscode 404: An evidence not found. - """.rstrip() - ) + """.rstrip()) def test_render_responses_json_schema_description(testrenderer, oas_fragment): """JSON schema description is rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '200': description: An evidence. content: @@ -108,12 +75,8 @@ def test_render_responses_json_schema_description(testrenderer, oas_fragment): type: string bar: type: integer - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :resjson foo: :resjsonobj foo: string :resjson bar: @@ -121,17 +84,13 @@ def test_render_responses_json_schema_description(testrenderer, oas_fragment): :statuscode 200: An evidence. - """ - ) + """) def test_render_responses_json_schema_description_4xx(testrenderer, oas_fragment): """JSON schema description is rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '400': description: An evidence. content: @@ -142,25 +101,17 @@ def test_render_responses_json_schema_description_4xx(testrenderer, oas_fragment type: string bar: type: integer - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :statuscode 400: An evidence. - """.rstrip() - ) + """.rstrip()) def test_render_responses_json_schema_description_first_2xx(testrenderer, oas_fragment): """JSON schema description is rendered.""" - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '400': description: An error. content: @@ -187,12 +138,8 @@ def test_render_responses_json_schema_description_first_2xx(testrenderer, oas_fr properties: bbb: type: string - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :resjson foo: :resjsonobj foo: string :resjson bar: @@ -205,8 +152,7 @@ def test_render_responses_json_schema_description_first_2xx(testrenderer, oas_fr :statuscode 201: An evidence created. - """ - ) + """) def test_render_responses_json_schema_description_turned_off(fakestate, oas_fragment): @@ -217,10 +163,7 @@ def test_render_responses_json_schema_description_turned_off(fakestate, oas_frag {"no-json-schema-description": True}, ) - markup = textify( - testrenderer.render_responses( - oas_fragment( - """ + markup = textify(testrenderer.render_responses(oas_fragment(""" '200': description: An evidence. content: @@ -231,13 +174,8 @@ def test_render_responses_json_schema_description_turned_off(fakestate, oas_frag type: string bar: type: integer - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ :statuscode 200: An evidence. - """ - ) + """) diff --git a/tests/renderers/httpdomain/test_render_restructuredtext_markup.py b/tests/renderers/httpdomain/test_render_restructuredtext_markup.py index 0df437f..a984ccf 100644 --- a/tests/renderers/httpdomain/test_render_restructuredtext_markup.py +++ b/tests/renderers/httpdomain/test_render_restructuredtext_markup.py @@ -12,10 +12,7 @@ def textify(generator): def test_oas2_minimal(testrenderer, oas_fragment): """Minimal OAS 2 can be rendered.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -26,27 +23,19 @@ def test_oas2_minimal(testrenderer, oas_fragment): responses: '200': description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test :statuscode 200: a response description - """ - ) + """) def test_oas2_complete(testrenderer, oas_fragment): """Feature rich OAS 2 can be rendered.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -90,12 +79,8 @@ def test_oas2_complete(testrenderer, oas_fragment): description: a response description '404': description: a username not found - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test :statuscode 200: @@ -119,17 +104,13 @@ def test_oas2_complete(testrenderer, oas_fragment): :statuscode 404: a username not found - """ - ) + """) def test_oas2_schema_example(testrenderer, oas_fragment): """Schema's 'example' property can be used in example snippets.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -153,12 +134,8 @@ def test_oas2_schema_example(testrenderer, oas_fragment): type: integer type: array description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -176,8 +153,7 @@ def test_oas2_schema_example(testrenderer, oas_fragment): 19, 84 ] - """ - ) + """) def test_oas2_complete_generate_examples_from_schema(fakestate, oas_fragment): @@ -186,10 +162,7 @@ def test_oas2_complete_generate_examples_from_schema(fakestate, oas_fragment): testrenderer = renderers.HttpdomainRenderer( fakestate, {"generate-examples-from-schemas": True} ) - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" swagger: "2.0" info: title: An example spec @@ -208,12 +181,8 @@ def test_oas2_complete_generate_examples_from_schema(fakestate, oas_fragment): type: integer type: array description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -231,17 +200,13 @@ def test_oas2_complete_generate_examples_from_schema(fakestate, oas_fragment): 1, 1 ] - """ - ) + """) def test_oas3_minimal(testrenderer, oas_fragment): """Minimal OAS 3 can be rendered.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -252,27 +217,19 @@ def test_oas3_minimal(testrenderer, oas_fragment): responses: '200': description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test :statuscode 200: a response description - """ - ) + """) def test_oas3_complete(testrenderer, oas_fragment): """Feature rich OAS 3 can be rendered.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -319,12 +276,8 @@ def test_oas3_complete(testrenderer, oas_fragment): description: a response description '404': description: a username not found - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test :statuscode 200: @@ -348,17 +301,13 @@ def test_oas3_complete(testrenderer, oas_fragment): :statuscode 404: a username not found - """ - ) + """) def test_oas3_schema_example(testrenderer, oas_fragment): """Schema's 'example' property can be used in example snippets.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -382,12 +331,8 @@ def test_oas3_schema_example(testrenderer, oas_fragment): type: integer type: array description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -405,8 +350,7 @@ def test_oas3_schema_example(testrenderer, oas_fragment): 19, 84 ] - """ - ) + """) def test_oas3_generate_examples_from_schema(fakestate, oas_fragment): @@ -415,10 +359,7 @@ def test_oas3_generate_examples_from_schema(fakestate, oas_fragment): testrenderer = renderers.HttpdomainRenderer( fakestate, {"generate-examples-from-schemas": True} ) - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -437,12 +378,8 @@ def test_oas3_generate_examples_from_schema(fakestate, oas_fragment): type: integer type: array description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -460,17 +397,13 @@ def test_oas3_generate_examples_from_schema(fakestate, oas_fragment): 1, 1 ] - """ - ) + """) def test_oas3_request_body(testrenderer, oas_fragment): """Request body example is rendered.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -490,12 +423,8 @@ def test_oas3_request_body(testrenderer, oas_fragment): responses: '200': description: a response description - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -512,17 +441,13 @@ def test_oas3_request_body(testrenderer, oas_fragment): :statuscode 200: a response description - """ - ) + """) def test_oas3_response_example_2xx(testrenderer, oas_fragment): """Response examples are rendered for 2XX status codes.""" - markup = textify( - testrenderer.render_restructuredtext_markup( - oas_fragment( - """ + markup = textify(testrenderer.render_restructuredtext_markup(oas_fragment(""" openapi: 3.0.3 info: title: An example spec @@ -549,12 +474,8 @@ def test_oas3_response_example_2xx(testrenderer, oas_fragment): "message": "an error message" } description: resource not found - """ - ) - ) - ) - assert markup == textwrap.dedent( - """\ + """))) + assert markup == textwrap.dedent("""\ .. http:get:: /test an operation description @@ -573,5 +494,4 @@ def test_oas3_response_example_2xx(testrenderer, oas_fragment): ] :statuscode 404: resource not found - """ - ) + """) diff --git a/tests/test_openapi.py b/tests/test_openapi.py index 551f6a6..d254572 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -1769,7 +1769,6 @@ def test_relative_ref_resolving_remote(self, mock_get): yaml_content = file.read() def get_side_effect(path): - nonlocal json_content if path.endswith('.json'): return mock.Mock(json=mock.Mock(return_value=json_content)) return mock.Mock(content=yaml_content, read=mock.Mock(side_effect=Exception)) @@ -1857,7 +1856,6 @@ def test_noproperties(self): def test_openapi2_examples(tmpdir, run_sphinx): spec = os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v2.0', 'json', @@ -1875,7 +1873,6 @@ def test_openapi2_examples(tmpdir, run_sphinx): def test_openapi3_examples(tmpdir, run_sphinx, render_examples): spec = os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v3.0', 'petstore.yaml') diff --git a/tests/test_spec_examples.py b/tests/test_spec_examples.py index 7fe4a07..652abb1 100644 --- a/tests/test_spec_examples.py +++ b/tests/test_spec_examples.py @@ -1,4 +1,4 @@ -"""Smoke test examples from OAI/OpenAPI-Specification repo.""" +"""Smoke test examples from OAI/learn.openapis.org repo.""" import os import glob @@ -12,7 +12,6 @@ glob.glob( os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v2.0', 'json', @@ -21,7 +20,6 @@ glob.glob( os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v2.0', 'yaml', @@ -38,7 +36,6 @@ def test_openapi2_success(tmpdir, run_sphinx, spec): @pytest.mark.parametrize('spec', glob.glob( os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v3.0', '*.yaml') @@ -58,7 +55,6 @@ def test_openapi30_success(tmpdir, run_sphinx, spec, render_examples, @pytest.mark.parametrize('spec', glob.glob( os.path.join( os.path.abspath(os.path.dirname(__file__)), - 'OpenAPI-Specification', 'examples', 'v3.1', '*.yaml')