Skip to content

Commit

Permalink
Merge pull request #74 from NoGRo/patch-1
Browse files Browse the repository at this point in the history
Enhanced HTTP status code 200 handling for API responses
  • Loading branch information
christianhelle authored Jun 15, 2023
2 parents b7b5bf9 + 8c39410 commit 577362c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Refitter.Core/RefitInterfaceGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using NSwag;
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace Refitter.Core;

Expand Down Expand Up @@ -42,9 +44,10 @@ private string GenerateInterfaceBody()
{
var operation = operations.Value;

var returnTypeParameter = operation.Responses.ContainsKey("200")
? generator.GetTypeName(operation.Responses["200"].ActualResponse.Schema, true, null)
: null;
var returnTypeParameter = new[] { "200", "201", "203", "206" }
.Where(code => operation.Responses.ContainsKey(code))
.Select(code => generator.GetTypeName(operation.Responses[code].ActualResponse.Schema, true, null))
.FirstOrDefault();

var returnType = GetReturnType(returnTypeParameter);

Expand Down Expand Up @@ -116,4 +119,4 @@ private string GenerateInterfaceDeclaration()
var modifier = settings.TypeAccessibility.ToString().ToLowerInvariant();
return $"{Separator}{modifier} interface I{title.CapitalizeFirstCharacter()}";
}
}
}

0 comments on commit 577362c

Please sign in to comment.