Skip to content

Commit

Permalink
Ignore json = - fields (#5)
Browse files Browse the repository at this point in the history
* Ignore `json = -` fields

Fixes webrpc/webrpc#66

* Fix example RIDL

* Update webrpc-gen
  • Loading branch information
VojtechVitek authored Jul 20, 2023
1 parent 7b2bd64 commit 62b5fa3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install webrpc-gen
run: |
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.10.0/webrpc-gen.linux-amd64
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.11.3/webrpc-gen.linux-amd64
chmod +x ./webrpc-gen
echo $PWD >> $GITHUB_PATH
Expand All @@ -34,7 +34,7 @@ jobs:
webrpc-interoperability:
strategy:
matrix:
webrpc-version: [v0.10.0]
webrpc-version: [v0.10.0, v0.11.3]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion _examples/hello-webrpc/hello-api.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct User
+ go.tag.db = username

- createdAt?: timestamp
+ json = created_at,omitempty
+ json = created_at
+ go.tag.json = created_at,omitempty
+ go.tag.db = created_at


Expand Down
6 changes: 3 additions & 3 deletions _examples/hello-webrpc/webapp/client.gen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// hello-webrpc v1.0.0 d53c5acbdcf95d64a61f2b4e0792b38854e9353a
// hello-webrpc v1.0.0 e7d03ae5c6db914d3d31a21b762b6c3af1af1a07
// --
// Code generated by webrpc-gen@v0.10.0 with custom generator. DO NOT EDIT.
// Code generated by webrpc-gen@v0.11.3 with custom generator. DO NOT EDIT.
//
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js

Expand All @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1"
export const WebRPCSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebRPCSchemaHash = "d53c5acbdcf95d64a61f2b4e0792b38854e9353a"
export const WebRPCSchemaHash = "e7d03ae5c6db914d3d31a21b762b6c3af1af1a07"

//
// Types
Expand Down
34 changes: 27 additions & 7 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,39 @@
constructor(_data) {
this._data = {}
if (_data) {
{{range $type.Fields -}}
this._data['{{template "fieldName" dict "Field" . }}'] = _data['{{template "fieldName" dict "Field" . }}']
{{- range $_, $field := $type.Fields -}}
{{- $isExportable := true -}}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "json" -}}
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
{{- $isExportable = false}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $isExportable }}
this._data['{{template "fieldName" dict "Field" $field }}'] = _data['{{template "fieldName" dict "Field" $field }}']
{{- end -}}
{{end}}
}
}
{{ range $type.Fields -}}
get {{template "fieldName" dict "Field" . }}() {
return this._data['{{template "fieldName" dict "Field" . }}']
{{ range $_, $field := $type.Fields -}}
{{- $isExportable := true -}}
{{- range $meta := $field.Meta -}}
{{- if exists $meta "json" -}}
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
{{- $isExportable = false}}
{{- end -}}
{{- end -}}
{{- end }}
{{- if $isExportable }}
get {{template "fieldName" dict "Field" $field }}() {
return this._data['{{template "fieldName" dict "Field" $field }}']
}
set {{template "fieldName" dict "Field" . }}(value) {
this._data['{{template "fieldName" dict "Field" . }}'] = value
set {{template "fieldName" dict "Field" $field }}(value) {
this._data['{{template "fieldName" dict "Field" $field }}'] = value
}
{{end}}
{{- end }}
toJSON() {
return this._data
}
Expand Down

0 comments on commit 62b5fa3

Please sign in to comment.