-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Test for embedded definitions (using single Swagger/OpenAPI file) #80
Comments
@Ajaxy could you share your schema definitions and the JSON you're trying to validate against them? |
It's just a regular {
"swagger": "2.0",
"info": {
"title": "My API 1.0",
"description": "...",
"version": "0.0.1"
},
"host": "...",
"basePath": "/v1",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
/* ... */
},
"tags": [
/* ... */
],
"definitions": {
"Clinic": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
},
"latitude": {
"type": "number"
},
"longitude": {
"type": "number"
}
},
"required": [
"name",
"address",
"latitude",
"longitude"
]
},
/* ... */
}
} So I'm to trying to check it like this: expect(result[:clinics][0]).to match_json_schema('swagger.json#/Clinic') |
I would love to be able to use my OpenAPI schema as the base file for validations. @seanpdoyle Any update on if this is possible? For example for the attached file I want to match the response from the
|
@barnaclebarnes I was able to do this with this code: require 'json'
require 'json_matchers/rspec'
JsonMatchers.schema_root = 'spec/schemas'
file = File.read 'spec/schemas/swagger.json'
swagger = JSON.parse(file, symbolize_names: true)
# Fix for json_matchers single-file restriction
swagger[:definitions].keys.each do |key|
File.open("spec/schemas/#{key}.json", 'w') do |f|
f.write(JSON.pretty_generate({
'$ref': "swagger.json#/definitions/#{key}"
}))
end
end |
I have a JSON file with embedded schemas in the
definitions
object. Is it possible to test for those schemas straight withmatch_json_schema()
?Neither
match_json_schema('openapi#/definitions/SomeSchema')
ormatch_json_schema('openapi.json#/definitions/SomeSchema')
are seem to work, so now I have to manually create separate files for each schema of my definitions before I run tests.The text was updated successfully, but these errors were encountered: