Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change swagger generator to produce lowerCamelCase field names, change default marshaler to do the same, and also emit default values #540

Closed
wants to merge 4 commits into from
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
84 changes: 59 additions & 25 deletions examples/browser/a_bit_of_everything_service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ABitOfEverythingService', function() {

describe('Create', function() {
var created;
var expected = {
var params = {
float_value: 1.5,
double_value: 2.5,
int64_value: "4294967296",
Expand All @@ -35,9 +35,37 @@ describe('ABitOfEverythingService', function() {
sint64_value: "4611686018427387903",
nonConventionalNameValue: "camelCase",
};
var expected = {
floatValue: 1.5,
doubleValue: 2.5,
int64Value: "4294967296",
uint64Value: "9223372036854775807",
int32Value: -2147483648,
fixed64Value: "9223372036854775807",
fixed32Value: 4294967295,
boolValue: true,
stringValue: "strprefix/foo",
uint32Value: 4294967295,
sfixed32Value: 2147483647,
sfixed64Value: "-4611686018427387904",
sint32Value: 2147483647,
sint64Value: "4611686018427387903",
nonConventionalNameValue: "camelCase",

bytesValue: null,
singleNested: null,
nested: [],
enumValue: "ZERO",
repeatedStringValue: [],
mapValue: Object({}),
mappedStringValue: Object({}),
mappedNestedValue: Object({}),
timestampValue: null,
repeatedEnumValue: [],
};

beforeEach(function(done) {
client.ABitOfEverythingService.Create(expected).then(function(resp) {
client.ABitOfEverythingService.Create(params).then(function(resp) {
created = resp.obj;
}).catch(function(err) {
done.fail(err);
Expand All @@ -57,35 +85,41 @@ describe('ABitOfEverythingService', function() {
describe('CreateBody', function() {
var created;
var expected = {
float_value: 1.5,
double_value: 2.5,
int64_value: "4294967296",
uint64_value: "9223372036854775807",
int32_value: -2147483648,
fixed64_value: "9223372036854775807",
fixed32_value: 4294967295,
bool_value: true,
string_value: "strprefix/foo",
uint32_value: 4294967295,
sfixed32_value: 2147483647,
sfixed64_value: "-4611686018427387904",
sint32_value: 2147483647,
sint64_value: "4611686018427387903",
floatValue: 1.5,
doubleValue: 2.5,
int64Value: "4294967296",
uint64Value: "9223372036854775807",
int32Value: -2147483648,
fixed64Value: "9223372036854775807",
fixed32Value: 4294967295,
boolValue: true,
stringValue: "strprefix/foo",
uint32Value: 4294967295,
sfixed32Value: 2147483647,
sfixed64Value: "-4611686018427387904",
sint32Value: 2147483647,
sint64Value: "4611686018427387903",
nonConventionalNameValue: "camelCase",

nested: [
{ name: "bar", amount: 10 },
{ name: "baz", amount: 20 },
{ name: "bar", amount: 10, ok: 'FALSE' },
{ name: "baz", amount: 20, ok: 'FALSE' },
],
repeated_string_value: ["a", "b", "c"],
oneof_string: "x",
repeatedStringValue: ["a", "b", "c"],
oneofString: "x",
// TODO(yugui) Support enum by name
map_value: { a: 1, b: 2 },
mapped_string_value: { a: "x", b: "y" },
mapped_nested_value: {
a: { name: "x", amount: 1 },
b: { name: "y", amount: 2 },
mapValue: { a: 1, b: 2 },
mappedStringValue: { a: "x", b: "y" },
mappedNestedValue: {
a: { name: "x", amount: 1, ok: 'FALSE' },
b: { name: "y", amount: 2, ok: 'FALSE' },
},

bytesValue: null,
singleNested: null,
enumValue: "ZERO",
timestampValue: null,
repeatedEnumValue: [],
};

beforeEach(function(done) {
Expand Down
4 changes: 2 additions & 2 deletions examples/browser/echo_service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('EchoService', function() {
{id: "foo"},
{responseContentType: "application/json"}
).then(function(resp) {
expect(resp.obj).toEqual({id: "foo"});
expect(resp.obj).toEqual({id: "foo", num: '0'});
}).catch(function(err) {
done.fail(err);
}).then(done);
Expand All @@ -34,7 +34,7 @@ describe('EchoService', function() {
{body: {id: "foo"}},
{responseContentType: "application/json"}
).then(function(resp) {
expect(resp.obj).toEqual({id: "foo"});
expect(resp.obj).toEqual({id: "foo", num: '0'});
}).catch(function(err) {
done.fail(err);
}).then(done);
Expand Down
24 changes: 11 additions & 13 deletions examples/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestAbitOfEverythingClient(t *testing.T) {
}

func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
want := &abe.ExamplepbABitOfEverything{
want := &abe.ExamplepbABitOfEverythingSansEnum{
FloatValue: 1.5,
DoubleValue: 2.5,
Int64Value: "4294967296",
Expand All @@ -72,8 +72,13 @@ func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
Sint32Value: 2147483647,
Sint64Value: "4611686018427387903",
NonConventionalNameValue: "camelCase",

Nested: []abe.ExamplepbABitOfEverythingSansEnumNested{},
RepeatedStringValue: []string{},
MappedStringValue: map[string]string{},
MappedNestedValue: map[string]abe.ExamplepbABitOfEverythingSansEnumNested{},
}
resp, _, err := cl.Create(
resp, _, err := cl.CreateSansEnum(
want.FloatValue,
want.DoubleValue,
want.Int64Value,
Expand Down Expand Up @@ -103,10 +108,7 @@ func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
}

func testABEClientCreateBody(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
t.Log("TODO: support enum")
return

want := abe.ExamplepbABitOfEverything{
want := &abe.ExamplepbABitOfEverythingSansEnum{
FloatValue: 1.5,
DoubleValue: 2.5,
Int64Value: "4294967296",
Expand All @@ -123,7 +125,7 @@ func testABEClientCreateBody(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
Sint64Value: "4611686018427387903",
NonConventionalNameValue: "camelCase",

Nested: []abe.ABitOfEverythingNested{
Nested: []abe.ExamplepbABitOfEverythingSansEnumNested{
{
Name: "bar",
Amount: 10,
Expand All @@ -135,20 +137,16 @@ func testABEClientCreateBody(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
},
RepeatedStringValue: []string{"a", "b", "c"},
OneofString: "x",
MapValue: map[string]abe.ExamplepbNumericEnum{
// "a": abe.ExamplepbNumericEnum_ONE,
// "b": abe.ExamplepbNumericEnum_ZERO,
},
MappedStringValue: map[string]string{
"a": "x",
"b": "y",
},
MappedNestedValue: map[string]abe.ABitOfEverythingNested{
MappedNestedValue: map[string]abe.ExamplepbABitOfEverythingSansEnumNested{
"a": {Name: "x", Amount: 1},
"b": {Name: "y", Amount: 2},
},
}
resp, _, err := cl.CreateBody(want)
resp, _, err := cl.CreateBodySansEnum(*want)
if err != nil {
t.Errorf("cl.CreateBody(%#v) failed with %v; want success", want, err)
}
Expand Down
Loading