@platformatic/sql-json-schema-mapper
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"0e430260-69b7-4ca8-85f2-59e8074eaab5":{"parent":"375cd919-4c7b-485d-b4d1-328984a29f7f","externalId":"test/simple.test.js","children":[]},"375cd919-4c7b-485d-b4d1-328984a29f7f":{"parent":null,"children":["0e430260-69b7-4ca8-85f2-59e8074eaab5"]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":["0e430260-69b7-4ca8-85f2-59e8074eaab5"]},"externalIds":{"test/simple.test.js":{"root":"0e430260-69b7-4ca8-85f2-59e8074eaab5","children":[]}}} | ||
{"processes":{"9d3ac57a-4999-48ee-aad7-ad4f69be52e8":{"parent":null,"children":["d742ed64-3762-424c-b671-a7c0db97cf10"]},"d742ed64-3762-424c-b671-a7c0db97cf10":{"parent":"9d3ac57a-4999-48ee-aad7-ad4f69be52e8","externalId":"test/simple.test.js","children":[]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-json-schema-mapper/index.js":["d742ed64-3762-424c-b671-a7c0db97cf10"]},"externalIds":{"test/simple.test.js":{"root":"d742ed64-3762-424c-b671-a7c0db97cf10","children":[]}}} |
10
index.js
@@ -63,3 +63,11 @@ 'use strict' | ||
const type = mapSQLTypeToOpenAPIType(field.sqlType) | ||
properties[field.camelcase] = { type } | ||
/* istanbul ignore next */ | ||
if (field.sqlType === 'json') { | ||
properties[field.camelcase] = { | ||
type: 'object', | ||
additionalProperties: true | ||
} | ||
} else { | ||
properties[field.camelcase] = { type } | ||
} | ||
if (field.isNullable) { | ||
@@ -66,0 +74,0 @@ properties[field.camelcase].nullable = true |
{ | ||
"name": "@platformatic/sql-json-schema-mapper", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Map SQL entity to JSON schema", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@platformatic/sql-mapper": "0.1.0", | ||
"@platformatic/sql-mapper": "0.2.0", | ||
"fastify": "^4.6.0", | ||
@@ -25,2 +25,3 @@ "snazzy": "^9.0.0", | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "standard | snazzy && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite", | ||
@@ -27,0 +28,0 @@ "test:postgresql": "DB=postgresql tap test/*.test.js", |
@@ -16,2 +16,3 @@ 'use strict' | ||
module.exports.isMysql = true | ||
module.exports.isMariaDB = true | ||
} else if (process.env.DB === 'mysql') { | ||
@@ -18,0 +19,0 @@ connInfo.connectionString = 'mysql://root@127.0.0.1/graph' |
@@ -6,3 +6,3 @@ 'use strict' | ||
const fastify = require('fastify') | ||
const { clear, connInfo, isSQLite } = require('./helper') | ||
const { clear, connInfo, isSQLite, isMariaDB } = require('./helper') | ||
const { mapSQLEntityToJSONSchema } = require('..') | ||
@@ -16,2 +16,3 @@ const { test } = t | ||
title VARCHAR(42) NOT NULL, | ||
metadata JSON, | ||
description TEXT | ||
@@ -23,2 +24,3 @@ );`) | ||
title VARCHAR(42) NOT NULL, | ||
metadata JSON, | ||
description TEXT | ||
@@ -57,4 +59,9 @@ );`) | ||
t.same(pageJsonSchema.properties.description, { type: 'string', nullable: true }) | ||
if (isMariaDB) { | ||
t.same(pageJsonSchema.properties.metadata, { type: 'string', nullable: true }) | ||
} else { | ||
t.same(pageJsonSchema.properties.metadata, { type: 'object', additionalProperties: true, nullable: true }) | ||
} | ||
t.same(pageJsonSchema.required, ['title']) | ||
} | ||
}) |
22903
202