Skip to content

Commit

Permalink
render godocs from parsed comments (#57)
Browse files Browse the repository at this point in the history
* render godocs from parsed comments

* update examples with comments
  • Loading branch information
LukasJenicek committed Mar 11, 2024
1 parent d2cd495 commit 3f1f017
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
20 changes: 14 additions & 6 deletions _examples/golang-basics/example.gen.go

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

12 changes: 10 additions & 2 deletions _examples/golang-basics/example.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ name = example # name of your backend app
version = v0.0.1 # version of your schema


# user role
# which defines which type of operations user can do
enum Kind: uint32
- USER
- USER # user can only see number of transactions
# admin permissions
# can manage transactions
# revert transactions
# see analytics dashboard
- ADMIN

enum Intent: string
- openSession
- closeSession
- validateSession

# Defines users within out wallet app
struct User
- id: uint64
+ go.field.name = ID
Expand All @@ -23,7 +30,8 @@ struct User
+ go.field.type = uuid.UUID
+ go.type.import = github.com/google/uuid

- username: string
# unique identifier of the user
- username: string # must be unique !
+ json = USERNAME
+ go.tag.db = username

Expand Down
6 changes: 3 additions & 3 deletions _examples/golang-imports/api.gen.go

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

9 changes: 7 additions & 2 deletions enum.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ type {{$name}} {{$type}}
{{- end }}

const (
{{- range $fields}}
{{$name}}_{{.Name}} {{$name}} = {{.Value}}
{{- range $_, $field := $fields }}
{{- if gt (len $field.Comments) 0 -}}
{{- range $_, $comment := $field.Comments }}
// {{ replaceAll $comment "\"" "'" }}
{{- end }}
{{- end }}
{{$name}}_{{.Name}} {{$name}} = {{$field.Value}}
{{- end}}
)

Expand Down
1 change: 0 additions & 1 deletion field.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
[]{{template "field" dict "Name" $name "Type" (listElemType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $typeMeta}}

{{- else if isCoreType $type -}}

{{if $optional}}*{{end}}{{ get $typeMap $type }}

{{- else -}}{{- /* structs */ -}}
Expand Down
11 changes: 8 additions & 3 deletions struct.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
{{- $typePrefix := .TypePrefix -}}

type {{$name}} struct {
{{range $_, $field := $fields -}}
{{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}}
{{end -}}
{{- range $_, $field := $fields -}}
{{- if gt (len $field.Comments) 0 -}}
{{- range $_, $comment := $field.Comments }}
// {{ replaceAll $comment "\"" "'" }}
{{- end }}
{{- end }}
{{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 }}
{{- end }}
}
{{- end }}
5 changes: 5 additions & 0 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
{{ end -}}

{{- if and (eq $type.Kind "struct") $opts.types }}
{{- if gt (len $type.Comments) 0 }}
{{- range $_, $comment := $type.Comments }}
// {{ replaceAll $comment "\"" "'" }}
{{- end }}
{{- end }}
{{template "struct" dict "Name" $type.Name "TypeMap" $typeMap "TypePrefix" $typePrefix "Fields" $type.Fields}}
{{ end -}}

Expand Down

0 comments on commit 3f1f017

Please sign in to comment.