Api-blueprint: Typed arrays don't render any values in JSON

Created on 23 Sep 2015  Â·  5Comments  Â·  Source: apiaryio/api-blueprint

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

Apiary.io Awaiting Input Tooling Implementation Bug

Most helpful comment

@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.

All 5 comments

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!

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.

@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.

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.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

teja5429 picture teja5429  Â·  9Comments

rodriguise picture rodriguise  Â·  11Comments

fgblomqvist picture fgblomqvist  Â·  3Comments

bazo picture bazo  Â·  8Comments

alronlam picture alronlam  Â·  4Comments