René's URL Explorer Experiment


Title: [Feature]: Support for injecting custom input in custom openapi error response format · Issue #910 · python-openapi/openapi-core · GitHub

Open Graph Title: [Feature]: Support for injecting custom input in custom openapi error response format · Issue #910 · python-openapi/openapi-core

X Title: [Feature]: Support for injecting custom input in custom openapi error response format · Issue #910 · python-openapi/openapi-core

Description: Suggested Behavior I would like to add a way to customize error response format and would like to add additional information in the error response generated by OpenAPI-Core currently the error response generated by OpenAPI-Core is as fol...

Open Graph Description: Suggested Behavior I would like to add a way to customize error response format and would like to add additional information in the error response generated by OpenAPI-Core currently the error resp...

X Description: Suggested Behavior I would like to add a way to customize error response format and would like to add additional information in the error response generated by OpenAPI-Core currently the error resp...

Opengraph URL: https://github.com/python-openapi/openapi-core/issues/910

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Feature]: Support for injecting custom input in custom openapi error response format","articleBody":"### Suggested Behavior\r\n\r\nI would like to add a way to customize error response format and would like to add additional information in the error response generated by OpenAPI-Core\r\n\r\ncurrently the error response generated by OpenAPI-Core is as follows\r\n```\r\n{\r\n    \"errors\": [\r\n        {\r\n            \"class\": \"\u003cclass 'openapi_core.validation.schemas.exceptions.InvalidSchemaValue'\u003e\",\r\n            \"status\": 400,\r\n            \"title\": \"Value {'flag': 'testF'} not valid for schema of type object: (\u003cValidationError: \\\"'testF' is too short\\\"\u003e,)\"\r\n        }\r\n    ]\r\n}\r\n```\r\n\r\nI want to customize the response in following format\r\n\r\n```\r\n{\r\n \"title\": \"Failed to execute your favorite API\"                       \\\\ Custom String provided by code\r\n\"causedBy\": [\r\n        \"Value {'flag': 'testF'} not valid for schema of type object: (\u003cValidationError: \\\"'testF' is too short\\\"     \\\\ Error Resposne generated by OpenAPI Core\r\n    ]\r\n}\r\n```\r\n\r\nAs you can see in the comments, the message in causedBy field includes error messages generated by OpenAPI Core module\r\nwhereas the message in title field includes data generated and injected by actual code\r\n\r\n### Why is this needed?\r\n\r\nThis is required to make OpenAPI core more flexible and customizable and become a better choice for openapi linters and validators.\r\n\r\nAlso If OpenAPI does not support cutomization on the content of response, then it would be a deal breaker for most of the implementation as most of the projects tries to maintain some standard format of response\r\n\r\n### References\r\n\r\nI came across `FlaskOpenAPIErrorsHandler class` and created a custom handler class which inherits from FlaskOpenAPIErrorsHandler class\r\n\r\nI used constructor of this class to inject custom fields and generate custom response accordingly.\r\n\r\nfollowing is my Flask code **server.py**\r\n```\r\n#!/usr/bin/python3\r\n\"\"\"Test server.\"\"\"\r\n\r\nfrom flask import Flask, request, jsonify\r\nfrom openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator, FlaskOpenAPIErrorsHandler\r\nfrom openapi_core import Spec\r\n\r\n# Custom Error Handler block\r\nclass MyCustomErrorHandler(FlaskOpenAPIErrorsHandler):\r\n    \"\"\"\"Custom Error Handler\"\"\"\r\n    def __init__(self, title:str):\r\n        self.title =  title\r\n\r\n    def handle(self, errors:list):\r\n        response_object =  jsonify({\r\n            \"title\": self.title,\r\n            \"causedBy\" : [self.handle_error(error) for error in errors]\r\n        })\r\n        response_object.error_code = 400\r\n        return response_object\r\n\r\n    def handle_error(self, error):\r\n        \"\"\"\r\n        Converts error object into error string message\r\n\r\n        :param error: Error object which stores exception message\r\n        :type error: Exception object\r\n        :return: Error message string corresponding to error object\r\n        :rtype: str\r\n        \"\"\"\r\n        if error.__cause__ is not None:\r\n            error = error.__cause__\r\n        return str(error)\r\n\r\nSPEC = \"test.yaml\"\r\napp = Flask(__name__)\r\n\r\nspec_object = Spec.from_file_path(SPEC)\r\nmy_error_handler_object = MyCustomErrorHandler(\"Failed to execute test API\")\r\nopenapi_decorator = FlaskOpenAPIViewDecorator.from_spec(spec_object, openapi_errors_handler=my_error_handler_object)\r\n\r\n@app.route(\"/test\", methods=[\"POST\"])\r\n@openapi_decorator\r\ndef read_permission():\r\n    \"\"\"Test function\"\"\"\r\n    temp =  jsonify({\r\n                    \"stri_normal_json\": request.json.get(\"flag\", 1)\r\n                })\r\n    print(dir(temp))\r\n    return temp\r\n\r\nif __name__ == \"__main__\":\r\n    app.run(host=\"0.0.0.0\", port=345, debug=True)\r\n\r\n#Valid request: curl -X POST http://localhost:345/test --data '{\"flag\":\"rohana\"}' -H 'Content-Type: application/json'\r\n\r\n#Invalid Request: curl -X POST http://localhost:345/test --data '{\"flag\":\"rohan\"}' -H 'Content-Type: application/json'\r\n```\r\n\r\nFollowing is OpenAPI Spec\r\n\r\n**test.yaml**\r\n```\r\nopenapi: '3.0.2'\r\ninfo:\r\n  title: Test Title\r\n  version: '1.0'\r\nservers:\r\n  - url: http://localhost:345/\r\npaths:\r\n  /test:\r\n    post:\r\n      requestBody:\r\n        content:\r\n          application/json:\r\n            schema:\r\n              type: object\r\n              required:\r\n                - flag\r\n              properties:\r\n                flag:\r\n                  x-pii: true\r\n                  type: string\r\n                  pattern: \"^[\\\\w.-]*$\"\r\n                  minLength: 6\r\n                  maxLength: 20\r\n      responses:\r\n        200:\r\n          description: Sample response\r\n          content:\r\n            application/json:\r\n              schema:\r\n                type: object\r\n                properties:\r\n                  stri_normal_json:\r\n                    type: string\r\n                    minLength: 6\r\n                    maxLength: 20\r\n```\r\n\r\nAs we can see in code, I am creating object of custom error handler and injecting custom string as part of constructor in above example following is the line\r\n```\r\nmy_error_handler_object = MyCustomErrorHandler(\"Failed to execute test API\")\r\n```\r\n\r\nFollowing is the output of curl request\r\n\r\n# Invalid Curl Request\r\n```\r\nroot@ip-10-31-1-220:~/playground# curl -X POST http://localhost:345/test --data '{\"flag\":\"rohan\"}' -H 'Content-Type: application/json'\r\n{\r\n  \"causedBy\": [\r\n    \"Value {'flag': 'rohan'} not valid for schema of type object: (\u003cValidationError: \\\"'rohan' is too short\\\"\u003e,)\"\r\n  ],\r\n  \"title\": \"Failed to execute test API\"\r\n}\r\n```\r\n\r\n# Valid Curl Request\r\n```\r\nroot@ip-10-31-1-220:~/playground# curl -X POST http://localhost:345/test --data '{\"flag\":\"rohana\"}' -H 'Content-Type: application/json'\r\n{\r\n  \"stri_normal_json\": \"rohana\"\r\n}\r\n```\r\nIn this way I was able to customize the response body and also inject my custom string when I create object of custom error handler. which was working fine till OpenAPI 0.16.x but **it started failing since OpenAPI 0.18.x**\r\n\r\nthis issue happened due to following pull request\r\nhttps://github.com/python-openapi/openapi-core/commit/22ace6d39607ef769ba0a36e8a24dc6df704a620\r\n\r\n### Would you like to implement a feature?\r\n\r\nYes","author":{"url":"https://github.com/rohan-97","@type":"Person","name":"rohan-97"},"datePublished":"2024-09-03T16:42:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/910/openapi-core/issues/910"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:533cc5a6-47f6-6181-a8dd-c492c4c572ce
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD08A:2477FA:896678:BC1E40:69775A42
html-safe-nonceba48a8710e352c787a940af26e0374c4e8ba7391f00729642dbbc29b0f941db5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDhBOjI0NzdGQTo4OTY2Nzg6QkMxRTQwOjY5Nzc1QTQyIiwidmlzaXRvcl9pZCI6IjQ1MzYxNDkyNDQ5NTEwOTE3NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac242bc5376be5f98799ce378d072ac12174c811dd81f33512d75489d89b34380e
hovercard-subject-tagissue:2503328483
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openapi/openapi-core/910/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5e6583b91d74e4e0f06545bfac658055133a2711d6bcb3c1c2622a0bf2f7f039/python-openapi/openapi-core/issues/910
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5e6583b91d74e4e0f06545bfac658055133a2711d6bcb3c1c2622a0bf2f7f039/python-openapi/openapi-core/issues/910
og:image:altSuggested Behavior I would like to add a way to customize error response format and would like to add additional information in the error response generated by OpenAPI-Core currently the error resp...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerohan-97
hostnamegithub.com
expected-hostnamegithub.com
None3310064f35a62c06a4024ba37f41c06836f39376a095c2dfd2c4b693c34965be
turbo-cache-controlno-preview
go-importgithub.com/python-openapi/openapi-core git https://github.com/python-openapi/openapi-core.git
octolytics-dimension-user_id126442889
octolytics-dimension-user_loginpython-openapi
octolytics-dimension-repository_id104200746
octolytics-dimension-repository_nwopython-openapi/openapi-core
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id104200746
octolytics-dimension-repository_network_root_nwopython-openapi/openapi-core
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release67d5f8d1d53c3cc4f49fc3bb8029933c3dc219e6
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openapi%2Fopenapi-core%2Fissues%2F910
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openapi%2Fopenapi-core%2Fissues%2F910
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-openapi%2Fopenapi-core
Reloadhttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910
Reloadhttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910
Reloadhttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910
python-openapi https://patch-diff.githubusercontent.com/python-openapi
openapi-corehttps://patch-diff.githubusercontent.com/python-openapi/openapi-core
Please reload this pagehttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-openapi%2Fopenapi-core
Fork 136 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-openapi%2Fopenapi-core
Star 356 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-openapi%2Fopenapi-core
Code https://patch-diff.githubusercontent.com/python-openapi/openapi-core
Issues 74 https://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues
Pull requests 13 https://patch-diff.githubusercontent.com/python-openapi/openapi-core/pulls
Discussions https://patch-diff.githubusercontent.com/python-openapi/openapi-core/discussions
Actions https://patch-diff.githubusercontent.com/python-openapi/openapi-core/actions
Projects 0 https://patch-diff.githubusercontent.com/python-openapi/openapi-core/projects
Security 0 https://patch-diff.githubusercontent.com/python-openapi/openapi-core/security
Insights https://patch-diff.githubusercontent.com/python-openapi/openapi-core/pulse
Code https://patch-diff.githubusercontent.com/python-openapi/openapi-core
Issues https://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues
Pull requests https://patch-diff.githubusercontent.com/python-openapi/openapi-core/pulls
Discussions https://patch-diff.githubusercontent.com/python-openapi/openapi-core/discussions
Actions https://patch-diff.githubusercontent.com/python-openapi/openapi-core/actions
Projects https://patch-diff.githubusercontent.com/python-openapi/openapi-core/projects
Security https://patch-diff.githubusercontent.com/python-openapi/openapi-core/security
Insights https://patch-diff.githubusercontent.com/python-openapi/openapi-core/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-openapi/openapi-core/issues/910
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-openapi/openapi-core/issues/910
[Feature]: Support for injecting custom input in custom openapi error response formathttps://patch-diff.githubusercontent.com/python-openapi/openapi-core/issues/910#top
kind/enhancementhttps://github.com/python-openapi/openapi-core/issues?q=state%3Aopen%20label%3A%22kind%2Fenhancement%22
https://github.com/rohan-97
https://github.com/rohan-97
rohan-97https://github.com/rohan-97
on Sep 3, 2024https://github.com/python-openapi/openapi-core/issues/910#issue-2503328483
22ace6dhttps://github.com/python-openapi/openapi-core/commit/22ace6d39607ef769ba0a36e8a24dc6df704a620
kind/enhancementhttps://github.com/python-openapi/openapi-core/issues?q=state%3Aopen%20label%3A%22kind%2Fenhancement%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.