Skip to content
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

Typed arrays don't render any values in JSON #271

Closed
annappropriate opened this issue Sep 23, 2015 · 5 comments
Closed

Typed arrays don't render any values in JSON #271

annappropriate opened this issue Sep 23, 2015 · 5 comments

Comments

@annappropriate
Copy link

I'm trying to use something like (array[number]) which should be possible according to MSON spec .
I want to have an array of numbers with resulting JSON { "foo" : [1, 99] } and preferrably type information in schema.

  • - foo: 1, 99 (array) renders {"foo": [ "1", "99" ]}
  • - foo: 1, 99 (array[number]) renders { "foo": [] }

The only way I got proper number array JSON was

- foo (array)
    - 1 (number)
    - 99 (number)

but this is way longer plus it's still not an array of numbers, just an array which elements happen to be numbers.
Also no type info is generated in schema in any case, it's always "foo": { "type": "array" }.
What am I missing here?

Test suite: http://docs.typedarraytest.apiary.io/#reference/default/foo/test

@zdne
Copy link
Contributor

zdne commented Sep 23, 2015

Hey @sheela-na-geek , this is actually (a known) bug in the JSON renderer. We have it fixed in our parser – Drafter – but it hasn't been released on Apiary.io production just yet.

We will update this issue once the fix is published on Apiary.io.

Regarding the schema – this is a bug as well and we are working towards its fix. Please note MSON is still considered in beta quality, we do our best to squash all these bugs as soon as possible! But please keep them reporting 😀

Thanks!

@LukeWinikates
Copy link

I just encountered this as well, and ended up working around it by adding an explicit + Schema block with the right json schema for my use case.

Looks like the fix hasn't landed on apiary.io yet, and the last activity here was several months ago. I'd be happy to see this fixed.

@pksunkara
Copy link
Contributor

@LukeWinikates Can you give the related part of the API Blueprint? The fix has been landed in Apiary, so I am wondering if you are running into another bug. Thanks.

@LukeWinikates
Copy link

Sorry for the delayed response here. Here's a repro.

FORMAT: 1A
HOST: http://polls.apiblueprint.org/

# typed-array-example


## Rocks [/rocks]


### List All Rocks [GET]

+ Response 200 (application/json;charset=UTF-8)

    + Attributes (array[Rock])

    + Body

            [
              {
                "id": "124",
                "title": "marble",
                "type": "metamorphic"
              }
            ]


# Data Structures
## Rock (object)
+ `id` (string, required) -
+ `title` (string, required) - e.g. basalt, marble, diamond
+ `type` (enum[string], required) 
    + Members
        + igneous
        + metamorphic
        + sedimentary

In the apiary editor, the JSON schema generated looks like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array"
}

I would have expected the generated schema to include the schema for the Rock data structure as well.

@kylef
Copy link
Member

kylef commented Oct 14, 2016

@LukeWinikates By default, an array in MSON doesn't have a fixed type. An array may contain the sample values you've specified or anything else. If you would like to make the JSON Schema of a fixed type, you will need to add the fixed-type keyword as shown here:

+ Attributes (array[Rock], fixed-type)

The original problem in this issue that was discussed have been fixed for some time now.

@kylef kylef closed this as completed Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants