@voxgig/apidef 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.
- package/dist/apidef.js +0 -13
- package/dist/apidef.js.map +1 -1
- package/package.json +2 -2
- package/src/apidef.ts +0 -16
package/dist/apidef.js
CHANGED
|
@@ -32,12 +32,9 @@ const jostraca_1 = require("jostraca");
|
|
|
32
32
|
function ApiDef(opts = {}) {
|
|
33
33
|
const fs = opts.fs || Fs;
|
|
34
34
|
async function watch(spec) {
|
|
35
|
-
console.log('APIDEF START', spec.def);
|
|
36
35
|
await generate(spec);
|
|
37
|
-
console.log('APIDEF START GEN', spec.def);
|
|
38
36
|
const fsw = new chokidar_1.FSWatcher();
|
|
39
37
|
fsw.on('change', (...args) => {
|
|
40
|
-
console.log('APIDEF CHANGE', args);
|
|
41
38
|
generate(spec);
|
|
42
39
|
});
|
|
43
40
|
fsw.add(spec.def);
|
|
@@ -79,10 +76,8 @@ function makeOpenAPITransform(spec, opts) {
|
|
|
79
76
|
return fieldMap;
|
|
80
77
|
}
|
|
81
78
|
return function OpenAPITransform(def, model) {
|
|
82
|
-
// console.log('DEF', def)
|
|
83
79
|
model.main.api.name = spec.meta.name;
|
|
84
80
|
(0, jostraca_1.each)(spec.entity, (entity) => {
|
|
85
|
-
// console.log('ENTITY', entity)
|
|
86
81
|
const entityModel = model.main.api.entity[entity.key$] = {
|
|
87
82
|
field: {},
|
|
88
83
|
cmd: {},
|
|
@@ -91,8 +86,6 @@ function makeOpenAPITransform(spec, opts) {
|
|
|
91
86
|
const firstParts = firstPath.split('/');
|
|
92
87
|
const entityPathPrefix = firstParts[0];
|
|
93
88
|
(0, jostraca_1.each)(entity.path, (path) => {
|
|
94
|
-
// console.log('PATH', entity.key$, entityPathPrefix, path.key$)
|
|
95
|
-
// console.dir(def.paths[path.key$], { depth: null })
|
|
96
89
|
const pathdef = def.paths[path.key$];
|
|
97
90
|
const parts = path.key$.split('/');
|
|
98
91
|
// TODO: use method prop in model!!!
|
|
@@ -106,17 +99,11 @@ function makeOpenAPITransform(spec, opts) {
|
|
|
106
99
|
properties = (0, jostraca_1.getx)(pathdef.get, 'parameters=null ^1 responses 200 content ' +
|
|
107
100
|
'application/json schema items properties');
|
|
108
101
|
}
|
|
109
|
-
// console.log('properties', properties)
|
|
110
|
-
// TODO: refactor to util function
|
|
111
|
-
// const field = each(properties)
|
|
112
|
-
// .reduce((a: any, p: any) => (a[p.key$] =
|
|
113
|
-
// { kind: camelify(p.type) }, a), {})
|
|
114
102
|
const field = extractFields(properties);
|
|
115
103
|
Object.assign(entityModel.field, field);
|
|
116
104
|
}
|
|
117
105
|
// Entity Commands
|
|
118
106
|
else if (pathdef.post) {
|
|
119
|
-
// console.log('CMD', parts, pathdef.post)
|
|
120
107
|
if (2 < parts.length && parts[0] === entityPathPrefix) {
|
|
121
108
|
const suffix = parts[parts.length - 1];
|
|
122
109
|
let param = (0, jostraca_1.getx)(pathdef.post, 'parameters?in=path') || [];
|
package/dist/apidef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;AAiKlD,wBAAM;AA/JR,4CAA6B;AAE7B,wDAAsE;AAEtE,uCAAoC;AAEpC,uCAA+C;AAU/C,SAAS,MAAM,CAAC,OAAsB,EAAE;IACtC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,CAAA;IAGxB,KAAK,UAAU,KAAK,CAAC,IAAS;QAC5B,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;QAEpB,MAAM,GAAG,GAAG,IAAI,oBAAS,EAAE,CAAA;QAE3B,GAAG,C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AE,CACrC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAA,mBAAQ,EAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;4BACvE,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE;yBAC7C,CAAA;oBACH,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/apidef",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/apidef.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/apidef.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"typescript": "^5.5.4"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@redocly/openapi-core": "^1.
|
|
46
|
+
"@redocly/openapi-core": "^1.21.0",
|
|
47
47
|
"chokidar": "^3.6.0",
|
|
48
48
|
"jostraca": "^0.2.0"
|
|
49
49
|
}
|
package/src/apidef.ts
CHANGED
|
@@ -21,14 +21,11 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
async function watch(spec: any) {
|
|
24
|
-
console.log('APIDEF START', spec.def)
|
|
25
24
|
await generate(spec)
|
|
26
|
-
console.log('APIDEF START GEN', spec.def)
|
|
27
25
|
|
|
28
26
|
const fsw = new FSWatcher()
|
|
29
27
|
|
|
30
28
|
fsw.on('change', (...args: any[]) => {
|
|
31
|
-
console.log('APIDEF CHANGE', args)
|
|
32
29
|
generate(spec)
|
|
33
30
|
})
|
|
34
31
|
|
|
@@ -94,13 +91,9 @@ function makeOpenAPITransform(spec: any, opts: any) {
|
|
|
94
91
|
|
|
95
92
|
|
|
96
93
|
return function OpenAPITransform(def: any, model: any) {
|
|
97
|
-
// console.log('DEF', def)
|
|
98
|
-
|
|
99
94
|
model.main.api.name = spec.meta.name
|
|
100
95
|
|
|
101
96
|
each(spec.entity, (entity: any) => {
|
|
102
|
-
// console.log('ENTITY', entity)
|
|
103
|
-
|
|
104
97
|
const entityModel: any = model.main.api.entity[entity.key$] = {
|
|
105
98
|
field: {},
|
|
106
99
|
cmd: {},
|
|
@@ -111,9 +104,6 @@ function makeOpenAPITransform(spec: any, opts: any) {
|
|
|
111
104
|
const entityPathPrefix = firstParts[0]
|
|
112
105
|
|
|
113
106
|
each(entity.path, (path: any) => {
|
|
114
|
-
// console.log('PATH', entity.key$, entityPathPrefix, path.key$)
|
|
115
|
-
|
|
116
|
-
// console.dir(def.paths[path.key$], { depth: null })
|
|
117
107
|
const pathdef = def.paths[path.key$]
|
|
118
108
|
|
|
119
109
|
const parts = path.key$.split('/')
|
|
@@ -131,19 +121,13 @@ function makeOpenAPITransform(spec: any, opts: any) {
|
|
|
131
121
|
properties = getx(pathdef.get, 'parameters=null ^1 responses 200 content ' +
|
|
132
122
|
'application/json schema items properties')
|
|
133
123
|
}
|
|
134
|
-
// console.log('properties', properties)
|
|
135
124
|
|
|
136
|
-
// TODO: refactor to util function
|
|
137
|
-
// const field = each(properties)
|
|
138
|
-
// .reduce((a: any, p: any) => (a[p.key$] =
|
|
139
|
-
// { kind: camelify(p.type) }, a), {})
|
|
140
125
|
const field = extractFields(properties)
|
|
141
126
|
Object.assign(entityModel.field, field)
|
|
142
127
|
}
|
|
143
128
|
|
|
144
129
|
// Entity Commands
|
|
145
130
|
else if (pathdef.post) {
|
|
146
|
-
// console.log('CMD', parts, pathdef.post)
|
|
147
131
|
|
|
148
132
|
if (2 < parts.length && parts[0] === entityPathPrefix) {
|
|
149
133
|
const suffix = parts[parts.length - 1]
|