danielgtaylor / eidolon

Generate JSON or JSON Schema from Refract & MSON data structures
MIT License
6 stars 1 forks source link

(default) gets converted to null #12

Open Anahkiasen opened 8 years ago

Anahkiasen commented 8 years ago

Small reproducible test case:

const protagonist = require('protagonist');
const eidolon = require('eidolon');

const apib = `
# Data structures

## Foobar (object)
+ foo (enum)
    + bar (default)
    + baz
`;

protagonist.parse(apib, (errors, result) => {
    const dataStructure = result.content[0].content[0].content[0].content[0];
    const schema = eidolon.schema(dataStructure, {});

    console.log(
        JSON.stringify(schema, null, 4)
    );
});

This yields:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "foo": {
            "enum": [
                null,
                "baz"
            ]
        }
    }
}
Anahkiasen commented 8 years ago

Same thing happens with enums that reference other data structures, as seen in the MSON spec's repo:

- `href` (enum, optional)
    - (URL) - References an external ALPS descriptor element.
    - (Fragment) - References a local descriptor element.

This yields "enum": [null, null]