danielgtaylor / aglio

An API Blueprint renderer with theme support that outputs static HTML
4.75k stars 480 forks source link

Prefer Body attribute in request if provided #357

Open jjatria opened 6 years ago

jjatria commented 6 years ago

Take a simple document like this one:

FORMAT: 1A
HOST: https://cold.pizza

# Some API

# Root [POST /foo]

+ Request (application/xml)

    + Attributes (foo)

    + Body

            <?xml version="1.0" encoding="UTF-8"?>
            <foo>
                <bar>something</bar>
            </foo>

+ Response 200 (application/xml)

    + Attributes (result)

    + Body

            <?xml version="1.0" encoding="UTF-8"?>
            <result>
                <status>OK</status>
            </result>

## Data Structures

### `result`

- result (status, required)

### `status`

- status: OK (string, required)

### `foo`

- foo (required, bar)

### `bar`

- bar: woof (required, string)

When rendered using the default template (is this different with any others?) both the request and the response elements render the body as JSON instead of XML, even though the content-type header is correctly detected.

aglio_json_v_xml

Note also that the example string for the rendered body ("woof") is taken from the Data Structures section instead of the provided Body (in which case it would be "something").

I propose two changes to fix this: