fcatae / Arda

Arda is an open source tool designed to manage team workloads.
42 stars 18 forks source link

ArdaSDK fails with invalid response HTTP 201 Create #92

Closed fcatae closed 7 years ago

fcatae commented 7 years ago

The problem happens in the integration test for AddItem method.

public void WorkspaceFolders_AddItems()
{
    // Add Test with different properties
    _client.WorkspaceFoldersService.AddItem(_user, new AddItemInput() { Title = "Test 1" });
    _client.WorkspaceFoldersService.AddItem(_user, new AddItemInput() { Title = "Test 2", Description = "123" });
    _client.WorkspaceFoldersService.AddItem(_user, new AddItemInput() { Title = "Test 3", ItemState = 2 });
}
fcatae commented 7 years ago

The problem happens in the AddItem method.

public IActionResult AddItem(string folderId, [FromBody,Required] AddItemInput workloadInput)
{
    if (folderId == null || folderId == "")
        return BadRequest("folderId is empty");
...
...
...
    return CreatedAtRoute("GetItem", new { itemId = workload.Id }, workload);
}

Solution:

Add the attribute ProducesResponseType to the method in order to indicate the return type:

[HttpPost("{folderId}/add")]
[ProducesResponseType(typeof(WorkspaceItem), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult AddItem(string folderId, [FromBody,Required] AddItemInput workloadInput)
{
...
...

The swagger.json will reflect the code, and AutoRest will produce the correct code. ArdaSDK client will work correctly.