Make nullable fix on all vars in Go (#8820)

* Make nullable fix on all vars in Go

This applies the Nullable change to all variables on the model, instead
of just the ones in vars.

* Add sample showing the issue
This commit is contained in:
Thomas Hervé
2021-02-27 11:12:51 +01:00
committed by GitHub
parent ebac91aa32
commit 3cf93226fa
5 changed files with 9 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
package org.openapitools.codegen.languages;
import com.google.common.collect.Iterables;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.commons.lang3.StringUtils;
@@ -387,7 +388,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
continue;
}
for (CodegenProperty param : model.vars) {
for (CodegenProperty param : Iterables.concat(model.vars, model.allVars, model.requiredVars, model.optionalVars)) {
param.vendorExtensions.put("x-go-base-type", param.dataType);
if (!param.isNullable || param.isMap || param.isArray ||
param.isFreeFormObject || param.isAnyType) {

View File

@@ -1752,6 +1752,7 @@ components:
boolean_prop:
type: boolean
nullable: true
default: false
string_prop:
type: string
nullable: true

View File

@@ -1868,6 +1868,7 @@ components:
nullable: true
type: number
boolean_prop:
default: false
nullable: true
type: boolean
string_prop:

View File

@@ -6,7 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**IntegerProp** | Pointer to **NullableInt32** | | [optional]
**NumberProp** | Pointer to **NullableFloat32** | | [optional]
**BooleanProp** | Pointer to **NullableBool** | | [optional]
**BooleanProp** | Pointer to **NullableBool** | | [optional] [default to false]
**StringProp** | Pointer to **NullableString** | | [optional]
**DateProp** | Pointer to **NullableString** | | [optional]
**DatetimeProp** | Pointer to **NullableTime** | | [optional]

View File

@@ -37,6 +37,8 @@ type NullableClass struct {
// will change when the set of required properties is changed
func NewNullableClass() *NullableClass {
this := NullableClass{}
var booleanProp bool = false
this.BooleanProp = *NewNullableBool(&booleanProp)
return &this
}
@@ -45,6 +47,8 @@ func NewNullableClass() *NullableClass {
// but it doesn't guarantee that properties required by API are set
func NewNullableClassWithDefaults() *NullableClass {
this := NullableClass{}
var booleanProp bool = false
this.BooleanProp = *NewNullableBool(&booleanProp)
return &this
}