Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !5680

[C#] Fixed valuetype parameters and discriminator deserialization

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/gbrown-ce/master into master 5 years ago
  • Overview 0
  • Commits 9
  • Pipelines 0
  • Changes 65

Created by: gbrown-ce

  • Made non-required valuetypes nullable, and flagged required valuetypes as "x-csharp-value-type"
  • Made sure to camelCase discriminator property names in Subtype converter
  • Made sure all enum variables are marked as such in the codegen

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@mandrean @jimschubert @frankyjuang @shibayan

This should address these issues: https://github.com/OpenAPITools/openapi-generator/issues/3308 https://github.com/OpenAPITools/openapi-generator/issues/4194

Compare
  • master (base)

and
  • latest version
    635d1768
    9 commits, 2 years ago

65 files
+ 550
- 545

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
AbstractCShar‎pCodegen.java‎ +26 -0
CSharpClient‎Codegen.java‎ +12 -0
resource‎s/csharp‎
modelGener‎ic.mustache‎ +3 -3
samples/cli‎ent/petstore‎
csh‎arp‎
OpenAP‎IClient‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +40 -40
Mo‎del‎
Anim‎al.cs‎ +2 -2
Categ‎ory.cs‎ +1 -1
EnumT‎est.cs‎ +2 -2
Format‎Test.cs‎ +4 -4
Nam‎e.cs‎ +1 -1
Pet‎.cs‎ +2 -2
TypeHolder‎Default.cs‎ +5 -5
TypeHolder‎Example.cs‎ +6 -6
OpenAPICl‎ientNet35‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +20 -20
Cli‎ent‎
ApiCli‎ent.cs‎ +0 -1
Mo‎del‎
Anim‎al.cs‎ +2 -2
Categ‎ory.cs‎ +1 -1
EnumT‎est.cs‎ +2 -2
Format‎Test.cs‎ +4 -4
Nam‎e.cs‎ +1 -1
Pet‎.cs‎ +2 -2
TypeHolder‎Default.cs‎ +5 -5
TypeHolder‎Example.cs‎ +6 -6
OpenAPICl‎ientNet40‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +20 -20
Cli‎ent‎
ApiCli‎ent.cs‎ +0 -1
Mo‎del‎
Anim‎al.cs‎ +2 -2
Categ‎ory.cs‎ +1 -1
EnumT‎est.cs‎ +2 -2
Format‎Test.cs‎ +5 -19
Nam‎e.cs‎ +1 -1
Pet‎.cs‎ +2 -2
TypeHolder‎Default.cs‎ +5 -5
TypeHolder‎Example.cs‎ +6 -6
OpenAPIClient‎NetCoreProject‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +40 -40
Cli‎ent‎
ApiCli‎ent.cs‎ +0 -1
Mo‎del‎
Anim‎al.cs‎ +2 -2
Categ‎ory.cs‎ +1 -1
EnumT‎est.cs‎ +2 -2
Format‎Test.cs‎ +4 -4
Nam‎e.cs‎ +1 -1
Pet‎.cs‎ +2 -2
TypeHolder‎Default.cs‎ +5 -5
TypeHolder‎Example.cs‎ +6 -6
OpenAPIClien‎tNetStandard‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +41 -41
Cli‎ent‎
ApiCli‎ent.cs‎ +0 -1
Mo‎del‎
Anim‎al.cs‎ +2 -2
Categ‎ory.cs‎ +1 -1
EnumT‎est.cs‎ +2 -2
Format‎Test.cs‎ +4 -4
Nam‎e.cs‎ +1 -1
Pet‎.cs‎ +2 -2
TypeHolder‎Default.cs‎ +5 -5
TypeHolder‎Example.cs‎ +6 -6
OpenAPIClientWit‎hPropertyChanged‎
do‎cs‎
FakeA‎pi.md‎ +31 -31
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +41 -41
Cli‎ent‎
ApiCli‎ent.cs‎ +0 -1
Mo‎del‎
Anim‎al.cs‎ +1 -1
EnumT‎est.cs‎ +1 -1
Format‎Test.cs‎ +1 -15
csharp-‎netcore‎
OpenAPIClien‎t/src/…/Model‎
EnumT‎est.cs‎ +1 -1
OpenAPIClientC‎ore/src/…/Model‎
EnumT‎est.cs‎ +1 -1
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
+ 26
- 0
  • View file @ 635d1768

  • Edit in single-file editor

  • Open in Web IDE


@@ -470,6 +470,32 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
var.isPrimitiveType = true;
}
}
for (CodegenProperty var : model.readWriteVars) {
if (enumRefs.containsKey(var.dataType)) {
// Handle any enum properties referred to by $ref.
// This is different in C# than most other generators, because enums in C# are compiled to integral types,
// while enums in many other languages are true objects.
CodegenModel refModel = enumRefs.get(var.dataType);
var.allowableValues = refModel.allowableValues;
var.isEnum = true;
// We do these after updateCodegenPropertyEnum to avoid generalities that don't mesh with C#.
var.isPrimitiveType = true;
}
}
for (CodegenProperty var : model.readOnlyVars) {
if (enumRefs.containsKey(var.dataType)) {
// Handle any enum properties referred to by $ref.
// This is different in C# than most other generators, because enums in C# are compiled to integral types,
// while enums in many other languages are true objects.
CodegenModel refModel = enumRefs.get(var.dataType);
var.allowableValues = refModel.allowableValues;
var.isEnum = true;
// We do these after updateCodegenPropertyEnum to avoid generalities that don't mesh with C#.
var.isPrimitiveType = true;
}
}
// We're looping all models here.
if (model.isEnum) {
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java
+ 12
- 0
  • View file @ 635d1768

  • Edit in single-file editor

  • Open in Web IDE


@@ -661,6 +661,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
postProcessPattern(parameter.pattern, parameter.vendorExtensions);
postProcessEmitDefaultValue(parameter.vendorExtensions);
super.postProcessParameter(parameter);
if (nullableType.contains(parameter.dataType)) {
if (!parameter.required) { //optional
parameter.dataType = parameter.dataType + "?";
} else {
parameter.vendorExtensions.put("x-csharp-value-type", true);
}
}
}
@Override
@@ -668,6 +676,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
postProcessPattern(property.pattern, property.vendorExtensions);
postProcessEmitDefaultValue(property.vendorExtensions);
super.postProcessModelProperty(model, property);
if (!property.isContainer && (nullableType.contains(property.dataType) || property.isEnum)) {
property.vendorExtensions.put("x-csharp-value-type", true);
}
}
/*
modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache
+ 3
- 3
  • View file @ 635d1768

  • Edit in single-file editor

  • Open in Web IDE


@@ -3,7 +3,7 @@
/// </summary>
[DataContract]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]{{#children}}
[JsonConverter(typeof(JsonSubtypes), "{{#lambda.camelcase_param}}{{{discriminatorName}}}{{/lambda.camelcase_param}}")]{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}}
{{/discriminator}}
{{#generatePropertyChanged}}
@@ -31,7 +31,7 @@
{{#description}}
/// <value>{{description}}</value>
{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#required}}true{{/required}}{{^required}}false{{/required}}{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]
public {{#complexType}}{{{complexType}}}{{/complexType}}{{^complexType}}{{{datatypeWithEnum}}}{{/complexType}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}} {{name}} { get; set; }
{{/isEnum}}
{{/vars}}
@@ -108,7 +108,7 @@ this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
/// </summary>{{#description}}
/// <value>{{description}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]{{#isDate}}
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#required}}true{{/required}}{{^required}}false{{/required}}{{/isNullable}}{{/vendorExtensions.x-emit-default-value}})]{{#isDate}}
[JsonConverter(typeof(OpenAPIDateConverter))]{{/isDate}}
public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
{{/isEnum}}
samples/client/petstore/csharp/OpenAPIClient/docs/FakeApi.md
+ 31
- 31
  • View file @ 635d1768

  • Edit in single-file editor

  • Open in Web IDE


@@ -97,7 +97,7 @@ No authorization required
## FakeOuterBooleanSerialize
> bool FakeOuterBooleanSerialize (bool body = null)
> bool FakeOuterBooleanSerialize (bool? body = null)
@@ -120,7 +120,7 @@ namespace Example
{
Configuration.Default.BasePath = "http://petstore.swagger.io:80/v2";
var apiInstance = new FakeApi(Configuration.Default);
var body = true; // bool | Input boolean as post body (optional)
var body = true; // bool? | Input boolean as post body (optional)
try
{
@@ -143,7 +143,7 @@ namespace Example
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | **bool**| Input boolean as post body | [optional]
**body** | **bool?**| Input boolean as post body | [optional]
### Return type
@@ -245,7 +245,7 @@ No authorization required
## FakeOuterNumberSerialize
> decimal FakeOuterNumberSerialize (decimal body = null)
> decimal FakeOuterNumberSerialize (decimal? body = null)
@@ -268,7 +268,7 @@ namespace Example
{
Configuration.Default.BasePath = "http://petstore.swagger.io:80/v2";
var apiInstance = new FakeApi(Configuration.Default);
var body = 8.14; // decimal | Input number as post body (optional)
var body = 8.14; // decimal? | Input number as post body (optional)
try
{
@@ -291,7 +291,7 @@ namespace Example
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | **decimal**| Input number as post body | [optional]
**body** | **decimal?**| Input number as post body | [optional]
### Return type
@@ -614,7 +614,7 @@ No authorization required
## TestEndpointParameters
> void TestEndpointParameters (decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int integer = null, int int32 = null, long int64 = null, float _float = null, string _string = null, System.IO.Stream binary = null, DateTime date = null, DateTime dateTime = null, string password = null, string callback = null)
> void TestEndpointParameters (decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, string _string = null, System.IO.Stream binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null, string callback = null)
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@@ -645,14 +645,14 @@ namespace Example
var _double = 1.2D; // double | None
var patternWithoutDelimiter = patternWithoutDelimiter_example; // string | None
var _byte = BYTE_ARRAY_DATA_HERE; // byte[] | None
var integer = 56; // int | None (optional)
var int32 = 56; // int | None (optional)
var int64 = 789; // long | None (optional)
var _float = 3.4F; // float | None (optional)
var integer = 56; // int? | None (optional)
var int32 = 56; // int? | None (optional)
var int64 = 789; // long? | None (optional)
var _float = 3.4F; // float? | None (optional)
var _string = _string_example; // string | None (optional)
var binary = BINARY_DATA_HERE; // System.IO.Stream | None (optional)
var date = 2013-10-20; // DateTime | None (optional)
var dateTime = 2013-10-20T19:20:30+01:00; // DateTime | None (optional)
var date = 2013-10-20; // DateTime? | None (optional)
var dateTime = 2013-10-20T19:20:30+01:00; // DateTime? | None (optional)
var password = password_example; // string | None (optional)
var callback = callback_example; // string | None (optional)
@@ -681,14 +681,14 @@ Name | Type | Description | Notes
**_double** | **double**| None |
**patternWithoutDelimiter** | **string**| None |
**_byte** | **byte[]**| None |
**integer** | **int**| None | [optional]
**int32** | **int**| None | [optional]
**int64** | **long**| None | [optional]
**_float** | **float**| None | [optional]
**integer** | **int?**| None | [optional]
**int32** | **int?**| None | [optional]
**int64** | **long?**| None | [optional]
**_float** | **float?**| None | [optional]
**_string** | **string**| None | [optional]
**binary** | **System.IO.Stream**| None | [optional]
**date** | **DateTime**| None | [optional]
**dateTime** | **DateTime**| None | [optional]
**date** | **DateTime?**| None | [optional]
**dateTime** | **DateTime?**| None | [optional]
**password** | **string**| None | [optional]
**callback** | **string**| None | [optional]
@@ -719,7 +719,7 @@ void (empty response body)
## TestEnumParameters
> void TestEnumParameters (List<string> enumHeaderStringArray = null, string enumHeaderString = null, List<string> enumQueryStringArray = null, string enumQueryString = null, int enumQueryInteger = null, double enumQueryDouble = null, List<string> enumFormStringArray = null, string enumFormString = null)
> void TestEnumParameters (List<string> enumHeaderStringArray = null, string enumHeaderString = null, List<string> enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null, List<string> enumFormStringArray = null, string enumFormString = null)
To test enum parameters
@@ -746,8 +746,8 @@ namespace Example
var enumHeaderString = enumHeaderString_example; // string | Header parameter enum test (string) (optional) (default to -efg)
var enumQueryStringArray = enumQueryStringArray_example; // List<string> | Query parameter enum test (string array) (optional)
var enumQueryString = enumQueryString_example; // string | Query parameter enum test (string) (optional) (default to -efg)
var enumQueryInteger = 56; // int | Query parameter enum test (double) (optional)
var enumQueryDouble = 1.2D; // double | Query parameter enum test (double) (optional)
var enumQueryInteger = 56; // int? | Query parameter enum test (double) (optional)
var enumQueryDouble = 1.2D; // double? | Query parameter enum test (double) (optional)
var enumFormStringArray = new List<string>(); // List<string> | Form parameter enum test (string array) (optional) (default to $)
var enumFormString = enumFormString_example; // string | Form parameter enum test (string) (optional) (default to -efg)
@@ -776,8 +776,8 @@ Name | Type | Description | Notes
**enumHeaderString** | **string**| Header parameter enum test (string) | [optional] [default to -efg]
**enumQueryStringArray** | **List&lt;string&gt;**| Query parameter enum test (string array) | [optional]
**enumQueryString** | **string**| Query parameter enum test (string) | [optional] [default to -efg]
**enumQueryInteger** | **int**| Query parameter enum test (double) | [optional]
**enumQueryDouble** | **double**| Query parameter enum test (double) | [optional]
**enumQueryInteger** | **int?**| Query parameter enum test (double) | [optional]
**enumQueryDouble** | **double?**| Query parameter enum test (double) | [optional]
**enumFormStringArray** | [**List&lt;string&gt;**](string.md)| Form parameter enum test (string array) | [optional] [default to $]
**enumFormString** | **string**| Form parameter enum test (string) | [optional] [default to -efg]
@@ -808,7 +808,7 @@ No authorization required
## TestGroupParameters
> void TestGroupParameters (int requiredStringGroup, bool requiredBooleanGroup, long requiredInt64Group, int stringGroup = null, bool booleanGroup = null, long int64Group = null)
> void TestGroupParameters (int requiredStringGroup, bool requiredBooleanGroup, long requiredInt64Group, int? stringGroup = null, bool? booleanGroup = null, long? int64Group = null)
Fake endpoint to test group parameters (optional)
@@ -834,9 +834,9 @@ namespace Example
var requiredStringGroup = 56; // int | Required String in group parameters
var requiredBooleanGroup = true; // bool | Required Boolean in group parameters
var requiredInt64Group = 789; // long | Required Integer in group parameters
var stringGroup = 56; // int | String in group parameters (optional)
var booleanGroup = true; // bool | Boolean in group parameters (optional)
var int64Group = 789; // long | Integer in group parameters (optional)
var stringGroup = 56; // int? | String in group parameters (optional)
var booleanGroup = true; // bool? | Boolean in group parameters (optional)
var int64Group = 789; // long? | Integer in group parameters (optional)
try
{
@@ -862,9 +862,9 @@ Name | Type | Description | Notes
**requiredStringGroup** | **int**| Required String in group parameters |
**requiredBooleanGroup** | **bool**| Required Boolean in group parameters |
**requiredInt64Group** | **long**| Required Integer in group parameters |
**stringGroup** | **int**| String in group parameters | [optional]
**booleanGroup** | **bool**| Boolean in group parameters | [optional]
**int64Group** | **long**| Integer in group parameters | [optional]
**stringGroup** | **int?**| String in group parameters | [optional]
**booleanGroup** | **bool?**| Boolean in group parameters | [optional]
**int64Group** | **long?**| Integer in group parameters | [optional]
### Return type
samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Api/FakeApi.cs
+ 40
- 40
  • View file @ 635d1768

  • Edit in single-file editor

  • Open in Web IDE

Files with large changes are collapsed by default.

0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
.NET dependencies
2
.NET dependencies
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!14216
Source branch: github/fork/gbrown-ce/master

Menu

Explore Projects Groups Snippets