0

I am planning on using NSwag CSharpClientGenerator to generate POCO classes for a project. I am having following two issues.

  1. In my sample console project, I am using a valid OpenApi3 spec document and it produces an empty partial class with no properties but for the same file if I use it on online apimundo tool here, it does produce a partial class with properties. I am using same C# generator settings that are same as on that site.
  2. Is there a way to generate just POCO classes and not have partial POCO classes by having some sort of C# Generator Settings value?

I am using VS 2019 with .NET 5.0

Settings:

private static CSharpGeneratorSettings GetSettings()
    {
        return new CSharpGeneratorSettings
        {
            Namespace = "CodeGen",
            RequiredPropertiesMustBeDefined = true,
            GenerateDataAnnotations = false,
            AnyType = "object",
            DateType = "System.DateTimeOffset",
            DateTimeType = "System.DateTimeOffset",
            TimeType = "System.TimeSpan",
            TimeSpanType = "System.TimeSpan",
            ArrayType = "System.Collections.Generic.ICollection",
            DictionaryType = "System.Collections.Generic.IDictionary",
            ArrayInstanceType = "System.Collections.ObjectModel.Collection",
            DictionaryInstanceType = "System.Collections.Generic.Dictionary",
            ArrayBaseType = "System.Collections.ObjectModel.Collection",
            DictionaryBaseType = "System.Collections.Generic.Dictionary",
            JsonLibrary = CSharpJsonLibrary.NewtonsoftJson,
            TypeAccessModifier = "public",
            PropertySetterAccessModifier = "",
            JsonConverters = null,
            GenerateImmutableArrayProperties = false,
            GenerateImmutableDictionaryProperties = false,
            HandleReferences = false,
            JsonSerializerSettingsTransformationMethod = null,
            GenerateJsonMethods = false,
            EnforceFlagEnums = false,
            InlineNamedDictionaries = false,
            InlineNamedTuples = false,
            InlineNamedArrays = false,
            GenerateOptionalPropertiesAsNullable = false,
            GenerateNullableReferenceTypes = true,
            SchemaType = SchemaType.OpenApi3,
            GenerateDefaultValues = true,
            ExcludedTypeNames = Array.Empty<string>(),
            TemplateDirectory = null,
            InlineNamedAny = false,
            ClassStyle = CSharpClassStyle.Poco

        };
    }

I am using pet-store file found here.

Thanks, Salil

Maharaj
  • 313
  • 2
  • 3
  • 14
  • Sounds like it should be possible. Take a look at these sources: https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild and https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document. I also recommend installing NSwagStudio to quickly play around with all the settings! – S. ten Brinke Jan 26 '22 at 19:49
  • Thanks @STenBrinke. I was able to produce the cs file using JsonSchema.FromSampleJson method. Now I need to see how I can translate so many anonymous classed to actual names. – Maharaj Jan 27 '22 at 15:24

0 Answers0