Open alandotcom opened 11 years ago
Can you please provide a small minimal example of a spec file and a .fdoc
file?
I ran into similar issue when mocking my response with DateTime. Apparently iso8601 on DateTime does not format UTC with a 'Z'. You can use ActiveSupport::TimeWithZone instead.
require 'active_support/core_ext'
=> true
ActiveSupport.use_standard_json_time_format
=> true
DateTime.new(2013, 5, 28).to_json
=> ""2013-05-28T00:00:00+00:00""
DateTime.new(2013, 5, 28).in_time_zone('UTC').to_json
=> "\"2013-05-28T00:00:00Z\""
ActiveSupport.use_standard_json_time_format = false
=> false
DateTime.new(2013, 5, 28).in_time_zone('UTC').to_json
=> "\"2013/05/28 00:00:00 +0000\""
Maybe you need to explicitly .iso8601
in your app?
require 'active_support/core_ext'
> DateTime.new(2013, 5, 28).in_time_zone('UTC').iso8601
=> "2013-05-28T00:00:00Z"
ActiveSupport.use_standard_json_time_format
is true
by default.
If it is false, you'll need to call iso8601
But you need to convert it to TimeWithZone because iso8601 on DateTime doesn't replace UTC with 'Z'
DateTime.new(2013, 5, 28).iso8601
=> ""2013-05-28T00:00:00+00:00""
I would try seeing if this worked, but getting another error now:
undefined method `each' for "???":String
This happens after generating the fdoc, then running the test again
I ran in exactly the same problem.
Here is my .fdoc
---
description: Endpoint to get guest movements from a given date up today.
responseCodes:
- status: 404
successful: false
description: Request cannot be satisfied due to bad request. In the body, usually,
there is a more detailed explanation about the reason of failure.
- status: 200
successful: true
description: Everything is OK.
requestParameters:
properties: {}
responseParameters:
properties: {}
description: An array guests movements grouped by facility.
type: array
items:
description: Guests movements on a single facility.
required: true
type: object
properties:
facility:
description: Represent a facility.
required: true
type: object
properties:
id:
description: Facility ID.
required: true
type: integer
example: 852
description:
description: Facility description.
required: false
type: string
example: Villa Felice
guests_movements:
description: A list of guests movements inside the facility.
required: true
type: array
items:
description: A list of movements by single guest and ward inside the facility.
required: true
type: object
properties:
guest_id:
description: The guest ID.
required: true
type: integer
example: 1650
movements:
description: A list of movements of the guest inside the ward.
required: true
type: array
items:
description: "???"
required: true
type: object
properties:
date:
description: "???"
required: true
type: string
format: date-time
example: '2014-10-24T10:29:00+02:00'
And here is a sample response which is considered to be invalid on date:
[{
"facility": {
"id": 852,
"description": "RESIDENZIALE"
},
"guests_movements": [{
"guest_id": 1650,
"movements": [{
"date": "2014-10-24T10:29:00+02:00"
}, {
"date": "2014-10-25T10:59:00+02:00"
}]
}, {
"guest_id": 5414,
"movements": [{
"date": "2014-10-03T11:12:00+02:00"
}, {
"date": "2014-10-03T11:12:00+02:00"
}]
}]
}]
The date is valid and validates ok if I try to put it as the only property of the response.
The problem seems related to the position of the date attribute.
Moreover, if I run the spec with scaffolding on (FDOC_SCAFFOLD=true
) the field is recognised as format: date-time
.
This will get fixed if you update json-schema in gemspec to >= 2.5.0 per this change https://github.com/ruby-json-schema/json-schema/commit/4e84940d956052d162b89c41104158b073fdb574
You might want to look at this changeset https://github.com/sromano/fdoc/commit/70f5ac3a2aab16e007c2fe7551e9e86acc7314c1
Unfortunately, this commit 2e5f93a5689740e3df195d5ceebef56a291b9ebc makes the update of json-schema infeasible.
Any chance to get this fixes?
After generating a template for a controller action (and tests passing), I run the specs again. I have some JSON keys 'created-at' and 'updated-at' that point to date-time strings. Fdoc is is giving an error for one of these fields.
I can confirm that the string is in the ISO8601 format. I parsed the response, converted the string to a DateTime object, then back to ISO8601 format and it's the same exact string I started with.