I have a series of JSON schema files that I'm trying to output to POCOs, and have the NJsonSchema.CodeGeneration.CSharp
library loaded for this purpose. In specifying a namespace for the models, it does not appear that the namespace is actually being output into the generated code files. The POCOs are being written, but no namespace declaration surrounds the objects. I am expecting a namespace MyApp.DataModels
to be in each file. What am I doing wrong?
Here are the relevant pieces of code:
CSharpGeneratorSettings csGenSettings = new CSharpGeneratorSettings() {
ClassStyle = CSharpClassStyle.Poco,
HandleReferences = true,
Namespace = "MyApp.DataModels"
};
var _resolver = new CSharpTypeResolver(csGenSettings);
_resolver.RegisterSchemaDefinitions(swaggerDoc.Definitions);
var generator = new CSharpGenerator(swaggerDoc, csGenSettings, _resolver);
var typeDef = generator.GenerateTypes();
foreach (CodeArtifact codeArtifact in typeDef.Artifacts)
{
File.WriteAllText(Path.Combine(dirDestination, codeArtifact.TypeName + ".cs"), codeArtifact.Code);
}