Почему не работает ключевое слово const
, если оно работает с enum
?
с enum
, rspec завершается неудачно:
{
"id": "https://json-schema.org/geo",
"$schema": "https://json-schema.org/draft-06/schema#",
"description": "unauthorized authentication",
"type": "object",
"required": ["error"],
"properties": {
"error": { "enum": ["Xinvalid credentials"] }
}
}
Failure/Error: expect(response).to match_json_schema('api/v1/user/unauthorized_authentication')
#/error: failed schema #/properties/error: Invalid credentials is not a member of ["Xinvalid credentials"].
---
expected
{
"error": "Invalid credentials"
}
to match schema "api/v1/user/unauthorized_authentication":
{
"id": "https://json-schema.org/geo",
"$schema": "https://json-schema.org/draft-06/schema#",
"description": "unauthorized authentication",
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"enum": [
"Xinvalid credentials"
]
}
}
}
# ./spec/requests/api/v1/users/authenticate_spec.rb:34:in `block (3 levels) in <main>'
Если я изменю это enum
на const
(или constant
) (без скобок), не выйдет из строя, почему?
{
"id": "https://json-schema.org/geo",
"$schema": "https://json-schema.org/draft-06/schema#",
"description": "unauthorized authentication",
"type": "object",
"required": ["error"],
"properties": {
"error": { "const": "Xinvalid credentials" }
}
}
Тест в порядке, но согласно документы должны провалиться
[POST] /api/v1/users/authenticate
User tries to authenticate with invalid redentials
returns an invalid credentials message
behaves like unauthorized endpoint
returns 403 http status code
behaves like json header
returns content-type: application/json header
Finished in 0.35215 seconds (files took 4.13 seconds to load)
3 examples, 0 failures
Спасибо