openapi-core
openapi-core copied to clipboard
Request for documentation
Please describe the request
object for the request_parameters_factory.create
. Can't find it in source code.
Is it possible to validate a response data?
I have this work in progress still. Request object should implement BaseOpenAPIRequest (from wrappers) interface (currently it is based on Request from werkzeug).
It really is time for some documentations :) Are you working on it or should I start?
@mes3yd hi. I'm still out of time this month so feel free to start if you can. Cheers.
Ok, I'll start by fixing a few bugs and documenting the methods I'm fixing.
Some documentation would be very useful, I've been getting into the code and I'd like to contribute some things that may be missing. A list of what is and isn't supported or validated from the OpenAPI spec, additional features, would be a great starting point. I'm taking a stab at some formats and regex patterns for instance, but it's not clear what's done already, or where.
Hi, is there any update to the process? I've just found your project while trying to find resources on how to build a flask API with swagger support. I have a specification and I want to:
- Use validation in requests
- ~Generate client libraries~ edit: this can be done with swagger-codegen
Is this something openapi-core can dow? If yes, are there some resources on how I can use it for my purposes?
Edit: I figured out 1)
with app.test_client() as client:
path = '/v1/healthz'
with app.test_request_context(path):
with open("spec.yml") as stream:
spec = create_spec(safe_load(stream))
openapi_response = FlaskOpenAPIResponse(client.get(path))
openapi_request = FlaskOpenAPIRequest(request)
validator = ResponseValidator(spec)
result = validator.validate(openapi_request, openapi_response)
result.raise_for_errors()
Possibly a little late to the party. But for those who find this package (which is great) and need a little more of a helping hand to get started. I've put my code below to show how to validate a request. Note that I use yaml for my OpenAPI specification and use the python requests library.
import yaml
import requests
from openapi_core import Spec
from openapi_core.contrib.requests import RequestsOpenAPIRequest
from openapi_core.validation.request import openapi_request_validator
openapi_spec_path = "somewhere/in/your/repo/openapi.yaml"
with open(openapi_spec_path) as f:
openapi_spec = yaml.safe_load(f)
spec = Spec.create(openapi_spec)
requests_request = requests.Request(
method="POST",
url="foo"
headers={
"content-type": "application/json",
"X-my-api-key": "1234"
},
json={},
)
openapi_request = RequestsOpenAPIRequest(requests_request)
result = openapi_request_validator.validate(spec, openapi_request)
It's not too bad and I worked out what to do after looking at the testing file here: tests/integration/contrib/requests/test_requests_validation.py.
have fun