openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Request for documentation

Open ghost opened this issue 7 years ago • 7 comments

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?

ghost avatar Oct 30 '17 14:10 ghost

I have this work in progress still. Request object should implement BaseOpenAPIRequest (from wrappers) interface (currently it is based on Request from werkzeug).

p1c2u avatar Oct 30 '17 14:10 p1c2u

It really is time for some documentations :) Are you working on it or should I start?

ghost avatar Jul 04 '18 11:07 ghost

@mes3yd hi. I'm still out of time this month so feel free to start if you can. Cheers.

p1c2u avatar Jul 04 '18 13:07 p1c2u

Ok, I'll start by fixing a few bugs and documenting the methods I'm fixing.

ghost avatar Jul 06 '18 07:07 ghost

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.

raybotha avatar Aug 23 '18 10:08 raybotha

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:

  1. Use validation in requests
  2. ~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()

obitech avatar Dec 15 '19 16:12 obitech

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

jarmanstephens avatar Jan 12 '23 03:01 jarmanstephens