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

GenerateTypes() not working without calling GenerateFile() first #681

Closed
basilfx opened this issue Apr 23, 2018 · 2 comments
Closed

GenerateTypes() not working without calling GenerateFile() first #681

basilfx opened this issue Apr 23, 2018 · 2 comments
Milestone

Comments

@basilfx
Copy link

basilfx commented Apr 23, 2018

According to #514, I should be able to use GenerateTypes() instead of GenerateFile(). I have noticed, using version 9.10.42 9.10.45, that the first doesn't work without calling the latter. In that case, the list of artifacts is empty.

This is the piece of code I am using. It works whenever I uncomment generator.GenerateFile().

// Generate class from schema file.
var schema = await JsonSchema4.FromFileAsync(options.Schema);

var settings = new CSharpGeneratorSettings
{
    ArrayType = "System.Collections.Generic.IEnumerable",
    ClassStyle = CSharpClassStyle.Poco,
    Namespace = options.Namespace,
    TypeNameGenerator = new TypeNameGenerator(),
    GenerateJsonMethods = !options.Cleanup
};

var generator = new CSharpGenerator(schema, settings);

// generator.GenerateFile();
var types = generator.GenerateTypes();

// Generate code for each artifact. However, types.Artifacts is empty if GenerateFile isn't invoked first.
foreach (var artifact in types.Artifacts)
{
    // Something with artifact.Code.
}
@basilfx basilfx changed the title GenerateTypes() not working without GenerateFile() first GenerateTypes() not working without calling GenerateFile() first Apr 23, 2018
@RicoSuter
Copy link
Owner

It should be possible... maybe we need to improve the design or document it better.

@RicoSuter RicoSuter added this to the vNext milestone May 14, 2018
@rrmayer
Copy link

rrmayer commented Nov 7, 2018

So, I discovered this issue while looking into another issue I'm having. It turns out if you write the code using JsonSchema4, then you have this issue. If, instead, you use a SwaggerDocument, the code generation works properly for GenerateTypes(), while GenerateFile() fails with a cast exception. There is an issue with the signature of the constructor for CSharpGenerator in that it accepts an object type rather than something a little more specific.

@basilfx basilfx closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants