mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
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,
|
|
};
|
|
}
|
|
}
|
|
}
|