Skip to content

[csharp-netcore] Fixed handling of nullable enum values#6112

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
shibayan:enum-nullable
May 2, 2020
Merged

[csharp-netcore] Fixed handling of nullable enum values#6112
wing328 merged 3 commits intoOpenAPITools:masterfrom
shibayan:enum-nullable

Conversation

@shibayan
Copy link
Contributor

@shibayan shibayan commented Apr 29, 2020

Fixes an issue where the enum type is not properly treated as nullable.

Fixed #5442

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.

if (model != null) {
for (CodegenProperty var : model.vars) {
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
var.vendorExtensions.put("x-csharp-value-type", true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only at this timing isEnum is set to the correct value

parameter.isEnum = true;
parameter.allowableValues = model.allowableValues;
parameter.isPrimitiveType = true;
parameter.vendorExtensions.put("x-csharp-value-type", true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only an enum with type generation can be determined here.

super.postProcessModelProperty(model, property);

if (!property.isContainer && (nullableType.contains(property.dataType) || property.isEnum)) {
property.vendorExtensions.put("x-csharp-value-type", true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEnum is always false at this timing

{{^vendorExtensions.x-csharp-value-type}}
{{#required}}
localVarRequestOptions.PathParameters.Add("{{baseName}}", {{packageName}}.Client.ClientUtils.ParameterToString({{paramName}})); // path parameter
{{/required}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been confirmed that required parameters have values at the beginning of the method regardless of whether they are nullable.

@shibayan
Copy link
Contributor Author

@mandrean (2017/08), @jimschubert (2017/09) ❤️ @frankyjuang (2019/09) @shibayan (2020/02)

@wing328
Copy link
Member

wing328 commented May 2, 2020

@shibayan thanks for fix. Let's go with what you've filed.

@wing328 wing328 merged commit 9732589 into OpenAPITools:master May 2, 2020
@shibayan shibayan deleted the enum-nullable branch May 2, 2020 13:43
@wing328
Copy link
Member

wing328 commented May 7, 2020

@shibayan thanks for the PR, which has been included in the v4.3.1 release: https://twitter.com/oas_generator/status/1258057660974329861

michaelpro1 pushed a commit to michaelpro1/openapi-generator that referenced this pull request May 7, 2020
…#6112)

* [csharp-netcore] Fixed handling of nullable enum values

* Update sample code

* Remove unnecessary method calls
MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request May 31, 2020
…#6112)

* [csharp-netcore] Fixed handling of nullable enum values

* Update sample code

* Remove unnecessary method calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [csharp-netcore] Invalid expressions are generated using ??

2 participants