Skip to content

Commit 3f1f017

Browse files
authored
render godocs from parsed comments (#57)
* render godocs from parsed comments * update examples with comments
1 parent d2cd495 commit 3f1f017

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

_examples/golang-basics/example.gen.go

+14-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/golang-basics/example.ridl

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ name = example # name of your backend app
44
version = v0.0.1 # version of your schema
55

66

7+
# user role
8+
# which defines which type of operations user can do
79
enum Kind: uint32
8-
- USER
10+
- USER # user can only see number of transactions
11+
# admin permissions
12+
# can manage transactions
13+
# revert transactions
14+
# see analytics dashboard
915
- ADMIN
1016

1117
enum Intent: string
1218
- openSession
1319
- closeSession
1420
- validateSession
1521

22+
# Defines users within out wallet app
1623
struct User
1724
- id: uint64
1825
+ go.field.name = ID
@@ -23,7 +30,8 @@ struct User
2330
+ go.field.type = uuid.UUID
2431
+ go.type.import = github.com/google/uuid
2532

26-
- username: string
33+
# unique identifier of the user
34+
- username: string # must be unique !
2735
+ json = USERNAME
2836
+ go.tag.db = username
2937

_examples/golang-imports/api.gen.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enum.go.tmpl

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ type {{$name}} {{$type}}
1010
{{- end }}
1111

1212
const (
13-
{{- range $fields}}
14-
{{$name}}_{{.Name}} {{$name}} = {{.Value}}
13+
{{- range $_, $field := $fields }}
14+
{{- if gt (len $field.Comments) 0 -}}
15+
{{- range $_, $comment := $field.Comments }}
16+
// {{ replaceAll $comment "\"" "'" }}
17+
{{- end }}
18+
{{- end }}
19+
{{$name}}_{{.Name}} {{$name}} = {{$field.Value}}
1520
{{- end}}
1621
)
1722

field.go.tmpl

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
[]{{template "field" dict "Name" $name "Type" (listElemType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $typeMeta}}
4949

5050
{{- else if isCoreType $type -}}
51-
5251
{{if $optional}}*{{end}}{{ get $typeMap $type }}
5352

5453
{{- else -}}{{- /* structs */ -}}

struct.go.tmpl

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
{{- $typePrefix := .TypePrefix -}}
77

88
type {{$name}} struct {
9-
{{range $_, $field := $fields -}}
10-
{{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true}}
11-
{{end -}}
9+
{{- range $_, $field := $fields -}}
10+
{{- if gt (len $field.Comments) 0 -}}
11+
{{- range $_, $comment := $field.Comments }}
12+
// {{ replaceAll $comment "\"" "'" }}
13+
{{- end }}
14+
{{- end }}
15+
{{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true }}
16+
{{- end }}
1217
}
1318
{{- end }}

types.go.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
{{ end -}}
2121

2222
{{- if and (eq $type.Kind "struct") $opts.types }}
23+
{{- if gt (len $type.Comments) 0 }}
24+
{{- range $_, $comment := $type.Comments }}
25+
// {{ replaceAll $comment "\"" "'" }}
26+
{{- end }}
27+
{{- end }}
2328
{{template "struct" dict "Name" $type.Name "TypeMap" $typeMap "TypePrefix" $typePrefix "Fields" $type.Fields}}
2429
{{ end -}}
2530

0 commit comments

Comments
 (0)