mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: improve monorepo dev experience
This commit is contained in:
47
packages/es-mapping-generator/src/generator/base.ts
Normal file
47
packages/es-mapping-generator/src/generator/base.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user