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
  • !6110
An error occurred while fetching the assigned milestone of the selected merge_request.

[csharp-netcore] Fix for issue 5442. Use if/else instead of ??

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/donatwork/fix_issue5442 into master 5 years ago
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 7

Created by: donatwork

Fix invalid C# code being generated on required parameters. Use if/else instead of ?? operator.

PR checklist

  • [X ] Read the contribution guidelines.
  • [X ] If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • [X ] 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).
  • [X ] File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • [ X] Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@mandrean @jimschubert @frankyjuang @shibayan

Compare
  • master (base)

and
  • latest version
    85e62a63
    2 commits, 2 years ago

7 files
+ 88
- 11

    Preferences

    File browser
    Compare changes
modules/…/…/…/…‎/csharp-netcore‎
modelGener‎ic.mustache‎ +8 -1
samples/client/‎…/…/…/…/…/Model‎
Anim‎al.cs‎ +8 -1
Categ‎ory.cs‎ +8 -1
Format‎Test.cs‎ +16 -2
Pet‎.cs‎ +16 -2
TypeHolder‎Default.cs‎ +16 -2
TypeHolder‎Example.cs‎ +16 -2
modules/openapi-generator/src/main/resources/csharp-netcore/modelGeneric.mustache
+ 8
- 1
  • View file @ 85e62a63


@@ -63,7 +63,14 @@
{{#required}}
{{^vendorExtensions.x-csharp-value-type}}
// to ensure "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" is required (not null)
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? throw new ArgumentNullException("{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} is a required property for {{classname}} and cannot be null");
if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} == null)
{
throw new ArgumentNullException("{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} is a required property for {{classname}} and cannot be null");
}
else
{
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
}
{{/vendorExtensions.x-csharp-value-type}}
{{#vendorExtensions.x-csharp-value-type}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Animal.cs
+ 8
- 1
  • View file @ 85e62a63


@@ -53,7 +53,14 @@ namespace Org.OpenAPITools.Model
public Animal(string className = default(string), string color = "red")
{
// to ensure "className" is required (not null)
this.ClassName = className ?? throw new ArgumentNullException("className is a required property for Animal and cannot be null");
if (className == null)
{
throw new ArgumentNullException("className is a required property for Animal and cannot be null");
}
else
{
this.ClassName = className;
}
// use default value if no "color" provided
this.Color = color ?? "red";
}
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Category.cs
+ 8
- 1
  • View file @ 85e62a63


@@ -45,7 +45,14 @@ namespace Org.OpenAPITools.Model
public Category(long id = default(long), string name = "default-name")
{
// to ensure "name" is required (not null)
this.Name = name ?? throw new ArgumentNullException("name is a required property for Category and cannot be null");
if (name == null)
{
throw new ArgumentNullException("name is a required property for Category and cannot be null");
}
else
{
this.Name = name;
}
this.Id = id;
}
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/FormatTest.cs
+ 16
- 2
  • View file @ 85e62a63


@@ -58,10 +58,24 @@ namespace Org.OpenAPITools.Model
{
this.Number = number;
// to ensure "_byte" is required (not null)
this.Byte = _byte ?? throw new ArgumentNullException("_byte is a required property for FormatTest and cannot be null");
if (_byte == null)
{
throw new ArgumentNullException("_byte is a required property for FormatTest and cannot be null");
}
else
{
this.Byte = _byte;
}
this.Date = date;
// to ensure "password" is required (not null)
this.Password = password ?? throw new ArgumentNullException("password is a required property for FormatTest and cannot be null");
if (password == null)
{
throw new ArgumentNullException("password is a required property for FormatTest and cannot be null");
}
else
{
this.Password = password;
}
this.Integer = integer;
this.Int32 = int32;
this.Int64 = int64;
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Pet.cs
+ 16
- 2
  • View file @ 85e62a63


@@ -82,9 +82,23 @@ namespace Org.OpenAPITools.Model
public Pet(long id = default(long), Category category = default(Category), string name = default(string), List<string> photoUrls = default(List<string>), List<Tag> tags = default(List<Tag>), StatusEnum? status = default(StatusEnum?))
{
// to ensure "name" is required (not null)
this.Name = name ?? throw new ArgumentNullException("name is a required property for Pet and cannot be null");
if (name == null)
{
throw new ArgumentNullException("name is a required property for Pet and cannot be null");
}
else
{
this.Name = name;
}
// to ensure "photoUrls" is required (not null)
this.PhotoUrls = photoUrls ?? throw new ArgumentNullException("photoUrls is a required property for Pet and cannot be null");
if (photoUrls == null)
{
throw new ArgumentNullException("photoUrls is a required property for Pet and cannot be null");
}
else
{
this.PhotoUrls = photoUrls;
}
this.Id = id;
this.Category = category;
this.Tags = tags;
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    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:
Source branch: github/fork/donatwork/fix_issue5442

Menu

Explore Projects Groups Snippets