From 9b65a42e1abee04d3b7b6295d2378451e49dac09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:55:12 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.10 → v0.5.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.10...v0.5.0) - [github.com/asottile/blacken-docs: 1.16.0 → 1.18.0](https://github.com/asottile/blacken-docs/compare/1.16.0...1.18.0) - [github.com/pre-commit/mirrors-mypy: v1.10.0 → v1.10.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.10.0...v1.10.1) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d07f6c1..c6ea6ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.10 + rev: v0.5.0 hooks: - id: ruff - id: ruff-format @@ -10,12 +10,12 @@ repos: - id: check-github-workflows - id: check-readthedocs - repo: https://github.com/asottile/blacken-docs - rev: 1.16.0 + rev: 1.18.0 hooks: - id: blacken-docs additional_dependencies: [black==23.12.1] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.0 + rev: v1.10.1 hooks: - id: mypy files: ^src/apispec_webframeworks/ From d2e25d073d87f53fbce25d9e8d2a4ad322a58d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 2 Jul 2024 15:15:07 +0200 Subject: [PATCH 2/2] Update ruff config --- pyproject.toml | 5 ++++- src/apispec_webframeworks/aiohttp.py | 7 +++--- src/apispec_webframeworks/bottle.py | 10 ++++++--- src/apispec_webframeworks/flask.py | 33 ++++++++++++++++------------ src/apispec_webframeworks/tornado.py | 6 +++-- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9635d83..fb0a150 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,10 @@ include = ["tests/", "CHANGELOG.rst", "tox.ini"] src = ["src"] fix = true show-fixes = true -show-source = true +output-format = "full" + +[tool.ruff.format] +docstring-code-format = true [tool.ruff.lint] select = [ diff --git a/src/apispec_webframeworks/aiohttp.py b/src/apispec_webframeworks/aiohttp.py index ba4ba20..05e38de 100644 --- a/src/apispec_webframeworks/aiohttp.py +++ b/src/apispec_webframeworks/aiohttp.py @@ -6,6 +6,7 @@ from apispec import APISpec from pprint import pprint + async def hello(request): '''Get a greeting endpoint. --- @@ -22,7 +23,7 @@ async def hello(request): app = web.Application() - app.add_routes([web.get('/hello', hello)]) + app.add_routes([web.get("/hello", hello)]) # Add all aiohttp routes to the APISpec for route in app.router.routes(): @@ -34,8 +35,8 @@ async def hello(request): route=route, ) - pprint(spec.to_dict()['paths']) - #{'/hello': {'get': {'description': 'Get a greeting', + pprint(spec.to_dict()["paths"]) + # {'/hello': {'get': {'description': 'Get a greeting', # 'responses': {'200': {'content': {'text/plain': {'schema': {'$ref': '#/definitions/Greeting'}}}, # 'description': 'A greeting to the ' # 'client'}}}}} diff --git a/src/apispec_webframeworks/bottle.py b/src/apispec_webframeworks/bottle.py index 1e2aebe..c7632a5 100644 --- a/src/apispec_webframeworks/bottle.py +++ b/src/apispec_webframeworks/bottle.py @@ -3,8 +3,11 @@ :: from bottle import route, default_app + app = default_app() - @route('/gists/') + + + @route("/gists/") def gist_detail(gist_id): '''Gist detail view. --- @@ -14,10 +17,11 @@ def gist_detail(gist_id): schema: $ref: '#/definitions/Gist' ''' - return 'detail for gist {}'.format(gist_id) + return "detail for gist {}".format(gist_id) + spec.path(view=gist_detail) - print(spec.to_dict()['paths']) + print(spec.to_dict()["paths"]) # {'/gists/{gist_id}': {'get': {'responses': {200: {'schema': {'$ref': '#/definitions/Gist'}}}}}} """ # noqa: E501 diff --git a/src/apispec_webframeworks/flask.py b/src/apispec_webframeworks/flask.py index c7c7e24..2365087 100644 --- a/src/apispec_webframeworks/flask.py +++ b/src/apispec_webframeworks/flask.py @@ -7,7 +7,8 @@ app = Flask(__name__) - @app.route('/gists/') + + @app.route("/gists/") def gist_detail(gist_id): '''Gist detail view. --- @@ -18,11 +19,12 @@ def gist_detail(gist_id): schema: $ref: '#/definitions/Gist' ''' - return 'detail for gist {}'.format(gist_id) + return "detail for gist {}".format(gist_id) + with app.test_request_context(): spec.path(view=gist_detail) - print(spec.to_dict()['paths']) + print(spec.to_dict()["paths"]) # {'/gists/{gist_id}': {'get': {'responses': {200: {'schema': {'$ref': '#/definitions/Gist'}}}}, # 'x-extension': 'metadata'}} @@ -33,25 +35,28 @@ def gist_detail(gist_id): app = Flask(__name__) + class GistApi(MethodView): '''Gist API. --- x-extension: metadata ''' + def get(self): - '''Gist view - --- - responses: - 200: - schema: - $ref: '#/definitions/Gist' - ''' - pass + '''Gist view + --- + responses: + 200: + schema: + $ref: '#/definitions/Gist' + ''' + pass def post(self): - pass + pass + - method_view = GistApi.as_view('gists') + method_view = GistApi.as_view("gists") app.add_url_rule("/gists", view_func=method_view) with app.test_request_context(): spec.path(view=method_view) @@ -59,7 +64,7 @@ def post(self): # Alternatively, pass in an app object as a kwarg # spec.path(view=method_view, app=app) - print(spec.to_dict()['paths']) + print(spec.to_dict()["paths"]) # {'/gists': {'get': {'responses': {200: {'schema': {'$ref': '#/definitions/Gist'}}}}, # 'post': {}, # 'x-extension': 'metadata'}} diff --git a/src/apispec_webframeworks/tornado.py b/src/apispec_webframeworks/tornado.py index efd849e..c60af91 100644 --- a/src/apispec_webframeworks/tornado.py +++ b/src/apispec_webframeworks/tornado.py @@ -6,6 +6,7 @@ from tornado.web import RequestHandler + class HelloHandler(RequestHandler): def get(self): '''Get a greeting endpoint. @@ -19,9 +20,10 @@ def get(self): ''' self.write("hello") - urlspec = (r'/hello', HelloHandler) + + urlspec = (r"/hello", HelloHandler) spec.path(urlspec=urlspec) - pprint(spec.to_dict()['paths']) + pprint(spec.to_dict()["paths"]) # {'/hello': {'get': {'description': 'Get a greeting', # 'responses': {200: {'description': 'A greeting to the ' # 'client',