@platformatic/sql-json-schema-mapper 0.20.0 → 0.21.0

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 CHANGED
@@ -16,7 +16,7 @@ function mapSQLTypeToOpenAPIType (sqlType) {
16
16
  case 'smallint':
17
17
  return 'integer'
18
18
  case 'decimal':
19
- return 'number'
19
+ return 'string'
20
20
  case 'bigint':
21
21
  return 'string'
22
22
  case 'int2':
@@ -42,7 +42,7 @@ function mapSQLTypeToOpenAPIType (sqlType) {
42
42
  case 'double precision':
43
43
  return 'number'
44
44
  case 'numeric':
45
- return 'number'
45
+ return 'string'
46
46
  case 'bigint unsigned':
47
47
  return 'integer'
48
48
  case 'float4':
@@ -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 { type, nullable, items } = properties[name]
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.0",
3
+ "version": "0.21.0",
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.0"
21
+ "@platformatic/sql-mapper": "0.21.0"
22
22
  },
23
23
  "dependencies": {
24
24
  "code-block-writer": "^12.0.0",
@@ -91,7 +91,7 @@ test('simple db, simple rest API', async (t) => {
91
91
  t.same(pageJsonSchema.properties.id, { type: 'integer' })
92
92
  t.same(pageJsonSchema.properties.title, { type: 'string' })
93
93
  t.same(pageJsonSchema.properties.description, { type: 'string', nullable: true })
94
- t.same(pageJsonSchema.properties.section, { type: 'number', nullable: true })
94
+ t.same(pageJsonSchema.properties.section, { type: 'string', nullable: true })
95
95
  if (isMariaDB) {
96
96
  t.same(pageJsonSchema.properties.metadata, { type: 'string', nullable: true })
97
97
  } else {
@@ -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
+ })