Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -83,7 +83,9 @@ public AbstractGoCodegen() {
"complex64",
"complex128",
"rune",
"byte")
"byte",
"interface{}"
)
);

instantiationTypes.clear();
Expand Down Expand Up @@ -298,12 +300,19 @@ public String getSchemaType(Schema p) {

if (ref != null && !ref.isEmpty()) {
type = openAPIType;
} else if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
return (type);
} else
type = openAPIType;
} else {
// Handle "any type" as an empty interface
if (openAPIType.equals("object") && p != null && !ModelUtils.isObjectSchema(p) && !ModelUtils.isMapSchema(p)) {
Copy link
Contributor

@zippolyte zippolyte Dec 3, 2019

Choose a reason for hiding this comment

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

Hmm, it seems this would only work with the following suggestion.

Suggested change
if (openAPIType.equals("object") && p != null && !ModelUtils.isObjectSchema(p) && !ModelUtils.isMapSchema(p)) {
if (openAPIType.equals("object") && p != null && ModelUtils.isObjectSchema(p) && !ModelUtils.isMapSchema(p)) {

Indeed, a schema like the following will be an ObjectSchema:

AnyType:
  type: object

Otherwise, I agree this should probably be added as part of go-experimental and released in a major

return "interface{}";
}

if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
return (type);
} else
type = openAPIType;
}
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ public void simpleModelTest() {
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
.addProperties("name", new StringSchema())
.addProperties("createdAt", new DateTimeSchema())
.addProperties("anyValue", new Schema())
.addRequiredItem("id")
.addRequiredItem("name");
.addRequiredItem("name")
.addRequiredItem("anyValue");
final DefaultCodegen codegen = new GoClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model, Collections.singletonMap("sample", model));

Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 3);
Assert.assertEquals(cm.vars.size(), 4);
Assert.assertEquals(cm.imports.size(), 1);

final CodegenProperty property1 = cm.vars.get(0);
Expand Down Expand Up @@ -85,10 +87,21 @@ public void simpleModelTest() {
Assert.assertEquals(property3.name, "CreatedAt");
Assert.assertNull(property3.defaultValue);
Assert.assertEquals(property3.baseType, "time.Time");
Assert.assertFalse(property3.hasMore);
Assert.assertTrue(property3.hasMore);
Assert.assertFalse(property3.required);

final CodegenProperty property4 = cm.vars.get(3);
Assert.assertEquals(property4.baseName, "anyValue");
Assert.assertEquals(property4.baseType, "interface{}");
Assert.assertEquals(property4.dataType, "interface{}");
Assert.assertTrue(property1.isPrimitiveType);
Assert.assertEquals(property4.name, "AnyValue");
Assert.assertNull(property4.defaultValue);
Assert.assertFalse(property4.hasMore);
Assert.assertTrue(property4.required);
}


@Test(description = "convert a model with list property")
public void listPropertyTest() {
final Schema model = new Schema()
Expand Down