Skip to content

Commit 62b5fa3

Browse files
authored
Ignore json = - fields (#5)
* Ignore `json = -` fields Fixes webrpc/webrpc#66 * Fix example RIDL * Update webrpc-gen
1 parent 7b2bd64 commit 62b5fa3

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- name: Install webrpc-gen
1717
run: |
18-
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.10.0/webrpc-gen.linux-amd64
18+
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.11.3/webrpc-gen.linux-amd64
1919
chmod +x ./webrpc-gen
2020
echo $PWD >> $GITHUB_PATH
2121
@@ -34,7 +34,7 @@ jobs:
3434
webrpc-interoperability:
3535
strategy:
3636
matrix:
37-
webrpc-version: [v0.10.0]
37+
webrpc-version: [v0.10.0, v0.11.3]
3838
runs-on: ubuntu-latest
3939
steps:
4040
- uses: actions/checkout@v3

_examples/hello-webrpc/hello-api.ridl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ struct User
1919
+ go.tag.db = username
2020

2121
- createdAt?: timestamp
22-
+ json = created_at,omitempty
22+
+ json = created_at
23+
+ go.tag.json = created_at,omitempty
2324
+ go.tag.db = created_at
2425

2526

_examples/hello-webrpc/webapp/client.gen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// hello-webrpc v1.0.0 d53c5acbdcf95d64a61f2b4e0792b38854e9353a
1+
// hello-webrpc v1.0.0 e7d03ae5c6db914d3d31a21b762b6c3af1af1a07
22
// --
3-
// Code generated by webrpc-gen@v0.10.0 with custom generator. DO NOT EDIT.
3+
// Code generated by webrpc-gen@v0.11.3 with custom generator. DO NOT EDIT.
44
//
55
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js
66

@@ -11,7 +11,7 @@ export const WebRPCVersion = "v1"
1111
export const WebRPCSchemaVersion = "v1.0.0"
1212

1313
// Schema hash generated from your RIDL schema
14-
export const WebRPCSchemaHash = "d53c5acbdcf95d64a61f2b4e0792b38854e9353a"
14+
export const WebRPCSchemaHash = "e7d03ae5c6db914d3d31a21b762b6c3af1af1a07"
1515

1616
//
1717
// Types

types.go.tmpl

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,39 @@
2424
constructor(_data) {
2525
this._data = {}
2626
if (_data) {
27-
{{range $type.Fields -}}
28-
this._data['{{template "fieldName" dict "Field" . }}'] = _data['{{template "fieldName" dict "Field" . }}']
27+
{{- range $_, $field := $type.Fields -}}
28+
{{- $isExportable := true -}}
29+
{{- range $meta := $field.Meta -}}
30+
{{- if exists $meta "json" -}}
31+
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
32+
{{- $isExportable = false}}
33+
{{- end -}}
34+
{{- end -}}
35+
{{- end -}}
36+
{{- if $isExportable }}
37+
this._data['{{template "fieldName" dict "Field" $field }}'] = _data['{{template "fieldName" dict "Field" $field }}']
38+
{{- end -}}
2939
{{end}}
3040
}
3141
}
32-
{{ range $type.Fields -}}
33-
get {{template "fieldName" dict "Field" . }}() {
34-
return this._data['{{template "fieldName" dict "Field" . }}']
42+
{{ range $_, $field := $type.Fields -}}
43+
{{- $isExportable := true -}}
44+
{{- range $meta := $field.Meta -}}
45+
{{- if exists $meta "json" -}}
46+
{{- if eq (printf "%v" (get $meta "json")) "-" -}}
47+
{{- $isExportable = false}}
48+
{{- end -}}
49+
{{- end -}}
50+
{{- end }}
51+
{{- if $isExportable }}
52+
get {{template "fieldName" dict "Field" $field }}() {
53+
return this._data['{{template "fieldName" dict "Field" $field }}']
3554
}
36-
set {{template "fieldName" dict "Field" . }}(value) {
37-
this._data['{{template "fieldName" dict "Field" . }}'] = value
55+
set {{template "fieldName" dict "Field" $field }}(value) {
56+
this._data['{{template "fieldName" dict "Field" $field }}'] = value
3857
}
3958
{{end}}
59+
{{- end }}
4060
toJSON() {
4161
return this._data
4262
}

0 commit comments

Comments
 (0)