Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix support of custom error handler in Django decorator#979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mik-laj wants to merge1 commit intopython-openapi:master
base:master
Choose a base branch
Loading
frommik-laj:django-decorator-fix
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletiondocs/integrations/django.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,7 +66,7 @@ Use `DjangoOpenAPIViewDecorator` with the OpenAPI object to create the decorator
``` python hl_lines="1 3 6"
from openapi_core.contrib.django.decorators import DjangoOpenAPIViewDecorator

openapi_validated =FlaskOpenAPIViewDecorator(openapi)
openapi_validated =DjangoOpenAPIViewDecorator(openapi)


@openapi_validated
Expand Down
1 change: 1 addition & 0 deletionsopenapi_core/contrib/django/decorators.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,6 +48,7 @@ def __init__(

self.request_cls = request_cls
self.response_cls = response_cls
self.errors_handler_cls = errors_handler_cls

def __call__(self, view_func: Callable[..., Any]) -> Callable[..., Any]:
"""
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
from pathlib import Path
from typing import Any
from typing import Dict

from django.http import HttpResponse
from jsonschema_path import SchemaPath

from openapi_core.contrib.django.decorators import DjangoOpenAPIViewDecorator
from openapi_core.contrib.django.handlers import DjangoOpenAPIErrorsHandler


class AppDjangoOpenAPIValidRequestHandler(DjangoOpenAPIErrorsHandler):
@classmethod
def format_openapi_error(cls, error: BaseException) -> Dict[str, Any]:
ret = DjangoOpenAPIErrorsHandler.format_openapi_error(error)
ret["title"] = ret["title"].upper()
return ret


check_minimal_spec = DjangoOpenAPIViewDecorator.from_spec(
SchemaPath.from_file_path(
Path("tests/integration/data/v3.0/minimal_with_servers.yaml")
)
),
errors_handler_cls=AppDjangoOpenAPIValidRequestHandler,
)


Expand Down
4 changes: 4 additions & 0 deletionstests/integration/contrib/django/test_django_project.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -460,3 +460,7 @@ def test_post_valid(self, client):
)

assert response.status_code == 405 # Method Not Allowed
assert (
response.json()["errors"][0]["title"]
== "OPERATION POST NOT FOUND FOR HTTP://PETSTORE.SWAGGER.IO/STATUS"
)
Loading

[8]ページ先頭

©2009-2025 Movatter.jp