Skip to content

Commit

Permalink
Support required vs. optional properties (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek authored Jul 10, 2023
1 parent 1ebf182 commit 5f47cad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
24 changes: 23 additions & 1 deletion _examples/openapi.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# example v0.0.1 8c962b82639c77d8c62f134f5c009611f35c7f8f
# example v0.0.1 21006c2dc2dc334a0382a645c1103910d151bb8c
# --
# Code generated by [email protected] with custom generator; DO NOT EDIT
#
Expand Down Expand Up @@ -218,6 +218,10 @@ components:
- ADMIN
User:
type: object
required:
- id
- username
- role
properties:
id:
type: number
Expand All @@ -227,11 +231,19 @@ components:
type: string
SearchFilter:
type: object
required:
- q
properties:
q:
type: string
active:
type: boolean
Version:
type: object
required:
- webrpcVersion
- schemaVersion
- schemaHash
properties:
webrpcVersion:
type: string
Expand All @@ -241,6 +253,16 @@ components:
type: string
ComplexType:
type: object
required:
- meta
- metaNestedExample
- namesList
- numsList
- doubleArray
- listOfMaps
- listOfUsers
- mapOfUsers
- user
properties:
meta:
type: object
Expand Down
1 change: 1 addition & 0 deletions _examples/proto.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct User

struct SearchFilter
- q: string
- active?: bool

struct Version
- webrpcVersion: string
Expand Down
12 changes: 9 additions & 3 deletions type.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
{{else}}
type: object
{{- if gt (len $type.Fields) 0}}
required:
{{- range $i, $field := $type.Fields -}}
{{- if not $field.Optional }}
- {{$field.Name}}
{{- end -}}
{{- end }}
properties:
{{- end -}}
{{- range $i, $fields := $type.Fields }}
{{.Name -}}:
{{ template "fieldType" dict "Type" .Type "TypeMap" $typeMap "Indent" " " }}
{{- range $i, $field := $type.Fields }}
{{$field.Name -}}:
{{ template "fieldType" dict "Type" $field.Type "TypeMap" $typeMap "Indent" " " }}
{{- end -}}
{{- end -}}
{{- end -}}

0 comments on commit 5f47cad

Please sign in to comment.