@voxgig/create-sdkgen 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/bin/run-create-sdkgen.js~ +1 -0
  2. package/package.json +3 -1
  3. package/tm/standard/.env.local +2 -0
  4. package/tm/standard/build/sdk.js +25 -0
  5. package/tm/standard/def/DEFINITION.md +2 -0
  6. package/tm/standard/model/.model-config/model-config.jsonic +13 -0
  7. package/tm/standard/model/go.jsonic +6 -0
  8. package/tm/standard/model/js.jsonic +6 -0
  9. package/tm/standard/model/php.jsonic +6 -0
  10. package/tm/standard/model/py.jsonic +7 -0
  11. package/tm/standard/model/rb.jsonic +6 -0
  12. package/tm/standard/model/sdk.jsonic.off +60 -0
  13. package/tm/standard/package.json +30 -0
  14. package/tm/standard/src/Root.ts +60 -0
  15. package/tm/standard/src/go/Entity_go.ts +226 -0
  16. package/tm/standard/src/go/MainEntity_go.ts +26 -0
  17. package/tm/standard/src/go/Main_go.ts +168 -0
  18. package/tm/standard/src/go/Quick_go.ts +108 -0
  19. package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
  20. package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
  21. package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
  22. package/tm/standard/src/go/TestAccept_go.ts +38 -0
  23. package/tm/standard/src/go/TestEntity_go.ts +79 -0
  24. package/tm/standard/src/go/TestMain_go.ts +61 -0
  25. package/tm/standard/src/go/Test_go.ts +20 -0
  26. package/tm/standard/src/js/Entity_js.ts +135 -0
  27. package/tm/standard/src/js/MainEntity_js.ts +22 -0
  28. package/tm/standard/src/js/Main_js.ts +128 -0
  29. package/tm/standard/src/js/Quick_js.ts +72 -0
  30. package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
  31. package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
  32. package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
  33. package/tm/standard/src/js/TestAccept_js.ts +60 -0
  34. package/tm/standard/src/js/TestEntity_js.ts +24 -0
  35. package/tm/standard/src/js/TestMain_js.ts +123 -0
  36. package/tm/standard/src/js/Test_js.ts +24 -0
  37. package/tm/standard/src/php/Entity_php.ts +97 -0
  38. package/tm/standard/src/php/MainEntity_php.ts +43 -0
  39. package/tm/standard/src/php/Main_php.ts +50 -0
  40. package/tm/standard/src/php/Quick_php.ts +59 -0
  41. package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
  42. package/tm/standard/src/php/TestAccept_php.ts +33 -0
  43. package/tm/standard/src/php/TestEntity_php.ts +64 -0
  44. package/tm/standard/src/php/TestMain_php.ts +120 -0
  45. package/tm/standard/src/php/Test_php.ts +21 -0
  46. package/tm/standard/src/py/Entity_py.ts +98 -0
  47. package/tm/standard/src/py/MainEntity_py.ts +19 -0
  48. package/tm/standard/src/py/Main_py.ts +211 -0
  49. package/tm/standard/src/py/Quick_py.ts +133 -0
  50. package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
  51. package/tm/standard/src/py/TestAccept_py.ts +77 -0
  52. package/tm/standard/src/py/TestEntity_py.ts +50 -0
  53. package/tm/standard/src/py/TestMain_py.ts +103 -0
  54. package/tm/standard/src/py/Test_py.ts +28 -0
  55. package/tm/standard/src/rb/Client_rb.ts +142 -0
  56. package/tm/standard/src/rb/Entity_rb.ts +153 -0
  57. package/tm/standard/src/rb/Error_rb.ts +56 -0
  58. package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
  59. package/tm/standard/src/rb/Main_rb.ts +55 -0
  60. package/tm/standard/src/rb/Quick_rb.ts +65 -0
  61. package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
  62. package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
  63. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
  64. package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
  65. package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
  66. package/tm/standard/src/rb/TestMain_rb.ts +67 -0
  67. package/tm/standard/src/rb/Test_rb.ts +27 -0
  68. package/tm/standard/src/tsconfig.json +15 -0
  69. package/tm/standard/tm/go/.env.example +2 -0
  70. package/tm/standard/tm/go/LICENSE +22 -0
  71. package/tm/standard/tm/go/go.mod +5 -0
  72. package/tm/standard/tm/go/go.sum +2 -0
  73. package/tm/standard/tm/js/LICENSE +22 -0
  74. package/tm/standard/tm/js/package.json +17 -0
  75. package/tm/standard/tm/php/LICENSE +22 -0
  76. package/tm/standard/tm/py/LICENSE +22 -0
  77. package/tm/standard/tm/py/MANIFEST.in +4 -0
  78. package/tm/standard/tm/py/Makefile +14 -0
  79. package/tm/standard/tm/py/pyproject.toml +4 -0
  80. package/tm/standard/tm/py/pytest.ini +3 -0
  81. package/tm/standard/tm/py/requirements.txt +4 -0
  82. package/tm/standard/tm/py/setup.cfg +2 -0
  83. package/tm/standard/tm/py/setup.py +82 -0
  84. package/tm/standard/tm/rb/.rspec +1 -0
  85. package/tm/standard/tm/rb/Gemfile +21 -0
  86. package/tm/standard/tm/rb/LICENSE +22 -0
  87. package/tm/standard/tm/rb/Rakefile +6 -0
  88. package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
  89. package/tm/standard/tm/rb/tm.gemspec +39 -0
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/create-sdkgen",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "dist/create-sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/create-sdkgen.d.ts",
@@ -34,6 +34,8 @@
34
34
  "files": [
35
35
  "src",
36
36
  "dist",
37
+ "bin",
38
+ "tm",
37
39
  "LICENSE"
38
40
  ],
39
41
  "devDependencies": {
@@ -0,0 +1,2 @@
1
+ $$NAME$$_ENDPOINT=https://api.example.com
2
+ $$NAME$$_APIKEY=apikey
@@ -0,0 +1,25 @@
1
+
2
+ const { SdkGen } = require('@voxgig/sdkgen')
3
+ const { Root } = require('../dist/Root')
4
+
5
+
6
+ try {
7
+ const config = {
8
+ folder: __dirname+'/../sdk',
9
+ def: __dirname+'/../def/$$def.filename$$',
10
+ meta: {
11
+ name: '$$name$$'
12
+ },
13
+ model: {
14
+ folder: __dirname+'/../model',
15
+
16
+ entity: {}
17
+ },
18
+ }
19
+
20
+ module.exports = SdkGen.makeBuild(Root, config)
21
+
22
+ }
23
+ catch(e) {
24
+ console.log('SDK ERROR', e)
25
+ }
@@ -0,0 +1,2 @@
1
+ # API Definition
2
+ API definition (OpenAPI etc) files live here.
@@ -0,0 +1,13 @@
1
+
2
+
3
+ @'@voxgig/model/model/.model-config/model-config.jsonic'
4
+
5
+ sys: model: builders: {
6
+ sdk: load: 'build/sdk.js'
7
+ }
8
+
9
+ sys: model: watch: {
10
+ 'build': {}
11
+ 'dist': {}
12
+ 'tm': {}
13
+ }
@@ -0,0 +1,6 @@
1
+
2
+ title: Go
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: JavaScript
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: PHP
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,7 @@
1
+ title: Python
2
+
3
+ extension: py
4
+
5
+ module: name: '$ModuleName'
6
+
7
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: Ruby
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,60 @@
1
+
2
+ name: '$$name$$'
3
+
4
+ @"api.jsonic"
5
+ @"def.jsonic"
6
+
7
+ main: sdk: build: &: { name: .$KEY }
8
+
9
+ main: sdk: build: js: @"js.jsonic"
10
+
11
+ main: sdk: build: rb: @"rb.jsonic"
12
+
13
+ main: sdk: build: py: @"py.jsonic"
14
+
15
+ main: sdk: build: php: @"php.jsonic"
16
+
17
+ main: sdk: build: go: @"go.jsonic"
18
+
19
+
20
+
21
+ main: sdk: test: quick: entity: name: $$test.quick.entity.name$$
22
+
23
+
24
+ main: sdk: entity: $.main.api.entity
25
+
26
+
27
+ main: sdk: entity: &: {
28
+ name: .$KEY
29
+ publish: *true | boolean
30
+ }
31
+
32
+
33
+
34
+ main: sdk: options: &: {
35
+ name: .$KEY
36
+ publish: *true | boolean
37
+ }
38
+
39
+
40
+ main: sdk: options: {
41
+
42
+ endpoint: {
43
+ kind: *String | string
44
+ short: "$$Name$$ API URL"
45
+ }
46
+
47
+ apikey: {
48
+ kind: *String | string
49
+ short: "$$Name$$ API Key"
50
+ }
51
+
52
+ fetch: {
53
+ kind: *Any | string
54
+ publish: false
55
+ }
56
+ }
57
+
58
+
59
+
60
+
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "build-$$name$$-sdk",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "QQQindex.js",
6
+ "scripts": {
7
+ "model": "voxgig-model model/sdk.jsonic",
8
+ "watch": "tsc --build src -w",
9
+ "build": "tsc --build src",
10
+ "test": "echo no-test",
11
+ "clean": "rm -rf node_modules yarn.lock package-lock.json",
12
+ "reset": "npm run clean && npm i && npm run build && npm test",
13
+ "mock-server": "prism mock def/$DefinitionFile"
14
+ },
15
+ "author": "",
16
+ "license": "MIT",
17
+ "overrides": {
18
+ "@stoplight/prism-cli": {
19
+ "@stoplight/json": "3.21.0"
20
+ }
21
+ },
22
+ "devDependencies": {
23
+ "@voxgig/model": "^3.2.0",
24
+ "@voxgig/sdkgen": "^0.6.0",
25
+ "@voxgig/util": "^0.0.3",
26
+ "@types/node": "22.5.4",
27
+ "@stoplight/prism-cli": "^5.9.0",
28
+ "typescript": "^5.5.4"
29
+ }
30
+ }
@@ -0,0 +1,60 @@
1
+
2
+ import {
3
+ names,
4
+ cmp,
5
+ each,
6
+
7
+ Project,
8
+ Folder,
9
+
10
+ Main,
11
+ Entity,
12
+ Readme,
13
+
14
+ } from '@voxgig/sdkgen'
15
+
16
+ // import { Readme } from './Readme'
17
+ // import { Main } from './Main'
18
+ // import { Entity } from './Entity'
19
+
20
+
21
+ const Root = cmp(function Root(props: any) {
22
+ const { model, ctx$ } = props
23
+
24
+ names(model, model.name)
25
+
26
+ // console.dir(model, { depth: null })
27
+
28
+ ctx$.model = model
29
+
30
+ const build = model.main.sdk.build
31
+ const entity = model.main.sdk.entity
32
+
33
+ Project({}, () => {
34
+
35
+ each(build, (build: any) => {
36
+ names(build, build.name)
37
+ // console.log('BUILD', build.name)
38
+
39
+ Folder({ name: build.name }, () => {
40
+
41
+ each(entity, (entity: any) => {
42
+ names(entity, entity.name)
43
+ // console.log('ENTITY', entity.name)
44
+
45
+ Entity({ build, entity })
46
+ })
47
+
48
+ Main({ build })
49
+
50
+ Readme({ build })
51
+ })
52
+ })
53
+ })
54
+ })
55
+
56
+
57
+ export {
58
+ Root
59
+ }
60
+
@@ -0,0 +1,226 @@
1
+
2
+ import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const Entity = cmp(function Entity(props: any) {
6
+ const { build, entity } = props
7
+ const { model } = props.ctx$
8
+
9
+ File({ name: entity.name + '.' + build.name }, () => {
10
+ const complexTypeMap: Record<string, string> = {
11
+ "custom": "map[string]any",
12
+ "xval": "float64",
13
+ "yval": "float64",
14
+ "zval": "float64",
15
+ "xlen": "int",
16
+ "ylen": "int",
17
+ "parent_xlen": "int",
18
+ "parent_xval": "float64",
19
+ "parent_xyangle": "float64",
20
+ "parent_ylen": "int",
21
+ "parent_yval": "float64",
22
+ "parent_zval": "float64",
23
+ "polygon": "struct{Points [][]float64}",
24
+ }
25
+
26
+ const defaultTypeMap: Record<string, string> = {
27
+ "boolean": "bool",
28
+ "string": "string"
29
+ }
30
+
31
+ Content(`
32
+ // ${model.Name} ${build.Name} ${entity.Name}
33
+
34
+ package ${model.name}sdk
35
+
36
+ import (
37
+ "fmt"
38
+ "encoding/json"
39
+ "io"
40
+ "errors"
41
+ "net/http"
42
+ )
43
+
44
+ type ${entity.Name}Data struct {`)
45
+ each(entity.field, (field: any) => {
46
+ const type = complexTypeMap[field.name] ? complexTypeMap[field.name]
47
+ : defaultTypeMap[field.type]
48
+ Content(`
49
+ ${field.Name} ${type} \`json:"${field.name}"\`
50
+ `)
51
+ })
52
+ Content(`
53
+ }
54
+
55
+ type ${entity.Name} struct {
56
+ Data ${entity.Name}Data
57
+ def map[string]any
58
+ sdk func () *${model.name}
59
+ }
60
+
61
+ func (e *${entity.Name}) reqSetup(op string, data ${entity.Name}Data) (*http.Request, error) {
62
+ e.Data = data
63
+
64
+ endpointConfig := endpointConfig{
65
+ op: op,
66
+ id: e.Data.Id,
67
+ name: e.def["name"].(string),
68
+ apiUrl: e.sdk().options.Endpoint,
69
+ }
70
+
71
+ fetchConfig := fetchConfig{
72
+ op: op,
73
+ url: endpoint(endpointConfig),
74
+ apikey: e.sdk().options.Apikey,
75
+ }
76
+
77
+ spec, err := fetchSpec(fetchConfig, e.Data)
78
+ if err != nil {
79
+ return nil, err
80
+ }
81
+
82
+ req, err := http.NewRequest(spec.method, spec.url, spec.body)
83
+ if err != nil {
84
+ return nil, err
85
+ }
86
+
87
+ req.Header.Set("Content-Type", spec.contentType)
88
+ req.Header.Set("Authorization", spec.authorization)
89
+
90
+ return req, nil
91
+ }
92
+
93
+ func (e *${entity.Name}) handleResult(op string, res *http.Response,
94
+ handler func(${entity.Name}Data) *${entity.Name}) (*${entity.Name}, error) {
95
+ var result ${entity.Name}Data
96
+ status := res.StatusContent
97
+
98
+ if status == 200 {
99
+ resBody, err := io.ReadAll(res.Body)
100
+ if err != nil {
101
+ return nil, err
102
+ }
103
+
104
+ if err = json.Unmarshal(resBody, &result); err != nil {
105
+ return nil, err
106
+ }
107
+ return handler(result), nil
108
+ }
109
+
110
+ return nil, errors.New(fmt.Sprintf("HTTP-ERROR: %v: ${entity.name}: %v",
111
+ op, status))
112
+ }
113
+
114
+ `)
115
+ each(entity.op, (op: any) => {
116
+ if (op.name == "list") {
117
+ Content(`
118
+ func (e *${entity.Name}) ${op.Name}() ([]*${entity.Name}, error) {
119
+ type entity${op.Name} struct {
120
+ ${op.Name} []${entity.Name}Data
121
+ }
122
+
123
+ op := "${op.name}"
124
+ var entities []*${entity.Name}
125
+
126
+ endpointConfig := endpointConfig{
127
+ op: op,
128
+ id: e.Data.Id,
129
+ name: e.def["name"].(string),
130
+ apiUrl: e.sdk().options.Endpoint,
131
+ }
132
+
133
+ fetchConfig := fetchConfig{
134
+ op: op,
135
+ url: endpoint(endpointConfig),
136
+ apikey: e.sdk().options.Apikey,
137
+ }
138
+
139
+ spec, err := fetchSpec(fetchConfig, e.Data)
140
+ if err != nil {
141
+ return nil, err
142
+ }
143
+
144
+ req, err := http.NewRequest(spec.method, spec.url, spec.body)
145
+ if err != nil {
146
+ return nil, err
147
+ }
148
+
149
+ req.Header.Set("Content-Type", spec.contentType)
150
+ req.Header.Set("Authorization", spec.authorization)
151
+
152
+ res, err := e.sdk().httpClient.Do(req)
153
+ if err != nil {
154
+ return nil, err
155
+ }
156
+ defer res.Body.Close()
157
+
158
+ status := res.StatusContent
159
+
160
+ if status == 200 {
161
+ resBody, err := io.ReadAll(res.Body)
162
+ if err != nil {
163
+ return nil, err
164
+ }
165
+
166
+ var entity${op.Name} entity${op.Name}
167
+ if err = json.Unmarshal(resBody, &entity${op.Name}); err != nil {
168
+ return nil, err
169
+ }
170
+
171
+ for _, entityData := range entity${op.Name}.${op.Name} {
172
+ entity := e.sdk().${entity.Name}(entityData)
173
+ entities = append(entities, entity)
174
+ }
175
+
176
+ return entities, nil
177
+ }
178
+
179
+ return nil, errors.New(fmt.Sprintf("HTTP-ERROR: %v: ${entity.name}: %v",
180
+ op, status))
181
+ }
182
+ `)
183
+ return
184
+ }
185
+ Content(`
186
+ func (e *${entity.Name}) ${op.Name}(data ${entity.Name}Data) (*${entity.Name}, error) {
187
+ op := "${op.name}"
188
+
189
+ req, err := e.reqSetup(op, data)
190
+ if err != nil {
191
+ return nil, err
192
+ }
193
+
194
+ res, err := e.sdk().httpClient.Do(req)
195
+ if err != nil {
196
+ return nil, err
197
+ }
198
+ defer res.Body.Close()
199
+
200
+ handler := func(data ${entity.Name}Data) *${entity.Name} {
201
+ e.Data = data
202
+ `)
203
+ if (op.name == "remove") {
204
+ Content(`
205
+ return nil
206
+ }
207
+ return e.handleResult(op, res, handler)
208
+ }
209
+ `)
210
+ return
211
+ }
212
+ Content(`
213
+ return e
214
+ }
215
+
216
+ return e.handleResult(op, res, handler)
217
+ }
218
+ `)
219
+ });
220
+ })
221
+ })
222
+
223
+
224
+ export {
225
+ Entity
226
+ }
@@ -0,0 +1,26 @@
1
+
2
+ import { cmp, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const MainEntity = cmp(async function MainEntity(props: any) {
6
+ const { model, entity } = props
7
+
8
+ Content(`
9
+ func (m *${model.name}) ${entity.Name}(data ...${entity.Name}Data) *${entity.Name} {
10
+ e := new (${entity.Name})
11
+ e.sdk = func () *${model.name} {return m}
12
+ if data != nil {
13
+ e.Data = data[0]
14
+ }
15
+ e.def = map[string]any{
16
+ "name": "${entity.name}",
17
+ }
18
+ return e
19
+ }
20
+ `)
21
+ })
22
+
23
+
24
+ export {
25
+ MainEntity
26
+ }
@@ -0,0 +1,168 @@
1
+
2
+ import { cmp, each, camelify, File, Content, Copy } from '@voxgig/sdkgen'
3
+
4
+ import { MainEntity } from './MainEntity_go'
5
+ import { Test } from './Test_go'
6
+
7
+
8
+ const Main = cmp(async function Main(props: any) {
9
+ const { build } = props
10
+ const { model } = props.ctx$
11
+
12
+ const entity = model.main.sdk.entity
13
+ const options = build.options
14
+
15
+ Copy({ from: 'tm/' + build.name + '/.env.example', name: '.env.example' })
16
+ Copy({ from: 'tm/' + build.name + '/go.mod', name: 'go.mod' })
17
+ Copy({ from: 'tm/' + build.name + '/go.sum', name: 'go.sum' })
18
+ Test({ build })
19
+ File({ name: model.name + 'sdk.' + build.name }, () => {
20
+
21
+ Content(`
22
+ // ${model.Name} ${build.Name} SDK
23
+
24
+ package ${model.name}sdk
25
+
26
+ import(
27
+ "bytes"
28
+ "encoding/json"
29
+ "fmt"
30
+ "net/http"
31
+ "errors"
32
+ "reflect"
33
+ )
34
+
35
+ type endpointConfig struct {
36
+ op string
37
+ id string
38
+ name string
39
+ apiUrl string
40
+ }
41
+
42
+ type fetchConfig struct {
43
+ op string
44
+ url string
45
+ apikey string
46
+ }
47
+
48
+ type spec struct {
49
+ body *bytes.Buffer
50
+ url string
51
+ method string
52
+ contentType string
53
+ authorization string
54
+ }
55
+
56
+ type Options struct {`)
57
+ each(options, (option: any) => {
58
+ if (option.kind != "Any") {
59
+ Content(`
60
+ ${camelify(option.name)} ${option.kind.toLowerCase()}
61
+ `)
62
+ }
63
+ }); Content(`
64
+ }
65
+
66
+ type ${model.name} struct {
67
+ httpClient http.Client
68
+ options Options
69
+ }
70
+
71
+ func method(op string) string {
72
+ operations := map[string]string {
73
+ "create": "POST",
74
+ "save": "PUT",
75
+ "load": "GET",
76
+ "list": "GET",
77
+ "remove": "DELETE",
78
+ }
79
+
80
+ return operations[op]
81
+ }
82
+
83
+ func endpoint(config endpointConfig) string {
84
+ url := fmt.Sprintf("%v/%v", config.apiUrl, config.name)
85
+
86
+ if config.op == "load" || config.op == "remove" {
87
+ url += fmt.Sprintf("/%v", config.id)
88
+ }
89
+
90
+ return url
91
+ }
92
+
93
+ func body[T any](data T) ([]byte, error) {
94
+ var msg []byte
95
+ msg, err := json.Marshal(data)
96
+ if err != nil {
97
+ return nil, err
98
+ }
99
+ return msg, nil
100
+ }
101
+
102
+ func fetchSpec[T any](config fetchConfig, data T) (spec, error){
103
+ method := method(config.op)
104
+ buffBody := bytes.NewBuffer([]byte{})
105
+
106
+ if method != "GET" && method != "DELETE" {
107
+ parsedBody, err := body(data)
108
+ if err != nil {
109
+ return spec{}, err
110
+ }
111
+ buffBody = bytes.NewBuffer(parsedBody)
112
+ }
113
+
114
+ spec := spec{
115
+ url: config.url,
116
+ method: method,
117
+ contentType: "application/json",
118
+ authorization: fmt.Sprintf("Bearer %v", config.apikey),
119
+ body: buffBody,
120
+ }
121
+ return spec, nil
122
+ }
123
+
124
+ `)
125
+
126
+ each(entity, (entity: any) => {
127
+ MainEntity({ model, build, entity })
128
+ })
129
+
130
+ Content(`
131
+ func validateOptions(options Options) error {
132
+ e := reflect.ValueOf(&options).Elem()
133
+
134
+ for i := 0; i < e.NumField(); i++ {
135
+ field := e.Field(i)
136
+ fieldName := e.Type().Field(i).Name
137
+ fieldValue := field.Interface()
138
+
139
+ if field.IsZero() {
140
+ return errors.New(fmt.Sprintf("${model.Name}SDK: Invalid options: opt: %v value: %v",
141
+ fieldName, fieldValue))
142
+ }
143
+ }
144
+ return nil
145
+ }
146
+
147
+ func new${model.Name}SDK(options Options) (*${model.name}, error) {
148
+ sdk := new(${model.name})
149
+ sdk.options = options
150
+ sdk.httpClient = *http.DefaultClient
151
+ return sdk, nil
152
+ }
153
+
154
+ func Make(options Options) (*${model.name}, error) {
155
+ err := validateOptions(options)
156
+ if err != nil {
157
+ return nil, err
158
+ }
159
+ return new${model.Name}SDK(options)
160
+ }
161
+ `)
162
+ })
163
+ })
164
+
165
+
166
+ export {
167
+ Main
168
+ }