You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to consume an OpenAPI 3.0 that is defined by a vendor. Thus, I don't have the option to modify the OpenAPI specification. My goal is to generate a .NET Core C# client based on their specification. In Visual Studio I have added the vendor's OpenAPI specification which generates the code for the C# client. The generated code refers to a class called Anonymous that is undefined. Thus, the code does not compile unless I stub these Anonymous classes.
Here is a simplified OpenAPI specification that reproduces the problem. I downloaded the NSwag code and added a unit test to verify the behavior I see. The API contains the following types: Pet, Value, SingleValue, MultiValue, ValueEntry.
[Fact]
public async Task When_generating_csharp_with_inheritance_code_is_generated_without_anonymous_classes_petstore_4_example()
{
// Arrange
var json = await File.ReadAllTextAsync(@".\Data\petstore-4.json");
try
{
var document = await OpenApiDocument.FromJsonAsync(json);
// Act
var settings = new CSharpClientGeneratorSettings();
var generator = new CSharpClientGenerator(document, settings);
var code = generator.GenerateFile();
// Assert
Assert.Contains("public partial class Pet", code);
Assert.Contains("public partial class Value", code);
Assert.Contains("public partial class SingleValue", code);
Assert.Contains("public partial class MultiValue", code);
Assert.Contains("public partial class ValueEntry", code);
Assert.DoesNotContain("public System.Collections.Generic.IDictionary<string, Anonymous> Values", code);
}
catch (Exception e)
{
var msg = e.Message;
}
}
I would expect the generated code to contain SingleValue, which it doesn't. Then, more critically, it generates a dictionary of type <string, Anonymous> and this fails to compile because Anonymous is unknown.
Does my mock API make sense? It replicates the exact problem I get with the fullscale API that I have no control over. Are there any options I have overlooked in the CSharpClientGeneratorSettings?
The text was updated successfully, but these errors were encountered:
I don't think so. There are a few issues open over on the NJsonSchema repo to attempt to handle this problem (which trickles down to codegens). The inheritance structure of the oneOf is not handled with OpenAPI 3.0+ with Nswag.
I am trying to consume an OpenAPI 3.0 that is defined by a vendor. Thus, I don't have the option to modify the OpenAPI specification. My goal is to generate a .NET Core C# client based on their specification. In Visual Studio I have added the vendor's OpenAPI specification which generates the code for the C# client. The generated code refers to a class called Anonymous that is undefined. Thus, the code does not compile unless I stub these Anonymous classes.
Here is a simplified OpenAPI specification that reproduces the problem. I downloaded the NSwag code and added a unit test to verify the behavior I see. The API contains the following types: Pet, Value, SingleValue, MultiValue, ValueEntry.
Here is the unit test I have created.
I would expect the generated code to contain SingleValue, which it doesn't. Then, more critically, it generates a dictionary of type <string, Anonymous> and this fails to compile because Anonymous is unknown.
Does my mock API make sense? It replicates the exact problem I get with the fullscale API that I have no control over. Are there any options I have overlooked in the CSharpClientGeneratorSettings?
The text was updated successfully, but these errors were encountered: