Skip to content

Commit 8c43707

Browse files
Merge pull request #62 from Vitalii4as/browser/HCK-3747
Allow usage of adaptJsonSchema in browser version of application
2 parents b8d4ab6 + db7c36a commit 8c43707

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

api/re.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { adaptJsonSchema } = require('../reverse_engineering/helpers/adaptJsonSchema/adaptJsonSchema');
2+
3+
module.exports = { adaptJsonSchema };

reverse_engineering/api.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const commonHelper = require('./helpers/commonHelper');
44
const dataHelper = require('./helpers/dataHelper');
55
const errorHelper = require('./helpers/errorHelper');
6-
const adaptJsonSchema = require('./helpers/adaptJsonSchema/adaptJsonSchema');
6+
const { adaptJsonSchema } = require('./helpers/adaptJsonSchema/adaptJsonSchema');
77
const resolveExternalDefinitionPathHelper = require('./helpers/resolveExternalDefinitionPathHelper');
88
const validationHelper = require('../forward_engineering/helpers/validationHelper');
99

@@ -62,22 +62,7 @@ module.exports = {
6262
callback(handledError);
6363
},
6464

65-
adaptJsonSchema(data, logger, callback) {
66-
logger.log('info', 'Adaptation of JSON Schema started...', 'Adapt JSON Schema');
67-
try {
68-
const jsonSchema = JSON.parse(data.jsonSchema);
69-
70-
const adaptedJsonSchema = adaptJsonSchema(jsonSchema, data.options?.targetDBVersion);
71-
72-
logger.log('info', 'Adaptation of JSON Schema finished.', 'Adapt JSON Schema');
73-
74-
callback(null, {
75-
jsonSchema: JSON.stringify(adaptedJsonSchema)
76-
});
77-
} catch(e) {
78-
callback(commonHelper.handleErrorObject(e, 'Adapt JSON Schema'), data);
79-
}
80-
},
65+
adaptJsonSchema,
8166

8267
resolveExternalDefinitionPath(data, logger, callback) {
8368
resolveExternalDefinitionPathHelper.resolvePath(data, callback);

reverse_engineering/helpers/adaptJsonSchema/adaptJsonSchema.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const mapJsonSchema = require('./mapJsonSchema');
2+
const commonHelper = require('../commonHelper')
23

34
const convertToString = (jsonSchema) => {
45
return Object.assign({}, jsonSchema, {
@@ -44,7 +45,7 @@ const handleNumericType = (jsonSchema) => {
4445
return jsonSchema;
4546
};
4647

47-
const adaptJsonSchema = (jsonSchema, targetDBVersion) => {
48+
const adaptSchema = (jsonSchema, targetDBVersion) => {
4849
const isJSONSchemaCompatibleTargetVersion = targetDBVersion?.split('.')?.[1] >= '1'; // 3.1.0 or higher
4950
return mapJsonSchema(jsonSchema, (jsonSchemaItem) => {
5051
if (Array.isArray(jsonSchemaItem.type) && !isJSONSchemaCompatibleTargetVersion) {
@@ -59,4 +60,21 @@ const adaptJsonSchema = (jsonSchema, targetDBVersion) => {
5960
});
6061
};
6162

62-
module.exports = adaptJsonSchema;
63+
const adaptJsonSchema = (data, logger, callback) => {
64+
logger.log('info', 'Adaptation of JSON Schema started...', 'Adapt JSON Schema');
65+
try {
66+
const jsonSchema = JSON.parse(data.jsonSchema);
67+
68+
const adaptedJsonSchema = adaptSchema(jsonSchema, data.options?.targetDBVersion);
69+
70+
logger.log('info', 'Adaptation of JSON Schema finished.', 'Adapt JSON Schema');
71+
72+
callback(null, {
73+
jsonSchema: JSON.stringify(adaptedJsonSchema)
74+
});
75+
} catch(e) {
76+
callback(commonHelper.handleErrorObject(e, 'Adapt JSON Schema'), data);
77+
}
78+
};
79+
80+
module.exports = { adaptJsonSchema };

0 commit comments

Comments
 (0)