openapi_contracts 0.7.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -19
  3. data/lib/openapi_contracts/doc/operation.rb +27 -0
  4. data/lib/openapi_contracts/doc/parameter.rb +49 -0
  5. data/lib/openapi_contracts/doc/path.rb +32 -12
  6. data/lib/openapi_contracts/doc/pointer.rb +81 -0
  7. data/lib/openapi_contracts/doc/request.rb +17 -0
  8. data/lib/openapi_contracts/doc/response.rb +5 -5
  9. data/lib/openapi_contracts/doc/schema.rb +44 -10
  10. data/lib/openapi_contracts/doc/with_parameters.rb +9 -0
  11. data/lib/openapi_contracts/doc.rb +17 -14
  12. data/lib/openapi_contracts/match.rb +34 -10
  13. data/lib/openapi_contracts/operation_router.rb +33 -0
  14. data/lib/openapi_contracts/parser/transformers/base.rb +15 -0
  15. data/lib/openapi_contracts/parser/transformers/nullable.rb +10 -0
  16. data/lib/openapi_contracts/parser/transformers/pointer.rb +34 -0
  17. data/lib/openapi_contracts/parser/transformers.rb +5 -0
  18. data/lib/openapi_contracts/parser.rb +61 -0
  19. data/lib/openapi_contracts/payload_parser.rb +39 -0
  20. data/lib/openapi_contracts/rspec.rb +2 -2
  21. data/lib/openapi_contracts/validators/base.rb +5 -1
  22. data/lib/openapi_contracts/validators/documented.rb +12 -5
  23. data/lib/openapi_contracts/validators/headers.rb +4 -0
  24. data/lib/openapi_contracts/validators/http_status.rb +2 -6
  25. data/lib/openapi_contracts/validators/request_body.rb +26 -0
  26. data/lib/openapi_contracts/validators/response_body.rb +28 -0
  27. data/lib/openapi_contracts/validators/schema_validation.rb +40 -0
  28. data/lib/openapi_contracts/validators.rb +9 -6
  29. data/lib/openapi_contracts.rb +11 -5
  30. metadata +31 -20
  31. data/lib/openapi_contracts/doc/file_parser.rb +0 -85
  32. data/lib/openapi_contracts/doc/method.rb +0 -18
  33. data/lib/openapi_contracts/doc/parser.rb +0 -44
  34. data/lib/openapi_contracts/validators/body.rb +0 -38
@@ -1,38 +0,0 @@
1
- module OpenapiContracts::Validators
2
- class Body < Base
3
- private
4
-
5
- def validate
6
- if spec.no_content?
7
- @errors << 'Expected empty response body' if response.body.present?
8
- elsif !spec.supports_content_type?(response_content_type)
9
- @errors << "Undocumented response with content-type #{response_content_type.inspect}"
10
- else
11
- validate_schema
12
- end
13
- end
14
-
15
- def validate_schema
16
- schema = spec.schema_for(response_content_type)
17
- # Trick JSONSchemer into validating only against the response schema
18
- schemer = JSONSchemer.schema(schema.raw.merge('$ref' => schema.fragment))
19
- schemer.validate(JSON(response.body)).each do |err|
20
- @errors << error_to_message(err)
21
- end
22
- end
23
-
24
- def error_to_message(error)
25
- if error.key?('details')
26
- error['details'].to_a.map do |(key, val)|
27
- "#{key.humanize}: #{val} at #{error['data_pointer']}"
28
- end.to_sentence
29
- else
30
- "#{error['data'].inspect} at #{error['data_pointer']} does not match the schema"
31
- end
32
- end
33
-
34
- def response_content_type
35
- response.headers['Content-Type'].split(';').first
36
- end
37
- end
38
- end