Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
489985d
Handle null type
sebastien-rosset Apr 30, 2020
c16089e
Handle null type
sebastien-rosset Apr 30, 2020
26865b3
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
48c310e
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
fddb63b
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
cf4e9f8
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
3b59b47
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset May 1, 2020
b362f92
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset May 1, 2020
ae93643
improve documentation
sebastien-rosset May 1, 2020
f5acfba
Handle 'null' type
sebastien-rosset May 1, 2020
6ba1523
Handle 'null' type. Add unit tests
sebastien-rosset May 1, 2020
de13169
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 1, 2020
2a6a87a
Add NullType for go
sebastien-rosset May 2, 2020
86bc4c0
Add NullType for go
sebastien-rosset May 2, 2020
6b9c0ce
fix modeling of AnyType for go-experimental
sebastien-rosset May 2, 2020
b0d221e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 2, 2020
a302894
execute scripts in bin directory
sebastien-rosset May 3, 2020
e449c82
resolve merge conflicts
sebastien-rosset May 3, 2020
043f247
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 4, 2020
1e14c94
Add review comments
sebastien-rosset May 4, 2020
747803e
Add 'null' type in oneOf
sebastien-rosset May 4, 2020
aa06a89
Improve OAS YAML file for golang openapi3 samples
sebastien-rosset May 4, 2020
543d406
'Any type' includes the null value, so 'isNullable' should be set to …
sebastien-rosset May 4, 2020
81093c7
'Any type' includes the null value, so 'isNullable' should be set to …
sebastien-rosset May 4, 2020
9a54ea1
Handle AnyType and NullType
sebastien-rosset May 5, 2020
dc7a7e0
handle anytype for go-experimental
sebastien-rosset May 5, 2020
ddc810c
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 5, 2020
03ec914
Log warning instead of error
sebastien-rosset May 5, 2020
bdf3653
anyOf/oneOf
sebastien-rosset May 5, 2020
9dbae45
Change x-golang-is-container extension to x-golang-has-wrapper
sebastien-rosset May 5, 2020
e1417ec
Add code comments
sebastien-rosset May 5, 2020
480ecbe
Handle Object and any type
sebastien-rosset May 5, 2020
a58f121
Handle Object and any type
sebastien-rosset May 5, 2020
01ff36e
Handle object and any type
sebastien-rosset May 5, 2020
ec97db3
add code comments
sebastien-rosset May 6, 2020
431356c
handle additional properties
sebastien-rosset May 6, 2020
93752ff
handle additional properties
sebastien-rosset May 6, 2020
261dbcd
handle additional properties
sebastien-rosset May 6, 2020
aa6b6df
handle anytype and objecttype for go-exerimental
sebastien-rosset May 6, 2020
90c0c9e
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
f56c812
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
b159356
Better names for the OAS document test properties
sebastien-rosset May 7, 2020
ef5149e
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
84162be
Run samples scripts
sebastien-rosset May 7, 2020
ee786cb
Run samples scripts
sebastien-rosset May 7, 2020
058694b
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 7, 2020
82cb0e9
fix unit test issues
sebastien-rosset May 8, 2020
2c5c1cf
Handle none type
sebastien-rosset May 8, 2020
0694f83
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 8, 2020
b6afbc6
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 8, 2020
f275dc9
Fix index out of range exception
sebastien-rosset May 8, 2020
93cc8c8
fix formatting issues
sebastien-rosset May 8, 2020
6939648
fix formatting issues
sebastien-rosset May 8, 2020
8bdca05
fix formatting issues. Finally figured out how to check formatting in…
sebastien-rosset May 8, 2020
4c01344
fix formatting issues
sebastien-rosset May 8, 2020
537c28b
resolve merge conflicts
sebastien-rosset May 11, 2020
71d550c
resolve merge conflicts
sebastien-rosset May 11, 2020
11c52e4
resolve merge conflicts
sebastien-rosset May 12, 2020
eadca7a
Add reference to oneOf schema
sebastien-rosset May 12, 2020
603b6fb
Add model showing unit test failure with ref to oneOf schema
sebastien-rosset May 12, 2020
e16c24e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
7b2ed9e
Updates get_discriminator_class to return visited_composed_classes
spacether May 12, 2020
9811b8c
Fixes broken test, adds is_valid_type
spacether May 12, 2020
8f1c202
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
5e48c72
run samples scripts
sebastien-rosset May 12, 2020
245c850
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
942edf0
move unit test to test_drawing.py file
sebastien-rosset May 12, 2020
f5050b0
Add more unit tests
sebastien-rosset May 12, 2020
251086b
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
2feed29
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
3a05ff6
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
40ecbfb
Improve unit tests
sebastien-rosset May 12, 2020
d5bd3d3
Merge branch 'python-null-type' of github.com:CiscoM31/openapi-genera…
sebastien-rosset May 13, 2020
42f6781
Add is_nullable_type util function
sebastien-rosset May 13, 2020
c4bc09d
Add unit test for null value
sebastien-rosset May 13, 2020
094e00d
Add 'ShapeOrNull' type to handle the oneOf/anyOf scenario when the ch…
sebastien-rosset May 13, 2020
a0aa380
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
7274ed5
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
bb44600
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
41e97e6
Mustache template should use invokerPackage tag to generate import
sebastien-rosset May 13, 2020
1760f6a
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
b26548e
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
87ed97e
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
7c4cd94
Add more unit test for nullable shape
sebastien-rosset May 13, 2020
3ae466e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
6cfe426
resolve merge conflicts
sebastien-rosset May 13, 2020
274ab6c
resolve merge conflicts
sebastien-rosset May 13, 2020
6c55fd9
resolve merge conflicts
sebastien-rosset May 13, 2020
b628667
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
fddadc3
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 13, 2020
8ec12af
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle anytype and objecttype for go-exerimental
  • Loading branch information
sebastien-rosset committed May 6, 2020
commit aa6b6dfcec737e2c03fe2a0c3cc17db894b50c4d
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public boolean isDiscriminator;
public List<String> _enum;
public Map<String, Object> allowableValues;
// If 'additionalProperties' is not set, items is null.
// If 'additionalProperties' is set to a type or refers to a type, 'items' provides the type information for
// the undeclared properties.
public CodegenProperty items;
public CodegenProperty mostInnerItems;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,57 @@ private void setExportParameterName(List<CodegenParameter> codegenParameters) {
}
}

/**
* OAS type mapping to golang implementation:
*
* AnyType interface{} Any type, e.g. null, string, integer, number, boolean, map, array.
* ObjectType map[string]interface{} Free-form object with no constraint on additional properties.
* map[string]Animal map[string]Animal Free-form object. The value of undeclared properties must be 'Animal'.
* map[string]ObjectType map[string]map[string]interface{} Free-form object. The value of undeclared properties must be an object (map).
* map[string][]interface{} Free-form object. The value of undeclared properties must be an array.
*
*/
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
// The 'go-experimental/model.mustache' template conditionally generates accessor methods.
// For containers (e.g. Array, Map) and non-nullable primitive types, the generated code
// returns the type directly.
// The 'go-experimental/model.mustache' template generates accessor methods.
// For containers (e.g. Array, Map) and non-nullable primitive types, the go struct field
// is the underlying type, e.g. *int32, *string, *bool...
// In other cases (nullable primitive types, free-form objects...), the generated code has
// a wrapper type and a Get() function to access the underlying type.
if ((property.isNullable && !property.isContainer) || property.isFreeFormObject) {
boolean hasWrapper = false;
if (property.isAnyType) {
// The wrapper type is the 'AnyType' struct and the wrapped type is 'interface{}'.
hasWrapper = true;
} else if (property.isFreeFormObject && !property.isNullable) { // &&
// Undeclared properties use case.
// The undeclared properties are implemented using a go map.
// The map key is always a string.
// The map value is interface{} when there are no constraints, but the
// 'additionalProperties' attribute may require a specific type.
if (property.items == null) {
// The 'additionalProperties' attribute is not set, so it is a free-form object
// with no constraint on the type of undeclared properties.
// The wrapper type is 'ObjectType'.
// The wrapped type is 'map[string]interface{}'.
hasWrapper = true;
} else if (property.items.isFreeFormObject && !property.items.isNullable) {
// The 'additionalProperties' attribute is set, and the value of the undeclared
// properties must be a free-form object. Hence it's a map of map.
// The wrapper type is map[string]ObjectType.
// The wrapped type is 'map[string]map[string]interface{}'.
hasWrapper = true;
} else {
// The 'additionalProperties' attribute is set, and the value of the undeclared
// properties is not free-form. For example, if the undeclared properties must
// be of type 'Animal', then:
// The wrapper type is map[string]Animal.
// The wrapped type is 'map[string]Animal'.
}
} else if (property.isNullable && !property.isContainer) {
// Primitive types.
hasWrapper = true;
}
if (hasWrapper) {
property.vendorExtensions.put("x-golang-has-wrapper", true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,37 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
}

for (CodegenProperty param : model.vars) {
// Two golang types are used in the generated code: the type of the
// struct fields and the types of the getter and setter methods.
// The struct fields may use a wrapper type (such as 'NullableBool'),
// whereas the getter method returns the unwrapped type (e.g. 'bool').
// param.dataType is the golang type of the generated struct field.
// "x-go-base-type" is the type in the setter and getter functions.
param.vendorExtensions.put("x-go-base-type", param.dataType);
if (!param.vendorExtensions.containsKey("x-golang-has-wrapper")) {
continue;
}
if (param.isAnyType) {
param.vendorExtensions.put("x-go-base-type", "interface{}");
continue;
} else if (param.isFreeFormObject) {
param.vendorExtensions.put("x-go-base-type", "map[string]interface{}");
continue;
switch (param.dataType) {
case "ObjectType":
param.vendorExtensions.put("x-go-base-type", "map[string]interface{}");
continue;
case "[]ObjectType":
param.vendorExtensions.put("x-go-base-type", "map[string][]interface{}");
continue;
case "map[string]ObjectType":
param.vendorExtensions.put("x-go-base-type", "map[string]map[string]interface{}");
continue;
}
}
param.vendorExtensions.put("x-go-base-type", param.dataType);
/*
if (!param.isNullable || param.isMapContainer || param.isListContainer) {
continue;
}
*/
if (param.isDateTime) {
// Note this could have been done by adding the following line in processOpts(),
// however, we only want to represent the DateTime object as NullableTime if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,20 @@ HasArrayItemsNullable returns a boolean if a field has been set.

### GetObjectNullableProp

`func (o *NullableClass) GetObjectNullableProp() map[string]interface{}`
`func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType`

GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise.

### GetObjectNullablePropOk

`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool)`
`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool)`

GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetObjectNullableProp

`func (o *NullableClass) SetObjectNullableProp(v map[string]interface{})`
`func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType)`

SetObjectNullableProp sets ObjectNullableProp field to given value.

Expand All @@ -378,20 +378,20 @@ HasObjectNullableProp returns a boolean if a field has been set.
UnsetObjectNullableProp ensures that no value is present for ObjectNullableProp, not even an explicit nil
### GetObjectAndItemsNullableProp

`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{}`
`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType`

GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise.

### GetObjectAndItemsNullablePropOk

`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool)`
`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool)`

GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetObjectAndItemsNullableProp

`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{})`
`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType)`

SetObjectAndItemsNullableProp sets ObjectAndItemsNullableProp field to given value.

Expand All @@ -413,20 +413,20 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set.
UnsetObjectAndItemsNullableProp ensures that no value is present for ObjectAndItemsNullableProp, not even an explicit nil
### GetObjectItemsNullable

`func (o *NullableClass) GetObjectItemsNullable() map[string]interface{}`
`func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType`

GetObjectItemsNullable returns the ObjectItemsNullable field if non-nil, zero value otherwise.

### GetObjectItemsNullableOk

`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool)`
`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool)`

GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetObjectItemsNullable

`func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{})`
`func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType)`

SetObjectItemsNullable sets ObjectItemsNullable field to given value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ module github.com/GIT_USER_ID/GIT_REPO_ID

go 1.13

require (
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
)
require golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ func (o *NullableClass) SetArrayItemsNullable(v []ObjectType) {
}

// GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *NullableClass) GetObjectNullableProp() map[string]interface{} {
func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType {
if o == nil {
var ret map[string]interface{}
var ret map[string]ObjectType
return ret
}
return o.ObjectNullableProp
Expand All @@ -409,7 +409,7 @@ func (o *NullableClass) GetObjectNullableProp() map[string]interface{} {
// GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool) {
func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool) {
if o == nil || o.ObjectNullableProp == nil {
return nil, false
}
Expand All @@ -426,14 +426,14 @@ func (o *NullableClass) HasObjectNullableProp() bool {
}

// SetObjectNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectNullableProp field.
func (o *NullableClass) SetObjectNullableProp(v map[string]interface{}) {
func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType) {
o.ObjectNullableProp = v
}

// GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{} {
func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType {
if o == nil {
var ret map[string]interface{}
var ret map[string]ObjectType
return ret
}
return o.ObjectAndItemsNullableProp
Expand All @@ -442,7 +442,7 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{} {
// GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool) {
func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool) {
if o == nil || o.ObjectAndItemsNullableProp == nil {
return nil, false
}
Expand All @@ -459,26 +459,26 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool {
}

// SetObjectAndItemsNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectAndItemsNullableProp field.
func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{}) {
func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType) {
o.ObjectAndItemsNullableProp = v
}

// GetObjectItemsNullable returns the ObjectItemsNullable field value if set, zero value otherwise.
func (o *NullableClass) GetObjectItemsNullable() map[string]interface{} {
func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType {
if o == nil || o.ObjectItemsNullable == nil {
var ret map[string]interface{}
var ret map[string]ObjectType
return ret
}
return *o.ObjectItemsNullable.Get()
return *o.ObjectItemsNullable
}

// GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool) {
func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool) {
if o == nil || o.ObjectItemsNullable == nil {
return nil, false
}
return o.ObjectItemsNullable.Get(), true
return o.ObjectItemsNullable, true
}

// HasObjectItemsNullable returns a boolean if a field has been set.
Expand All @@ -491,8 +491,8 @@ func (o *NullableClass) HasObjectItemsNullable() bool {
}

// SetObjectItemsNullable gets a reference to the given map[string]ObjectType and assigns it to the ObjectItemsNullable field.
func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{}) {
o.ObjectItemsNullable.Set(&v)
func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType) {
o.ObjectItemsNullable = &v
}

func (o NullableClass) MarshalJSON() ([]byte, error) {
Expand Down