goa_model_gen 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/goa_model_gen/cli.rb +4 -1
- data/lib/goa_model_gen/templates/converter.go.erb +34 -2
- data/lib/goa_model_gen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35b0d93af5777f1460e792e2b1aafb7553d0bd054558a411668687d825de5e9d
|
4
|
+
data.tar.gz: 8b1ec15e0b26806474ca3005f9951529434f680e0e22b243c04d9d8467215d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b68b7d2d1488af468dc14a78ab150d22becfcacd852aa8ec87fbf6b40b107bcaa40688154205ff3a727a6d87a7536cb3f39ca492b612188782c7ac6debd780d6
|
7
|
+
data.tar.gz: bb0dcd08ac16663d0cb3f54dfee59ed5e52d3a0a4e75872fdf2f9665e573a774d2d70ffb2de6fabd117ac337bc1eb40e73735764ca3701aa5edce74c6540bff2
|
data/lib/goa_model_gen/cli.rb
CHANGED
@@ -88,9 +88,12 @@ module GoaModelGen
|
|
88
88
|
pt = (structs['payload'] || []).detect{|t| t["Name"] == "#{m.name}Payload" }
|
89
89
|
rt = (structs['result'] || []).detect{|t| t["Name"] == m.name }
|
90
90
|
variables = {
|
91
|
+
models: (structs['model'] || []),
|
92
|
+
payloads: (structs['payload'] || []),
|
93
|
+
results: (structs['result'] || []),
|
91
94
|
model: m,
|
92
95
|
payload: pt ? GoStruct.new(pt) : nil,
|
93
|
-
result: rt ? GoStruct.new(rt) : nil
|
96
|
+
result: rt ? GoStruct.new(rt) : nil,
|
94
97
|
}
|
95
98
|
new_generator.run('templates/converter.go.erb', File.join(cfg.converter_dir, m.name.underscore, "conv.go"), variables)
|
96
99
|
end
|
@@ -6,13 +6,16 @@ def method_calling_exp(m, argument)
|
|
6
6
|
"#{m}(#{argument})"
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
gen_package = "#{config.go_package}/gen/#{model.name.underscore}"
|
11
|
+
|
9
12
|
-%>
|
10
13
|
<%- package model.name.underscore -%>
|
11
14
|
|
12
15
|
<%- if payload-%>
|
13
16
|
<%-
|
14
17
|
import "#{config.go_package}/converters"
|
15
|
-
import :gen,
|
18
|
+
import :gen, gen_package
|
16
19
|
import "#{config.go_package}/model"
|
17
20
|
-%>
|
18
21
|
func <%= model.name %>PayloadToModel(payload *gen.<%= payload.name %>) (*model.<%= model.name %>, error) {
|
@@ -80,9 +83,36 @@ func CopyFrom<%= model.name %>PayloadToModel(payload *gen.<%= payload.name %>, m
|
|
80
83
|
<%- if result -%>
|
81
84
|
<%-
|
82
85
|
import "#{config.go_package}/converters"
|
83
|
-
import :gen,
|
86
|
+
import :gen, gen_package
|
84
87
|
import "#{config.go_package}/model"
|
88
|
+
|
89
|
+
indirect_types =
|
90
|
+
result.fields.map{|rf| rf.type.pkg_path == gen_package ? rf.type : nil }.
|
91
|
+
compact.uniq{|rft| "#{rft.pkg_path}.#{rft.name}" }
|
92
|
+
indirect_type_names = indirect_types.map(&:name)
|
93
|
+
|
94
|
+
indirect_types.each do |rft|
|
95
|
+
mt_hash = models.detect{|t| t['Name'] == rft.name} || raise("model not found for #{rft.name}")
|
96
|
+
rt_hash = results.detect{|rt| (rt['PkgPath'] == gen_package) && (rt['Name'] == rft.name)} || raise("#{gen_package}.#{rft.name} not found in structs")
|
97
|
+
mt = GoStruct.new(mt_hash)
|
98
|
+
rt = GoStruct.new(rt_hash)
|
85
99
|
-%>
|
100
|
+
func <%= rt.name %>ModelToResult(m *model.<%= rt.name %>) *gen.<%= rt.name %> {
|
101
|
+
return &gen.<%= rt.name %> {
|
102
|
+
<%-
|
103
|
+
rt.fields.each do |rf|
|
104
|
+
mf = mt.fields.detect{|f| f.name == rf.name}
|
105
|
+
if mf && mf.type.assignable_with?(rf.type)
|
106
|
+
-%>
|
107
|
+
<%= rf.name %>: m.<%= mf.name %>,
|
108
|
+
<%-
|
109
|
+
end
|
110
|
+
end
|
111
|
+
-%>
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
<%- end -%>
|
86
116
|
func <%= model.name %>ModelToResult(m *model.<%= model.name %>) (*gen.<%= result.name %>, error) {
|
87
117
|
if m == nil {
|
88
118
|
return nil, converters.NoModelGiven
|
@@ -103,6 +133,8 @@ func <%= model.name %>ModelToResult(m *model.<%= model.name %>) (*gen.<%= result
|
|
103
133
|
r.<%= rf.name %> = m.<%= mf.name %>
|
104
134
|
<%- elsif rf.type.pointer_of?(mf.type) -%>
|
105
135
|
r.<%= rf.name %> = &m.<%= mf.name %>
|
136
|
+
<%- elsif indirect_type_names.include?(rf.type.name) -%>
|
137
|
+
r.<%= rf.name %> = <%= rf.type.name %>ModelToResult(&m.<%= mf.name %>)
|
106
138
|
<%- elsif !mf.type.needs_error_to_convert_to?(rf.type) -%>
|
107
139
|
r.<%= rf.name %> = <%= conv_pkg %>.<%= mf.type.method_part_name %>To<%= rf.type.method_part_name %>(m.<%= mf.name %>)
|
108
140
|
<%- else -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goa_model_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|