apiaryio / mson

Markdown Syntax for Object Notation
MIT License
903 stars 180 forks source link

How to enum as custom type? #84

Closed enumag closed 7 years ago

enumag commented 7 years ago

Currently I have this:

## Invoice (object)
+ id: `1` (number)
... some other fields
+ status: `3` (enum[number])
    + Members
        + `0` - Draft
        + `1` - Unpaid
        + `2` - Partially paid
        + `3` - Paid
        + `4` - Void

Now I need to use the InvoiceStatus elsewhere as well and I don't want to repeat the members definition. So I need to define InvoiceStatus as custom type:

## Invoice (object)
+ id: `1` (number)
... some other fields
+ status: `3` (InvoiceStatus)

## InvoiceStatus (enum[number])
+ Members
    + `0` - Draft
    + `1` - Unpaid
    + `2` - Partially paid
    + `3` - Paid
    + `4` - Void

This however causes error Apiary service responded with an error: Document you are trying to publish is not valid. (expected header block, e.g. '# <text>'). How can I define such type then? What I need to achieve is basically array[InvoiceStatus] for my filtering API.

kylef commented 7 years ago

@enumag + Members directive isn't correct for a data structure, only when you are embedding data structures inside another.

You can remove + Members as follows:

# Data Structures

## Invoice (object)
+ id: `1` (number)
+ status: `3` (InvoiceStatus)

## InvoiceStatus (enum[number])
+ `0` - Draft
+ `1` - Unpaid
+ `2` - Partially paid
+ `3` - Paid
+ `4` - Void

Or convert Members to a heading as follows:

# Data Structures

## Invoice (object)
+ id: `1` (number)
+ status: `3` (InvoiceStatus)

## InvoiceStatus (enum[number])

### Members

+ `0` - Draft
+ `1` - Unpaid
+ `2` - Partially paid
+ `3` - Paid
+ `4` - Void
enumag commented 7 years ago

@kylef Thanks!