Skip to content

Commit

Permalink
adding go object generator
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Feb 23, 2023
1 parent 35e084d commit 9d7b103
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions render/example_golang_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package render

import (
"os"
"strings"
"testing"

"github.com/matryer/is"
"github.com/pacedotdev/oto/parser"
)

func TestExmapleGolang(t *testing.T) {
is := is.New(t)
patterns := []string{"../parser/testdata/services/pleasantries"}
parser := parser.New(patterns...)
parser.Verbose = testing.Verbose()
parser.ExcludeInterfaces = []string{"Ignorer"}
def, err := parser.Parse()
is.NoErr(err)
inputObject, err := def.Object(def.Services[0].Methods[0].InputObject.ObjectName)
is.NoErr(err) // get inputObject
example := ObjectGolang(def, *inputObject, 0)
err = os.WriteFile("./delete-me-example.go.notgo", []byte(example), 0666)
is.NoErr(err) // write file

for _, should := range []string{
"// Package services contains services.",
"package services",
} {
if !strings.Contains(example, should) {
t.Errorf("missing: %s", should)
is.Fail()
}
}
}
1 change: 1 addition & 0 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Render(template string, def parser.Definition, params map[string]interface{
ctx.Set("format_comment_text", formatCommentText)
ctx.Set("format_comment_html", formatCommentHTML)
ctx.Set("format_tags", formatTags)
ctx.Set("object_golang", ObjectGolang)
s, err := plush.Render(string(template), ctx)
if err != nil {
return "", err
Expand Down
4 changes: 4 additions & 0 deletions testdata/services/paging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package services
// Page describes a page of data.
type Page struct {
// Cursor is the cursor to start at.
// example: "cursor-123456"
Cursor string
// OrderField is the field to use to order the results.
// example: "Name"
OrderField string
// OrderAsc is whether to order the field in an ascending order or not.
// example: "ASC"
// options: ["ASC", "DESC"]
OrderAsc bool
}

0 comments on commit 9d7b103

Please sign in to comment.