Skip to content

Commit

Permalink
Merge pull request #7 from MobileTeleSystems/feture/upd_sdk
Browse files Browse the repository at this point in the history
Upd Sdk + fix NRE
  • Loading branch information
genusP authored Dec 5, 2024
2 parents adddbe7 + af6c187 commit 67485fe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ApiCodeGenerator.OpenApi.Sdk" Version="3.0.0-rc.18" />
<PackageReference Include="ApiCodeGenerator.OpenApi.Sdk" Version="3.0.0-rc.44" />
<PackageReference Include="NSwag.Core.Yaml" Version="14.0.2" />
<PackageReference Include="NSwag.CodeGeneration.CSharp" Version="14.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
Expand Down
4 changes: 2 additions & 2 deletions ApiCodeGenerator.OpenApi.Refit.Tests/FormDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public async Task FormData()
" /// <returns>valid input</returns>\n" +
" /// <exception cref=\"Refit.ApiException\">A server side error occurred.</exception>\n" +
" [Post(\"/test\")]\n" +
$" System.Threading.Tasks.Task GetTest([Body(BodySerializationMethod.UrlEncoded)]GetTestFormData body);\n" +
$" System.Threading.Tasks.Task GetTest([Body(BodySerializationMethod.UrlEncoded)]Body body);\n" +
"\n" +
" }\n";
var expectedClassCode =
$" {GENERATED_CODE}\n" +
" public partial class GetTestFormData\n" +
" public partial class Body\n" +
" {\n" +
" [Newtonsoft.Json.JsonProperty(\"testProp\", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]\n" +
" public string TestProp { get; set; }\n" +
Expand Down
30 changes: 30 additions & 0 deletions ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,36 @@ public void GenerateClientInterface_NotBringDefaultParamsToEnd_IfOptParamDisable
RunTest(settings, expected, "defaultParamTestSchema.json");
}

[Test]
public void ExcludeParam()
{
var settings = new RefitCodeGeneratorSettings
{
GenerateClientInterfaces = true,
ExcludedParameterNames = [
"paramWithDef"
],
CSharpGeneratorSettings = { Namespace = "TestNS" },
};

var expected =
" public partial interface IClient\n" +
" {\n" +
" /// <summary>\n" +
" /// Test operation\n" +
" /// </summary>\n" +
" /// <param name=\"queryParametr\">Параметр передаваемый в строке запроса</param>\n" +
" /// <returns>Запрос успешно принят</returns>\n" +
" /// <exception cref=\"Refit.ApiException\">A server side error occurred.</exception>\n" +
" [Get(\"/testService/testOper\")]\n" +
" System.Threading.Tasks.Task<TestOperResponse> GetTestOper([Query]string queryParametr);\n" +
"\n" +
" }\n";

//Act & Assert
RunTest(settings, expected, "defaultParamTestSchema.json");
}

[Test]
public void GenerateClientInterface_AuthHeaderParameter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="ApiCodeGenerator.OpenApi.Sdk/3.0.0-rc.18">
<Project Sdk="ApiCodeGenerator.OpenApi.Sdk/3.0.0-rc.44">

<PropertyGroup>
<Description>Generates code for the Refit library from an OpenApi document.</Description>
Expand Down
29 changes: 16 additions & 13 deletions ApiCodeGenerator.OpenApi.Refit/Model/RefitOperationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,27 @@ internal void InitWrappedQueryParameters()

protected override string ResolveParameterType(OpenApiParameter parameter)
{
if (ConsumesFormUrlEncoded && parameter.Kind == OpenApiParameterKind.Body)
if (Settings is not null)
{
var isNullable = parameter.IsRequired == false || parameter.IsNullable(Settings.CodeGeneratorSettings.SchemaType);
var typeNameHint = $"{Id}FormData";
return _resolver?.Resolve(parameter.ActualSchema, isNullable, typeNameHint);
}

if (_resolver is not null && HasFormParameters)
{
var typeName = Settings.BinaryPartType;
if (parameter.IsBinaryBodyParameter || parameter.ActualSchema.IsBinary)
if (ConsumesFormUrlEncoded && parameter.Kind == OpenApiParameterKind.Body)
{
return typeName;
var isNullable = parameter.IsRequired == false || parameter.IsNullable(Settings.CodeGeneratorSettings.SchemaType);
var typeNameHint = $"{Id}FormData";
return _resolver?.Resolve(parameter.ActualSchema, isNullable, typeNameHint);
}

if (parameter.ActualSchema.IsArray && parameter.ActualSchema.Item.IsBinary)
if (_resolver is not null && HasFormParameters)
{
return $"{Settings.CSharpGeneratorSettings.ArrayType}<{typeName}>";
var typeName = Settings.BinaryPartType;
if (parameter.IsBinaryBodyParameter || parameter.ActualSchema.IsBinary)
{
return typeName;
}

if (parameter.ActualSchema.IsArray && parameter.ActualSchema.Item.IsBinary)
{
return $"{Settings.CSharpGeneratorSettings.ArrayType}<{typeName}>";
}
}
}

Expand Down

0 comments on commit 67485fe

Please sign in to comment.