Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pacedotdev/oto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.10.1
Choose a base ref
...
head repository: pacedotdev/oto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.10.2
Choose a head ref
  • 10 commits
  • 12 files changed
  • 3 contributors

Commits on Aug 21, 2020

  1. added version

    matryer committed Aug 21, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c8131e6 View commit details
  2. made parser a module

    matryer committed Aug 21, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    08eadf7 View commit details

Commits on Aug 22, 2020

  1. Copy the full SHA
    3af828f View commit details

Commits on Aug 23, 2020

  1. Fixing typo in template

    The template is trying to access a "method" called `field.Type.JSType()`. It should be `field.Type.JSType`.
    TcM1911 authored Aug 23, 2020
    Copy the full SHA
    2fd1a63 View commit details

Commits on Aug 26, 2020

  1. Merge pull request #16 from TcM1911/patch-1

    Fixing typo in template
    matryer authored Aug 26, 2020
    Copy the full SHA
    78f559a View commit details

Commits on Aug 27, 2020

  1. fixed broken template

    matryer committed Aug 27, 2020
    Copy the full SHA
    f61f1b9 View commit details
  2. Copy the full SHA
    8e8a53c View commit details

Commits on Aug 28, 2020

  1. always return metadata map

    matryer committed Aug 28, 2020
    Copy the full SHA
    28ce4a9 View commit details
  2. Copy the full SHA
    1e00a18 View commit details
  3. Copy the full SHA
    eeaf776 View commit details
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -41,7 +41,8 @@ type GreetRequest struct {
Name string
}

// GreetResponse is the response object for GreeterService.Greet.
// GreetResponse is the response object containing a
// person's greeting.
type GreetResponse struct {
// Greeting is the greeting that was generated.
// example: "Hello Mat Ryer"
3 changes: 2 additions & 1 deletion example/def/greeter_service.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ type GreetRequest struct {
Name string
}

// GreetResponse is the response object for GreeterService.Greet.
// GreetResponse is the response object containing a
// person's greeting.
type GreetResponse struct {
// Greeting is a nice message welcoming somebody.
Greeting string
3 changes: 2 additions & 1 deletion example/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -2,21 +2,16 @@ module github.com/pacedotdev/oto

go 1.13

replace github.com/pacedotdev/oto/parser => ./parser

require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/structtag v1.2.0
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/flect v0.2.1 // indirect
github.com/gobuffalo/helpers v0.6.1 // indirect
github.com/gobuffalo/plush v3.8.3+incompatible
github.com/gobuffalo/tags v2.1.7+incompatible // indirect
github.com/gobuffalo/validate/v3 v3.3.0 // indirect
github.com/gofrs/uuid v3.3.0+incompatible // indirect
github.com/markbates/inflect v1.0.4
github.com/matryer/is v1.4.0
github.com/microcosm-cc/bluemonday v1.0.3 // indirect
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.6.0 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b
)
31 changes: 5 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU=
github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -13,11 +9,8 @@ github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/gobuffalo/envy v1.6.5 h1:X3is06x7v0nW2xiy2yFbbIjwHz57CD6z6MkvqULTCm8=
github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
github.com/gobuffalo/envy v1.9.0 h1:eZR0DuEgVLfeIb1zIKt3bT4YovIMf9O9LXQeCZLXpqE=
github.com/gobuffalo/envy v1.9.0/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/flect v0.2.0 h1:EWCvMGGxOjsgwlWaP+f4+Hh6yrrte7JeFL2S6b+0hdM=
github.com/gobuffalo/flect v0.2.0/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80=
github.com/gobuffalo/flect v0.2.1 h1:GPoRjEN0QObosV4XwuoWvSd5uSiL0N3e91/xqyY4crQ=
github.com/gobuffalo/flect v0.2.1/go.mod h1:vmkQwuZYhN5Pc4ljYQZzP+1sq+NEkK+lh20jmEmX3jc=
github.com/gobuffalo/github_flavored_markdown v1.1.0 h1:8Zzj4fTRl/OP2R7sGerzSf6g2nEJnaBEJe7UAOiEvbQ=
github.com/gobuffalo/github_flavored_markdown v1.1.0/go.mod h1:TSpTKWcRTI0+v7W3x8dkSKMLJSUpuVitlptCkpeY8ic=
github.com/gobuffalo/helpers v0.6.1 h1:LLcL4BsiyDQYtMRUUpyFdBFvFXQ6hNYOpwrcYeilVWM=
@@ -30,14 +23,8 @@ github.com/gobuffalo/tags/v3 v3.1.0 h1:mzdCYooN2VsLRr8KIAdEZ1lh1Py7JSMsiEGCGata2
github.com/gobuffalo/tags/v3 v3.1.0/go.mod h1:ZQeN6TCTiwAFnS0dNcbDtSgZDwNKSpqajvVtt6mlYpA=
github.com/gobuffalo/validate/v3 v3.0.0 h1:dF7Bg8NMF9Zv8bZvUMXYJXxZdj+eSZ8z/lGM7/jVFUE=
github.com/gobuffalo/validate/v3 v3.0.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
github.com/gobuffalo/validate/v3 v3.3.0 h1:j++FFx9gtjTmIQeI9xlaIDZ0nV4x8YQZz4RJAlZNUxg=
github.com/gobuffalo/validate/v3 v3.3.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -51,15 +38,10 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/microcosm-cc/bluemonday v1.0.3 h1:EjVH7OqbU219kdm8acbveoclh2zZFqPJTJw6VUlTLAQ=
github.com/microcosm-cc/bluemonday v1.0.3/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.6.0 h1:IZRgg4sfrDH7nsAD1Y/Nwj+GzIfEwpJSLjCaNC3SbsI=
github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
@@ -69,6 +51,7 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
@@ -85,9 +68,8 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
@@ -97,18 +79,15 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d h1:hYhnolbefSSt3WZp66sgmgnEOFv5PD6a5PIcnKJ8jdU=
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b h1:ob2Rprc4uPVPGKaYKm9lrGewYQJRu7KtuzGTICCM1X4=
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ flags:`)
}
p.Verbose = *v
if p.Verbose {
fmt.Println("oto - github.com/pacedotdev/oto")
fmt.Println("oto - github.com/pacedotdev/oto", Version)
}
def, err := p.Parse()
if err != nil {
12 changes: 7 additions & 5 deletions otohttp/templates/client.ts.plush
Original file line number Diff line number Diff line change
@@ -27,7 +27,9 @@ export class Client {
const headers: HeadersInit = new Headers();
headers.set('Accept', 'application/json');
headers.set('Content-Type', 'application/json');
await this.client.headers(headers);
if (this.client.headers) {
await this.client.headers(headers);
}
const response = await fetch(this.client.basepath + '<%= service.Name %>.<%= method.Name %>', {
method: 'POST',
headers: headers,
@@ -52,13 +54,13 @@ export class Client {
<%= if (field.Type.IsObject) { %>
<%= if (field.Type.Multiple) { %>
if (data.<%= field.NameLowerCamel %>) {
this.<%= field.NameLowerCamel %> = new Array<<%= field.Type.ObjectName() %>>()
this.<%= field.NameLowerCamel %> = new Array<<%= field.Type.ObjectName %>>()
for (let i = 0; i < data.<%= field.NameLowerCamel %>.length; i++) {
this.<%= field.NameLowerCamel %>.push(new <%= field.Type.ObjectName() %>(data.<%= field.NameLowerCamel %>[i]));
this.<%= field.NameLowerCamel %>.push(new <%= field.Type.ObjectName %>(data.<%= field.NameLowerCamel %>[i]));
}
}
<% } else { %>
this.<%= field.NameLowerCamel %> = new <%= field.Type.ObjectName() %>(data.<%= field.NameLowerCamel %>);
this.<%= field.NameLowerCamel %> = new <%= field.Type.ObjectName %>(data.<%= field.NameLowerCamel %>);
<% } %>
<% } else { %>
this.<%= field.NameLowerCamel %> = data.<%= field.NameLowerCamel %>;
@@ -67,7 +69,7 @@ export class Client {
}
}
<%= for (field) in object.Fields { %>
<%= format_comment_text(field.Comment) %> <%= field.NameLowerCamel %>: <%= if (field.Type.IsObject) { %><%= field.Type.TypeName %><% } else { %><%= field.Type.JSType() %><% } %><%= if (field.Type.Multiple) { %>[]<% } %>;
<%= format_comment_text(field.Comment) %> <%= field.NameLowerCamel %>: <%= if (field.Type.IsObject) { %><%= field.Type.TypeName %><% } else { %><%= field.Type.JSType %><% } %><%= if (field.Type.Multiple) { %>[]<% } %>;
<% } %>
}
<% } %>
9 changes: 4 additions & 5 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ func New(patterns ...string) *Parser {
// Parse parses the files specified, returning the definition.
func (p *Parser) Parse() (Definition, error) {
cfg := &packages.Config{
Mode: packages.NeedTypes | packages.NeedDeps | packages.NeedName | packages.NeedSyntax,
Mode: packages.NeedTypes | packages.NeedName | packages.NeedTypesInfo | packages.NeedDeps | packages.NeedName | packages.NeedSyntax,
Tests: false,
}
pkgs, err := packages.Load(cfg, p.patterns...)
@@ -161,7 +161,6 @@ func (p *Parser) Parse() (Definition, error) {
if err != nil {
panic(err)
}

p.def.PackageName = pkg.Name
scope := pkg.Types.Scope()
for _, name := range scope.Names() {
@@ -531,17 +530,17 @@ func (p *Parser) extractCommentMetadata(comment string) (map[string]interface{},
if metadataCommentRegex.MatchString(line) {
line = strings.TrimSpace(line)
if line == "" {
return nil, strings.Join(lines, "\n"), nil
return metadata, strings.Join(lines, "\n"), nil
}
// SplitN is being used to ensure that colons can exist
// in values by only splitting on the first colon in the line
splitLine := strings.SplitN(line, ":", 2)
splitLine := strings.SplitN(line, ": ", 2)
key := splitLine[0]
value := strings.TrimSpace(splitLine[1])
var val interface{}
if err := json.Unmarshal([]byte(value), &val); err != nil {
if p.Verbose {
fmt.Printf("(skipping) failed to marshal JSON value (%s): %s", err, value)
fmt.Printf("(skipping) failed to marshal JSON value (%s): %s\n", err, value)
}
continue
}
16 changes: 16 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package parser

import (
"bytes"
"go/doc"
"strings"
"testing"

"github.com/matryer/is"
@@ -10,6 +13,7 @@ func TestParse(t *testing.T) {
is := is.New(t)
patterns := []string{"./testdata/services/pleasantries"}
parser := New(patterns...)
parser.Verbose = testing.Verbose()
parser.ExcludeInterfaces = []string{"Ignorer"}
def, err := parser.Parse()
is.NoErr(err)
@@ -43,6 +47,16 @@ You will love it.`)
is.Equal(def.Services[0].Methods[1].OutputObject.Multiple, false)
is.Equal(def.Services[0].Methods[1].OutputObject.Package, "")

formatCommentText := func(s string) string {
var buf bytes.Buffer
doc.ToText(&buf, s, "// ", "", 80)
return buf.String()
}
greetResponseObject, err := def.Object(def.Services[0].Methods[1].OutputObject.TypeName)
is.NoErr(err)
actualComment := strings.TrimSpace(formatCommentText(greetResponseObject.Comment))
is.Equal(actualComment, `// GreetResponse is the response object containing a person's greeting.`)

greetInputObject, err := def.Object(def.Services[0].Methods[0].InputObject.TypeName)
is.NoErr(err)
is.Equal(greetInputObject.Name, "GetGreetingsRequest")
@@ -146,6 +160,7 @@ You will love it.`)
is.Equal(welcomeOutputObject.Fields[1].Type.TypeName, "string")
is.Equal(welcomeOutputObject.Fields[1].Type.Multiple, false)
is.Equal(welcomeOutputObject.Fields[1].Type.Package, "")
is.True(welcomeOutputObject.Metadata != nil)

is.Equal(len(def.Objects), 8)
for i := range def.Objects {
@@ -169,6 +184,7 @@ func TestExtractCommentMetadata(t *testing.T) {
is := is.New(t)

p := &Parser{}
p.Verbose = testing.Verbose()
metadata, comment, err := p.extractCommentMetadata(`
This is a comment
example: "With an example"
5 changes: 3 additions & 2 deletions parser/testdata/services/pleasantries/greeter.go
Original file line number Diff line number Diff line change
@@ -23,9 +23,10 @@ type GreetRequest struct {
Names []string
}

// GreetResponse is the response object for GreeterService.Greet.
// GreetResponse is the response object containing a
// person's greeting.
type GreetResponse struct {
// Greeting is the generated Greeting.
// Greeting is the greeted person's Greeting.
Greeting Greeting
}

7 changes: 7 additions & 0 deletions render/render_test.go
Original file line number Diff line number Diff line change
@@ -67,3 +67,10 @@ func TestFormatTags(t *testing.T) {
is.Equal(trimBackticks(string(tagStr)), `json:"field,omitempty" monkey:"true"`)

}

func TestFormatCommentText(t *testing.T) {
is := is.New(t)

actual := strings.TrimSpace(formatCommentText("card's"))
is.Equal(actual, "// card's")
}
3 changes: 2 additions & 1 deletion testdata/services/pleasantries/greeter.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ type GreetRequest struct {
Names []string
}

// GreetResponse is the response object for GreeterService.Greet.
// GreetResponse is the response object containing a
// person's greeting.
type GreetResponse struct {
// Greeting is the generated Greeting.
Greeting Greeting