mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-23 10:02:51 +00:00
feat: generator updates
This commit is contained in:
49
packages/es-mapping-generator/src/generator/base.js
Normal file
49
packages/es-mapping-generator/src/generator/base.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import {transformObject} from './transformers/object.js';
|
||||
import {transformString} from './transformers/string.js';
|
||||
import {transformDefinition} from './definition.js';
|
||||
|
||||
/**
|
||||
* Transform JSONSchema without applying custom tag logic
|
||||
* @typedef {import('json-schema').JSONSchema7} JSONSchema
|
||||
*
|
||||
* @param context {import('./context.js').Context}
|
||||
* @param definition {JSONSchema}
|
||||
* @returns {import('../types.js').MappingProperty}
|
||||
*/
|
||||
export function transformBase(context, definition) {
|
||||
if (definition.anyOf) {
|
||||
return context.resolveUnion(/** @type {JSONSchema[]} */ (definition.anyOf));
|
||||
}
|
||||
|
||||
switch (definition.type) {
|
||||
case 'array': {
|
||||
if (Array.isArray(definition.items)) {
|
||||
return context.resolveUnion(/** @type {JSONSchema[]} */ (definition.items));
|
||||
} else if (typeof definition.items === 'object') {
|
||||
return transformDefinition(context, definition.items);
|
||||
} else {
|
||||
return context.bail(`Not implemented array type ${typeof definition.items}`);
|
||||
}
|
||||
}
|
||||
case 'object': {
|
||||
return transformObject(context, definition);
|
||||
}
|
||||
case 'string': {
|
||||
return transformString(definition);
|
||||
}
|
||||
case 'number': {
|
||||
return {type: 'float'};
|
||||
}
|
||||
case 'integer': {
|
||||
return {type: 'integer'};
|
||||
}
|
||||
case 'boolean': {
|
||||
return {type: 'boolean'};
|
||||
}
|
||||
default: {
|
||||
return {
|
||||
dynamic: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user