Swagger-codegen: [CSharp] Some additional properties not working

Created on 5 Jul 2017  路  8Comments  路  Source: swagger-api/swagger-codegen

Description

Some additional properties like packageTitle and packageDescriptions are not working.
When I create a nuget package, the title is always "Swagger Library".

Swagger-codegen version

2.2.2

Excerpts

Configuration at config.json:

{
  "packageName": "MyTestPackage",
  "packageGuid": "e110209d-3673-4b82-8afc-894796f3c090",
  "packageVersion": "7.8.9",
  "packageTitle": "The title",
  "packageDescriptions": "The description"
}

Generated AssemblyInfo.cs:

using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Swagger Library")]
[assembly: AssemblyDescription("A library generated from a Swagger doc")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Swagger")]
[assembly: AssemblyProduct("SwaggerLibrary")]
[assembly: AssemblyCopyright("No Copyright")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.8.9")]
[assembly: AssemblyFileVersion("7.8.9")]

Command line used for generation
java -jar swagger-codegen-cli.jar generate -l csharp -i http://petstore.swagger.io/v2/swagger.json -o petstore_gen --config config.json
Steps to reproduce

Just run the command line and see for yourself

Related issues

I think no

C-Sharp Question

Most helpful comment

To customize the variables in the mustache template, please use --additional-properties instead.

e.g. --additional-properties packageVersion=7.8.9

All 8 comments

@mniak I don't see those options (e.g. packageTitle) listed in the C# client generator.

CONFIG OPTIONS
    packageName
        C# package name (convention: Title.Case). (Default: IO.Swagger)

    packageVersion
        C# package version. (Default: 1.0.0)

    sourceFolder
        source folder for generated code (Default: src)

    packageGuid
        The GUID that will be associated with the C# project

    interfacePrefix
        Prefix interfaces with a community standard or widely accepted prefix. (Default: I)

    targetFramework
        The target .NET framework version. (Default: v4.5)
            v3.5 - .NET Framework 3.5 compatible
            v4.5 - .NET Framework 4.5+ compatible
            v5.0 - .NET Standard 1.3 compatible
            uwp - Universal Windows Platform (IMPORTANT: this will be decommissioned and replaced by v5.0)

    hideGenerationTimestamp
        Hides the generation timestamp when files are generated. (Default: true)

    sortParamsByRequiredFlag
        Sort method arguments to place required parameters before optional parameters. (Default: true)

    useDateTimeOffset
        Use DateTimeOffset to model date-time properties (Default: false)

    useCollection
        Deserialize array types to Collection<T> instead of List<T>. (Default: false)

    returnICollection
        Return ICollection<T> instead of the concrete type. (Default: false)

    optionalMethodArgument
        C# Optional method argument, e.g. void square(int x=10) (.net 4.0+ only). (Default: true)

    optionalAssemblyInfo
        Generate AssemblyInfo.cs. (Default: true)

    optionalProjectFile
        Generate {PackageName}.csproj. (Default: true)

    optionalEmitDefaultValues
        Set DataMember's EmitDefaultValue. (Default: false)

    generatePropertyChanged
        Specifies a AssemblyDescription for the .NET Framework global assembly attributes stored in the AssemblyInfo file. (Default: false)

    nonPublicApi
        Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers. (Default: false)

    allowUnicodeIdentifiers
        boolean, toggles whether unicode identifiers are allowed in names or not, default is false (Default: false)

    netCoreProjectFile
        Use the new format (.NET Core) for .NET project files (.csproj). (Default: false)

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l csharp

In fact they are not.
I supposed it should work because these variables are present in the nuget mustache file.

Maybe this issue can be considered a feature-request

To customize the variables in the mustache template, please use --additional-properties instead.

e.g. --additional-properties packageVersion=7.8.9

Thank you very much!
This was what I was looking for!

@mniak No problem.

I agree with you that we should add the corresponding CLI option as users may not be aware of --additional-properties for customizing mustache templates.

Let me know if you've cycle to contribute the enhancement.

@wing328 Any update on making this more visible?

This is the only reference to this issue I've found after searching for a few days.

Was having to copy out the csharp template directory and hard-code the values packageTitle and packageDescriptions in nuspec.mustache. :grimacing:

@PaulSearcy thanks for tagging me but I'm no longer involved in this particular project. I hope others will be able to help you. Good luck.

This is what I am doing now:

java -jar scripts\swagger-codegen-cli-2.4.12.jar generate -l csharp -i documentation.yaml -c scripts\generate.json --additional-properties packageTitle="API Client C#",packageDescription="CSharp client library of API",packageAuthors="Team",packageCopyright="Copyright 2020"
MSBuild.exe" /t:Restore;Build /p:Configuration=Release Api.Client.Cs.sln
nuget.exe pack src\Api.Client.Cs\Api.Client.Cs.csproj -Properties Configuration=Release

Other properties are in generate.json

Was this page helpful?
0 / 5 - 0 ratings