Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 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
e16c24e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset 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
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
Move golang changes to a separate branch
  • Loading branch information
sebastien-rosset committed May 7, 2020
commit 90c0c9ed7a47eee28f05bc079c600bcee7e03af5
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public AbstractGoCodegen() {
"complex128",
"rune",
"byte",
"ObjectType",
"AnyType"
"map[string]interface{}",
"interface{}"
)
);

Expand Down Expand Up @@ -128,15 +128,9 @@ public AbstractGoCodegen() {
// map[string]interface{}, whereas an arbitrary type is implemented
// in golang as interface{}.
// See issue #5387 for more details.
typeMapping.put("object", "ObjectType");
// A schema that does not specify the 'type' attribute. The value
// can be anything.
typeMapping.put("AnyType", "AnyType");
// Below is the entry to map the JSON 'null' type to golang.
// Note there is no built-in 'null' type in golang, and it's not possible
// to declare a variable whose only possible value is 'nil'.
// For example `a := nil` is not a valid go statement.
typeMapping.put("null", "NullType");
typeMapping.put("object", "map[string]interface{}");
typeMapping.put("interface{}", "interface{}");
typeMapping.put("AnyType", "interface{}");

numberTypes = new HashSet<String>(
Arrays.asList(
Expand Down Expand Up @@ -397,7 +391,7 @@ public String getSchemaType(Schema p) {
type = openAPIType;
} else if ("object".equals(openAPIType) && ModelUtils.isAnyTypeSchema(p)) {
// Arbitrary type. Note this is not the same thing as free-form object.
type = "AnyType";
type = "interface{}";
} else if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
Expand Down Expand Up @@ -604,58 +598,14 @@ 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 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.
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);
// The 'go-experimental/model.mustache' template conditionally generates accessor methods.
// For primitive types and custom types (e.g. interface{}, map[string]interface{}...),
// the generated code has a wrapper type and a Get() function to access the underlying type.
// For containers (e.g. Array, Map), the generated code returns the type directly.
if (property.isContainer || property.isFreeFormObject || property.isAnyType) {
property.vendorExtensions.put("x-golang-is-container", true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,37 +177,11 @@ 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")) {
if (!param.isNullable || param.isMapContainer || param.isListContainer ||
param.isFreeFormObject || param.isAnyType) {
continue;
}
if (param.isAnyType) {
param.vendorExtensions.put("x-go-base-type", "interface{}");
continue;
} else if (param.isFreeFormObject) {
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;
}
}
/*
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