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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manual request/response validation #195
Comments
That looks great! I suppose the |
I would rather go the other way around and |
Hi @MrBananaLord and @twe4ked and others, This text is mainly for me to clarify the different interface approaches, but any thoughts on this would be much appreciated. I am working on changing the structure of the gem to make it simpler to either use a ready-made middleware or build your own middleware. In my head I am aiming for the following high level interface and would love to get feedback on this: Variant 1 – Runtime request interfacedefinition = OpenapiFirst.load('petstore.yaml')
definition.request(rack_request).validate # or validate! to validate the request
# #request will never return nil even if the request is not defind in the API description
# Inspect how the current request matches the API description. (Low level interface)
request = definition.request(rack_request)
request.defined? # (or similar name) return true if request is defined (operation and path_item are defined), false if not.
request.operation # returns nil if the request method is not defined
request.path_item # returns nil if the path is unknown
# Validate the response
definition.request(rack_request).response(rack_response).validate # or validate! to validate the response One good thing about this interface is that the user does not need to know about OpenAPI internals (path items, operations) to validate a request. This interface should also work with the current state of the OpenAPI 4.0 discussion. Variant 2 – Document tree interfacedefinition = OpenapiFirst.load('petstore.yaml')
# Navigate through the API description document until you find the operation for the current request and validate it.
# Note that path_item and operation methods return nil if the request does not match the API description.
definition.path_item(rack_request.path).operation(request.method).validate(request)
## Validate the response
operation = definition.path_item(rack_request.path).operation(request.method)
operation.response(rack_response.status).validate(rack_response) This is very simple, but the user needs at least know about how to find path items and operations in an OpenAPI document. Also this interface wont't work with the current state of OpenAPI 4.0. Any thoughts? |
Thanks for this @ahx! Variant 1 looks good to me, good that it should be future proof for OpenAPI 4.0 too. 💯 |
Hi @ahx, Variant 1 would be my preferred one :) thanks for the work on this! |
Should be solved with #202 |
The idea is to programatically validate requests/responses.
See also #169 (comment) #140.
Api proposal:
UPDATE: See Variant 1
The text was updated successfully, but these errors were encountered: