mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import {JSONSchema7} from 'json-schema';
|
|
import {MappingProperty} from '@elastic/elasticsearch/lib/api/types.js';
|
|
import {transformObject} from './transformers/object.js';
|
|
import {transformString} from './transformers/string.js';
|
|
import {Context} from './context.js';
|
|
import {transformDefinition} from './definition.js';
|
|
|
|
/**
|
|
* Transform JSONSchema without applying custom tag logic
|
|
*/
|
|
export function transformBase(context: Context, definition: JSONSchema7): MappingProperty {
|
|
if (definition.anyOf) {
|
|
return context.resolveUnion(definition.anyOf as JSONSchema7[]);
|
|
}
|
|
|
|
switch (definition.type) {
|
|
case 'array': {
|
|
if (Array.isArray(definition.items)) {
|
|
return context.resolveUnion(definition.items as JSONSchema7[]);
|
|
} 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,
|
|
};
|
|
}
|
|
}
|
|
}
|