Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,14 @@ public CodegenModel fromModel(String name, Schema schema) {
m.xmlNamespace = schema.getXml().getNamespace();
m.xmlName = schema.getXml().getName();
}

if (ModelUtils.isAnyTypeSchema(schema)) {
// The 'null' value is allowed when the OAS schema is 'any type'.
// See https://github.com/OAI/OpenAPI-Specification/issues/1389
if (Boolean.FALSE.equals(schema.getNullable())) {
LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", name);
}
m.isNullable = true;
}
if (ModelUtils.isArraySchema(schema)) {
m.isArrayModel = true;
m.arrayModelType = fromProperty(name, schema).complexType;
Expand Down Expand Up @@ -2986,6 +2993,12 @@ public CodegenProperty fromProperty(String name, Schema p) {
} else if (ModelUtils.isFreeFormObject(p)) {
property.isFreeFormObject = true;
} else if (ModelUtils.isAnyTypeSchema(p)) {
// The 'null' value is allowed when the OAS schema is 'any type'.
// See https://github.com/OAI/OpenAPI-Specification/issues/1389
if (Boolean.FALSE.equals(p.getNullable())) {
LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName());
}
property.isNullable = true;
property.isAnyType = true;
} else if (ModelUtils.isArraySchema(p)) {
// default to string if inner item is undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public AbstractGoCodegen() {
"complex128",
"rune",
"byte",
"map[string]interface{}",
"interface{}"
"ObjectType",
"AnyType"
)
);

Expand Down Expand Up @@ -128,9 +128,15 @@ public AbstractGoCodegen() {
// map[string]interface{}, whereas an arbitrary type is implemented
// in golang as interface{}.
// See issue #5387 for more details.
typeMapping.put("object", "map[string]interface{}");
typeMapping.put("interface{}", "interface{}");
typeMapping.put("AnyType", "interface{}");
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");

numberTypes = new HashSet<String>(
Arrays.asList(
Expand Down Expand Up @@ -391,7 +397,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 = "interface{}";
type = "AnyType";
} else if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
Expand Down Expand Up @@ -601,10 +607,10 @@ private void setExportParameterName(List<CodegenParameter> codegenParameters) {
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
// 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) {
// For containers (e.g. Array, Map), the generated code returns the type directly.
// In other cases, the generated code has a wrapper type and a Get() function to
// access the underlying type.
if (property.isContainer) {
property.vendorExtensions.put("x-golang-is-container", true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,15 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
}

for (CodegenProperty param : model.vars) {
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;
}
param.vendorExtensions.put("x-go-base-type", param.dataType);
if (!param.isNullable || param.isMapContainer || param.isListContainer ||
param.isFreeFormObject || param.isAnyType) {
if (!param.isNullable || param.isMapContainer || param.isListContainer) {
continue;
}
if (param.isDateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public PythonClientCodegen() {
// map uuid to string for the time being
typeMapping.put("UUID", "str");
typeMapping.put("URI", "str");
typeMapping.put("null", "none_type");

// from https://docs.python.org/3/reference/lexical_analysis.html#keywords
setReservedWordsLowerCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
composedSchemaSets.add(cm.oneOf);
for (Set<String> importSet : composedSchemaSets) {
for (String otherModelName : importSet) {
cm.imports.add(otherModelName);
if (!languageSpecificPrimitives.contains(otherModelName)) {
cm.imports.add(otherModelName);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
// note that we can't just toAdd.removeAll(m.vars) for every interfaceModel,
// as they might have different value of `hasMore` and thus are not equal
List<String> omitAdding = new ArrayList<String>();
for (CodegenModel m : cm.interfaceModels) {
for (CodegenProperty v : m.vars) {
omitAdding.add(v.baseName);
if (cm.interfaceModels != null) {
for (CodegenModel m : cm.interfaceModels) {
for (CodegenProperty v : m.vars) {
omitAdding.add(v.baseName);
}
}
}
for (CodegenProperty v : toAdd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
{{#isFreeFormObject}}
return o.{{name}}.Get()
{{/isFreeFormObject}}
{{^isFreeFormObject}}
return o.{{name}}
{{/isFreeFormObject}}
{{/isNullable}}
}

Expand All @@ -151,7 +156,12 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, b
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
{{#isFreeFormObject}}
return &o.{{name}}.Get(), true
{{/isFreeFormObject}}
{{^isFreeFormObject}}
return &o.{{name}}, true
{{/isFreeFormObject}}
{{/isNullable}}
}

Expand Down Expand Up @@ -187,7 +197,12 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
{{#isFreeFormObject}}
return *o.{{name}}.Get()
{{/isFreeFormObject}}
{{^isFreeFormObject}}
return *o.{{name}}
{{/isFreeFormObject}}
{{/isNullable}}
}

Expand All @@ -209,7 +224,12 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, b
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
{{#isFreeFormObject}}
return o.{{name}}.Get(), true
{{/isFreeFormObject}}
{{^isFreeFormObject}}
return o.{{name}}, true
{{/isFreeFormObject}}
{{/isNullable}}
}

Expand All @@ -233,7 +253,12 @@ func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
{{#isFreeFormObject}}
o.{{name}}.Set(&v)
{{/isFreeFormObject}}
{{^isFreeFormObject}}
o.{{name}} = &v
{{/isFreeFormObject}}
{{/isNullable}}
}
{{#isNullable}}
Expand Down Expand Up @@ -326,6 +351,7 @@ func (s *{{classname}}) UnmarshalJSON(src []byte) error {
{{/discriminator}}
{{^discriminator}}
{{#oneOf}}
{{! TODO: validate the payload against the JSON schema. Relying on golang JSON unmarshaling is not sufficient to determine the payload validates against the schema}}
var unmarshaled{{{.}}} *{{{.}}} = &{{{.}}}{}
err = json.Unmarshal(src, unmarshaled{{{.}}})
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
package {{packageName}}

import (
"bytes"
"encoding/json"
"errors"
"time"
)

Expand Down Expand Up @@ -30,6 +32,117 @@ func PtrString(v string) *string { return &v }
// PtrTime is helper routine that returns a pointer to given Time value.
func PtrTime(v time.Time) *time.Time { return &v }

var nullLiteral []byte = []byte("null")

// NullType is a type whose only value can be the JSON 'null' value.
type NullType struct{
isSet bool
}

func NewNullType() *NullType {
return nil
}

func (v NullType) Get() interface{} {
return nil
}

func (v *NullType) Set() {
v.isSet = true
}

func (v NullType) IsSet() bool {
return v.isSet
}

func (v *NullType) Unset() {
v.isSet = false
}

func (v NullType) MarshalJSON() ([]byte, error) {
return nullLiteral, nil
}

func (v *NullType) UnmarshalJSON(src []byte) error {
if bytes.Equal(bytes.TrimSpace(nullLiteral), src) {
v.isSet = true
return nil
}
return errors.New("Cannot unmarshal value into 'null' type")
}

// AnyType is a type whose value can anything.
type AnyType struct{
value *interface{}
isSet bool
}

func NewAnyType(val *interface{}) *AnyType {
return &AnyType{value: val, isSet: true}
}

func (v AnyType) Get() *interface{} {
return v.value
}

func (v *AnyType) Set(val *interface{}) {
v.value = val
v.isSet = true
}

func (v AnyType) IsSet() bool {
return v.isSet
}

func (v *AnyType) Unset() {
v.isSet = false
}

func (v AnyType) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}

func (v *AnyType) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

// ObjectType is a type whose value can be an object with undeclared properties.
type ObjectType struct{
value *map[string]interface{}
isSet bool
}

func NewObjectType(val *map[string]interface{}) *ObjectType {
return &ObjectType{value: val, isSet: true}
}

func (v ObjectType) Get() *map[string]interface{} {
return v.value
}

func (v *ObjectType) Set(val *map[string]interface{}) {
v.value = val
v.isSet = true
}

func (v ObjectType) IsSet() bool {
return v.isSet
}

func (v *ObjectType) Unset() {
v.isSet = false
}

func (v ObjectType) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}

func (v *ObjectType) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

type NullableBool struct {
value *bool
isSet bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def get_oneof_instance(self, model_args, constant_args):
and path to item.

Returns
oneof_instance (instance/None)
oneof_instance (instance)
"""
if len(self._composed_schemas['oneOf']) == 0:
return None
Expand Down Expand Up @@ -1086,9 +1086,11 @@ def get_anyof_instances(self, model_args, constant_args):
Args:
self: the class we are handling
model_args (dict): var_name to var_value
used to make instances
The input data, e.g. the payload that must match at least one
anyOf child schema in the OpenAPI document.
constant_args (dict): var_name to var_value
used to make instances
args that every model requires, including configuration, server
and path to item.

Returns
anyof_instances (list)
Expand Down
Loading