Open mwijns opened 3 years ago
Any update to this?
I stuck to the 13.6.x version and haven't tried it with a more recent version lately.
I have the feeling this might have been fixed with this PR: https://github.com/RicoSuter/NJsonSchema/pull/1317
Please try again with v13.10.4+
I get the exact same issue when trying to generate a C# client based on a public Swagger 2.0 yaml specification. This is the spec: https://dev.float.com/swagger-api-v3.yaml
I'm using version 13.11.3 of the Nuget packages NSwag.CodeGeneration.CSharp and NSwag.Core.Yaml
static async Task Main(string[] args)
{
const string endpoint = "https://dev.float.com/swagger-api-v3.yaml";
var document = await OpenApiYamlDocument.FromUrlAsync(endpoint);
var settings = new CSharpClientGeneratorSettings
{
ClassName = "MyClass",
CSharpGeneratorSettings =
{
Namespace = "MyNamespace",
}
};
var generator = new CSharpClientGenerator(document, settings);
var code = generator.GenerateFile();
}
Exception has occurred: CLR/System.InvalidOperationException
An exception of type 'System.InvalidOperationException' occurred in NJsonSchema.dll but was not handled in user code: 'The schema reference path '#/definitions/ReportsPeople' has not been resolved.'
at NJsonSchema.JsonSchema.GetActualSchema(IList1 checkedSchemas) at NJsonSchema.JsonSchema.get_ActualSchema() at NSwag.OpenApiDocument.<>c.<GenerateOperationIds>b__63_3(KeyValuePair
2 r)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func
2 predicate)
at NSwag.OpenApiDocument.<>c.1 source, Func
2 predicate, Boolean& found)
at NSwag.OpenApiDocument.GenerateOperationIds()
at NSwag.CodeGeneration.ClientGeneratorBase3.GetOperations(OpenApiDocument document) at NSwag.CodeGeneration.ClientGeneratorBase
3.GenerateAllClientTypes()
at NSwag.CodeGeneration.ClientGeneratorBase3.GenerateFile(ClientGeneratorOutputType outputType) at NSwag.CodeGeneration.ClientGeneratorBase
3.GenerateFile()
at NSwagClientGenerator.Program.
Any help would be appreciated
Same issue with 13.20.0. Generate client/controller from someapi.yaml, which $ref schema from ./includes/common.yaml, which $ref schema from itself.
System.InvalidOperationException: The schema reference path './common.yaml#/components/schemas/NanoId' has not been resolved.
I`ve found that external references works only for section #/definitions If you have document A.yaml referencing document B.yaml it loads B as JsonSchema document (not OpenAPI document). Then JsonSchema search references in /definitions section.
First reference from A to B works well, but all other references in B must point to #/definitions section (https://json-schema.org/draft-07/schema#)
When generating C# client code with the NSwag command line toolchain 13.9.2 Netcore31 from
root.yaml:
path.yaml:
object.yaml
I get the following error:
I saw that path reference support was added recently (#1953). When recreating the same case in ExternalReferenceTests.cs / path-reference.json no error is given. When generating from the same files with the 13.6.0 toolchain no error is given and the code is correctly generated.