diff --git a/render/example_golang_test.go b/render/example_golang_test.go new file mode 100644 index 0000000..663dd49 --- /dev/null +++ b/render/example_golang_test.go @@ -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() + } + } +} diff --git a/render/render.go b/render/render.go index 974c173..edc2a9e 100644 --- a/render/render.go +++ b/render/render.go @@ -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 diff --git a/testdata/services/paging.go b/testdata/services/paging.go index c4ebd75..6b12f44 100644 --- a/testdata/services/paging.go +++ b/testdata/services/paging.go @@ -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 }