danielgtaylor / danielgtaylor/aglio

Prefer Body attribute in request if provided

Open
#357 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
4.7k
Forks
471
PR merge metrics
No merged PRs in 30d

Description

Take a simple document like this one:

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

# Some API

# Root [POST /foo]

+ Request (application/xml)

+ Attributes (foo)

+ Body



something

+ Response 200 (application/xml)

+ Attributes (result)

+ Body



OK

## 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](https://user-images.githubusercontent.com/2975989/44903794-66722b00-ad05-11e8-94e3-8135fcef0d39.png)

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:

* Generate a request body from the attributes _only_ when no Body has been provided already (we can assume that if the user provided one it's because they wanted it).

* When generating a body, take into consideration what the content-type is for that request. There are probably too many to get it right, but we could definitely do better than forcing everything to use JSON no matter what.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.