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

HELP: SpecError Validator class not found#815

Unanswered
r1cc4rdo asked this question inQ&A
Discussion options

Not sure if misundestanding how to use the library -- I'm new to both OpenApi and openapi-core.

The code I'm using is very similar to the following:

from requests import Requestfrom openapi_core import OpenAPIfrom openapi_core.contrib.requests import RequestsOpenAPIRequestopenapi = OpenAPI.from_file_path('api_spec.json')request = Request('GET', 'https://example.com/status')openapi_request = RequestsOpenAPIRequest(request)openapi.validate_request(openapi_request)

It fails with the following stack trace:

---------------------------------------------------------------------------SpecError                                 Traceback (most recent call last)Cell In[210], line 8      6 request = Request('GET', 'https://example.com/status')      7 openapi_request = RequestsOpenAPIRequest(request)----> 8 openapi.validate_request(openapi_request)File ~/opt/anaconda3/envs/ptv/lib/python3.10/site-packages/openapi_core/app.py:347, in OpenAPI.validate_request(self, request)    345     self.validate_webhook_request(request)    346 else:--> 347     self.validate_apicall_request(request)File [~/opt/anaconda3/envs/ptv/lib/python3.10/site-packages/openapi_core/app.py:360](http://localhost:8888/lab/tree/~/opt/anaconda3/envs/ptv/lib/python3.10/site-packages/openapi_core/app.py#line=359), in OpenAPI.validate_apicall_request(self, request)    358 if not isinstance(request, Request):    359     raise TypeError("'request' argument is not type of Request")--> 360 self.request_validator.validate(request)File [~/opt/anaconda3/envs/ptv/lib/python3.10/site-packages/openapi_core/app.py:206](http://localhost:8888/lab/tree/~/opt/anaconda3/envs/ptv/lib/python3.10/site-packages/openapi_core/app.py#line=205), in OpenAPI.request_validator(self)    203 @property    204 def request_validator(self) -> RequestValidator:    205     if self.request_validator_cls is None:--> 206         raise SpecError("Validator class not found")    207     return self.request_validator_cls(    208         self.spec,    209         base_url=self.config.server_base_url,   (...)    217         security_provider_factory=self.config.security_provider_factory,    218     )SpecError: Validator class not found

Is the problem with my code or with the .json schema?
Thank you in advance!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

'SpecError' suggests is a problem with your specification. What OpenApi version are you using?

You must be logged in to vote
1 reply
@r1cc4rdo
Comment options

Thank you for your response!

'SpecError' suggests is a problem with your specification.

If that's the case, shouldn't the problem be caught at the act of instantiating the OpenAPI object?

What OpenApi version are you using?

Ah! I now believe it's v2. The API I'm trying to validate against liveshere, whilethis is the .json schema.
I originally thought it to be v3, but your question made me realize that the 'v3' references plastered all over the API website referred to the API revision, not of the specification. I guess I'll have to find an openapi-core equivalent for the v2 format? :)

For the record, the .json didn't load unmodified into the OpenAPI object because of a couple ofPointerToNowhere issues, which I fixed as follows:

wget https://timetableapi.ptv.vic.gov.au/swagger/docs/v3 -O original.jsoncat original.json| python -m json.tool> original_prettyprinted.json

and the following patch:

--- modified.json2024-03-26 01:39:11+++ original_prettyprinted.json2024-03-26 01:38:49@@ -3571,23 +3571,6 @@                 }             }         },-        "V3.FareEstimateResponse": {-            "type": "object",-            "properties": {-                "fare_estimate": {-                    "$ref": "#/definitions/V3.FareEstimate",-                    "description": "Resultant set fare estimates"-                },-                "status": {-                    "$ref": "#/definitions/V3.Status",-                    "description": "API Status / Metadata"-                }-            }-        },-        "V3.FareEstimate": {-            "type": "object",-            "properties": {}-        },         "V3.Disruptions": {             "type": "object",             "properties": {
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@r1cc4rdo@p1c2u

[8]ページ先頭

©2009-2025 Movatter.jp