neuronaut
neuronaut

Reputation: 2709

How can I make enums in API Blueprint be DRY

I'm documenting an API using API Blueprint and I've got several endpoints that use the same enum type with the same values. Rather than repeat all of the values at every point where this enum is used I'd like to put it in the Data Structures section and just have a reference to it, thus making it DRY. However, I can't figure out from the documentation how to put an enum into the Data Structures section. I can do objects just fine, but it seems to ignore the specified members when I declare an enum in the Data Structures section.

Here's a (very contrived) example of what I have now (that is not DRY):

### Some Request [GET]
+ Parameters
    + name: `sample` (string) - the name
    + type: `A` (enum[string]) - the type
        + Members
            + A
            + B
            + C

### Another Request [GET]
+ Parameters
    + address: `123 St.` (string) - the address
    + type: `B` (enum[string]) - the same type as above
        + Members
            + A
            + B
            + C

And here's what I'd like to be able to do:

### Some Request [GET]
+ Parameters
    + name: `sample` (string) - the name
    + type: `A` (The Type) - the type

### Another Request [GET]
+ Parameters
    + address: `123 St.` (string) - the address
    + type: `A` (The Type) - the type

# Data Structures
## The Type (enum[string])
    + Members
        + A
        + B
        + C

I've tried a few variations on this syntax, all with no luck. Of course it's entirely possible that I'm just barking up the wrong tree and there's a completely different way to get repeated enums to be DRY.

Upvotes: 1

Views: 1068

Answers (1)

Honza Javorek
Honza Javorek

Reputation: 8796

The problem is you're trying to use MSON syntax for URI parameters, but that's not fully supported yet. For historical reasons, the current syntax of the Paramters section is only aligned with the syntax of the Attributes section, but there's not a full feature parity. See this RFC.

So I'm afraid you won't be able to use MSON inheritance and types in the Parameters section as of now. Only simple structures and types can be used.

Upvotes: 2

Related Questions