@platformatic/sql-json-schema-mapper 0.20.0 → 0.20.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/index.js +4 -1
- package/package.json +2 -2
- package/test/types.test.js +22 -0
package/index.js
CHANGED
|
@@ -123,7 +123,8 @@ function mapOpenAPItoTypes (obj, opts = {}) {
|
|
|
123
123
|
|
|
124
124
|
function renderProperties (writer, addedProps, properties = {}, additionalProperties, required = []) {
|
|
125
125
|
for (const name of Object.keys(properties)) {
|
|
126
|
-
const
|
|
126
|
+
const localProperty = properties[name]
|
|
127
|
+
const { type, nullable, items } = localProperty
|
|
127
128
|
addedProps.add(name)
|
|
128
129
|
if (required.indexOf(name) !== -1) {
|
|
129
130
|
writer.write(property(null, name))
|
|
@@ -170,6 +171,8 @@ function renderProperties (writer, addedProps, properties = {}, additionalProper
|
|
|
170
171
|
const current = properties[name]
|
|
171
172
|
renderProperties(writer, addedProps, current.properties, current.additionalProperties, current.required)
|
|
172
173
|
})
|
|
174
|
+
} else if (type === 'string' && localProperty.enum) {
|
|
175
|
+
writer.write(localProperty.enum.sort().map((v) => `"${v}"`).join(' | '))
|
|
173
176
|
} else {
|
|
174
177
|
writer.write(JSONSchemaToTsType(type))
|
|
175
178
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-json-schema-mapper",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Map SQL entity to JSON schema",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"snazzy": "^9.0.0",
|
|
19
19
|
"standard": "^17.0.0",
|
|
20
20
|
"tap": "^16.3.4",
|
|
21
|
-
"@platformatic/sql-mapper": "0.20.
|
|
21
|
+
"@platformatic/sql-mapper": "0.20.1"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"code-block-writer": "^12.0.0",
|
package/test/types.test.js
CHANGED
|
@@ -187,3 +187,25 @@ referenceTest('objects in arrays', {
|
|
|
187
187
|
'title'
|
|
188
188
|
]
|
|
189
189
|
})
|
|
190
|
+
|
|
191
|
+
referenceTest('enums', {
|
|
192
|
+
id: 'Page',
|
|
193
|
+
title: 'Page',
|
|
194
|
+
description: 'A Page',
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: {
|
|
197
|
+
id: {
|
|
198
|
+
type: 'integer'
|
|
199
|
+
},
|
|
200
|
+
title: {
|
|
201
|
+
type: 'string'
|
|
202
|
+
},
|
|
203
|
+
color: {
|
|
204
|
+
type: 'string',
|
|
205
|
+
enum: ['amber', 'green', 'red']
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
required: [
|
|
209
|
+
'title'
|
|
210
|
+
]
|
|
211
|
+
})
|