massimo-cli 1.5.0 → 1.5.1
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/lib/frontend-openapi-generator.js +16 -1
- package/lib/get-type.js +12 -7
- package/package.json +7 -7
|
@@ -68,6 +68,7 @@ function generateFrontendImplementationFromOpenAPI ({
|
|
|
68
68
|
useTabs: false,
|
|
69
69
|
useSingleQuote: true
|
|
70
70
|
})
|
|
71
|
+
const hasPathParameters = operations.some(operation => operation.path.includes('{'))
|
|
71
72
|
|
|
72
73
|
writer.write('// This client was generated by Platformatic from an OpenAPI specification.')
|
|
73
74
|
writer.blankLine()
|
|
@@ -132,6 +133,18 @@ function generateFrontendImplementationFromOpenAPI ({
|
|
|
132
133
|
writer.writeLine('return output')
|
|
133
134
|
})
|
|
134
135
|
}
|
|
136
|
+
if (hasPathParameters) {
|
|
137
|
+
writer.newLine()
|
|
138
|
+
writer
|
|
139
|
+
.write(`function encodePathParameter(value${isTsLang ? ': unknown' : ''})${isTsLang ? ': string' : ''} `)
|
|
140
|
+
.block(() => {
|
|
141
|
+
writer.writeLine(`const encoded = encodeURIComponent(value${isTsLang ? ' as string' : ''})`)
|
|
142
|
+
writer.write('if (encoded === \'.\' || encoded === \'..\') ').block(() => {
|
|
143
|
+
writer.writeLine('throw new Error(\'Path parameters cannot be "." or ".."\')')
|
|
144
|
+
})
|
|
145
|
+
writer.writeLine('return encoded')
|
|
146
|
+
})
|
|
147
|
+
}
|
|
135
148
|
writer.blankLine()
|
|
136
149
|
const allOperations = []
|
|
137
150
|
const originalFullResponse = fullResponse
|
|
@@ -192,7 +205,9 @@ function generateFrontendImplementationFromOpenAPI ({
|
|
|
192
205
|
// /organizations/{orgId}/members/{memberId}
|
|
193
206
|
// to
|
|
194
207
|
// /organizations/${request.orgId}/members/${request.memberId}
|
|
195
|
-
const stringLiteralPath = path
|
|
208
|
+
const stringLiteralPath = path
|
|
209
|
+
.replace(/\{/gm, '${encodePathParameter(' + req + "['")
|
|
210
|
+
.replace(/\}/gm, "'])}")
|
|
196
211
|
// GET methods need query strings instead of JSON bodies
|
|
197
212
|
if (queryParams.length) {
|
|
198
213
|
// query parameters should be appended to the url
|
package/lib/get-type.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import jsonpointer from 'jsonpointer'
|
|
2
2
|
|
|
3
|
-
export function getType (typeDef, methodType, spec) {
|
|
3
|
+
export function getType (typeDef, methodType, spec, seenRefs = new Set()) {
|
|
4
4
|
if (typeDef.$ref) {
|
|
5
|
+
if (seenRefs.has(typeDef.$ref)) {
|
|
6
|
+
return 'unknown'
|
|
7
|
+
}
|
|
8
|
+
seenRefs = new Set(seenRefs)
|
|
9
|
+
seenRefs.add(typeDef.$ref)
|
|
5
10
|
typeDef = jsonpointer.get(spec, typeDef.$ref.replace('#', ''))
|
|
6
11
|
}
|
|
7
12
|
if (typeDef.schema) {
|
|
8
|
-
return getType(typeDef.schema, methodType, spec)
|
|
13
|
+
return getType(typeDef.schema, methodType, spec, seenRefs)
|
|
9
14
|
}
|
|
10
15
|
if (typeDef.anyOf) {
|
|
11
16
|
// recursively call this function
|
|
12
17
|
const mapped = typeDef.anyOf.map(t => {
|
|
13
|
-
return getType(t, methodType, spec)
|
|
18
|
+
return getType(t, methodType, spec, seenRefs)
|
|
14
19
|
})
|
|
15
20
|
return mapped.join(' | ')
|
|
16
21
|
}
|
|
@@ -18,7 +23,7 @@ export function getType (typeDef, methodType, spec) {
|
|
|
18
23
|
if (typeDef.oneOf) {
|
|
19
24
|
// recursively call this function
|
|
20
25
|
const mapped = typeDef.oneOf.map(t => {
|
|
21
|
-
return getType(t, methodType, spec)
|
|
26
|
+
return getType(t, methodType, spec, seenRefs)
|
|
22
27
|
})
|
|
23
28
|
|
|
24
29
|
if (typeDef.discriminator && typeDef.discriminator.propertyName) {
|
|
@@ -56,13 +61,13 @@ export function getType (typeDef, methodType, spec) {
|
|
|
56
61
|
// recursively call this function
|
|
57
62
|
return typeDef.allOf
|
|
58
63
|
.map(t => {
|
|
59
|
-
return getType(t, methodType, spec)
|
|
64
|
+
return getType(t, methodType, spec, seenRefs)
|
|
60
65
|
})
|
|
61
66
|
.join(' & ')
|
|
62
67
|
}
|
|
63
68
|
if (typeDef.type === 'array') {
|
|
64
69
|
const nullable = typeDef.nullable
|
|
65
|
-
return `Array<${getType(typeDef.items, methodType, spec)}>${nullable === true ? ' | null' : ''}`
|
|
70
|
+
return `Array<${getType(typeDef.items, methodType, spec, seenRefs)}>${nullable === true ? ' | null' : ''}`
|
|
66
71
|
}
|
|
67
72
|
if (typeDef.enum) {
|
|
68
73
|
// Note: null type represented with an enum have no types and single enum element 'null'
|
|
@@ -107,7 +112,7 @@ export function getType (typeDef, methodType, spec) {
|
|
|
107
112
|
if (additionalPropsRequired) {
|
|
108
113
|
required = required || !!additionalPropsRequired.includes(prop)
|
|
109
114
|
}
|
|
110
|
-
return `'${prop}'${required ? '' : '?'}: ${getType(objProperties[prop], methodType, spec)}`
|
|
115
|
+
return `'${prop}'${required ? '' : '?'}: ${getType(objProperties[prop], methodType, spec, seenRefs)}`
|
|
111
116
|
})
|
|
112
117
|
if (additionalProps === true) {
|
|
113
118
|
props.push('[key: string]: unknown')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massimo-cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A client for HTTP services.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"graphql": "^16.8.1",
|
|
26
26
|
"help-me": "^5.0.0",
|
|
27
27
|
"jsonpointer": "^5.0.1",
|
|
28
|
-
"massimo": "1.5.
|
|
28
|
+
"massimo": "1.5.1",
|
|
29
29
|
"minimist": "^1.2.8",
|
|
30
30
|
"pino": "^9.9.0",
|
|
31
31
|
"pino-pretty": "^13.0.0",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"yaml": "^2.4.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@platformatic/composer": "3.
|
|
36
|
+
"@platformatic/composer": "3.68.0",
|
|
37
37
|
"@platformatic/db": "3.67.0",
|
|
38
|
-
"@platformatic/foundation": "3.
|
|
39
|
-
"@platformatic/runtime": "3.
|
|
38
|
+
"@platformatic/foundation": "3.68.0",
|
|
39
|
+
"@platformatic/runtime": "3.68.0",
|
|
40
40
|
"@platformatic/service": "3.67.0",
|
|
41
|
-
"@platformatic/sql-graphql": "3.
|
|
42
|
-
"@platformatic/sql-mapper": "3.
|
|
41
|
+
"@platformatic/sql-graphql": "3.68.0",
|
|
42
|
+
"@platformatic/sql-mapper": "3.68.0",
|
|
43
43
|
"@playwright/test": "^1.42.1",
|
|
44
44
|
"@types/react": "^19.1.6",
|
|
45
45
|
"@types/react-dom": "^19.1.5",
|