mkon / openapi_contracts Goto Github PK
View Code? Open in Web Editor NEWOpenapi schemas as API contracts
License: MIT License
Openapi schemas as API contracts
License: MIT License
Hi @mkon,
I would really love to see the feature of Request schema validation working similarly to Response schema validation and I see you put it in Future Plans. Do you have any idea when this could be?
I would like to try implementing this myself but first wanted to check with you and see what you think about it, maybe you have some general guidelines or ideas you want me to follow or something like that.
Thank you in advance for your response.
Best regards.
Ruby 3.3 has been released in December.
Could openapi_contracts be upgraded/modified to support the new stable version.
I use Redocly to bundle and split my OpenAPI 3.1.0 spec, which includes webhooks documented under the webhook
field.
Based on the first line in the README, and no mention of limited support for OpenAPI 3.1.0, I expected this to work.
Currently supports OpenAPI documentation in the structure as used by Redocly, but should also work for single file schemas.
Instead, when I try to parse my spec (here's the main file), I receive this error:
RuntimeError:
Unknown file: #<Pathname:webhooks/account.created.yaml>
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser/transformers/pointer.rb:29:in `transform_pointer'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser/transformers/pointer.rb:20:in `transform_refs'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser/transformers/pointer.rb:5:in `call'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:59:in `block in transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:59:in `each'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:59:in `transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `block in transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `each_value'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `block in transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `each_value'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:58:in `transform_objects!'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:51:in `block in file_to_data'
# <internal:kernel>:90:in `tap'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:50:in `file_to_data'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:24:in `block in parse'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:21:in `each'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:21:in `each_with_object'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:21:in `parse'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/parser.rb:8:in `call'
# /usr/local/bundle/gems/openapi_contracts-0.13.0/lib/openapi_contracts/doc.rb:14:in `parse'
Hi @mkon,
we're getting the following error after updating to 0.7.0:
TypeError:
no implicit conversion of String into Integer
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/schema.rb:29:in `[]'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/schema.rb:29:in `[]'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/method.rb:5:in `initialize'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/path.rb:6:in `new'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/path.rb:6:in `block in initialize'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/schema.rb:29:in `to_h'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/schema.rb:29:in `to_h'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc/path.rb:5:in `initialize'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:20:in `new'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:20:in `block in initialize'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:19:in `to_h'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:19:in `initialize'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:12:in `new'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/openapi_contracts-0.7.0/lib/openapi_contracts/doc.rb:12:in `parse'
# ./spec/support/helpers/openapi_helper.rb:3:in `oas'
# ./spec/controllers/api/v1/configuration/languages_controller_spec.rb:36:in `block (3 levels) in <top (required)>'
# /Users/kmeyer/.rvm/gems/ruby-3.1.3@service-dbs-configuration/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
I did a bit of debugging and figured out being related to the case when having a parameters:
block shared between the defined methods of a certain path.
Here a way to reproduce it via change in the fixtures:
diff --git spec/fixtures/openapi/paths/message.yaml spec/fixtures/openapi/paths/message.yaml
index 6961280..e122d26 100644
--- spec/fixtures/openapi/paths/message.yaml
+++ spec/fixtures/openapi/paths/message.yaml
@@ -1,16 +1,16 @@
+parameters:
+- name: id
+ in: path
+ description: Id of the message.
+ required: true
+ schema:
+ type: string
get:
tags:
- Message
summary: Get Message
description: Get Message
operationId: get_message
- parameters:
- - name: id
- in: path
- description: Id of the message.
- required: true
- schema:
- type: string
responses:
The issue seems to be mainly the parameters
key not being filtered out here (or in the logic before):
Let me know if I should try to provide a fix or if you want to do it on your own.
Thanks, Klaus
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.