Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'NSwag.OpenApiDocument' to type 'NJsonSchema.JsonSchema' #1663

Open
brendonparker opened this issue Jan 11, 2024 · 1 comment

Comments

@brendonparker
Copy link

I'm sure this is a dumb question. I have an openapi spec provided to me. I want to generate the CSharp objects. Trying this:

using NJsonSchema.CodeGeneration.CSharp;

var openapi = await NSwag.OpenApiDocument.FromFileAsync("spec.json");
var generator = new CSharpGenerator(openapi);
var file = generator.GenerateFile();

Console.WriteLine(file);

But getting:

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'NSwag.OpenApiDocument' to type 'NJsonSchema.JsonSchema'.
   at NJsonSchema.CodeGeneration.GeneratorBase.GenerateFile()

The Readme seems to indicate that this is supported (openapi), but what is the recipe to make this happen?

net8.0 with the following packages:

<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.0.0" />
<PackageReference Include="NSwag.Core" Version="14.0.0" />
@Purgator
Copy link

Purgator commented Feb 9, 2024

I would read it as a JsonSchema:

 var schema = await JsonSchema.FromFileAsync( "spec.json" );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants