typed-aws
Version:
Helps you write AWS CloudFormation in TypeScript
33 lines (32 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeSchema = void 0;
function normalizeSchemaType(schema) {
if (!schema.type && schema['$ref'])
return 'reference';
if (!schema.type && schema['allOf'])
return;
if (!schema.type && schema['oneOf'])
return;
if (!schema.type && schema['anyOf'])
return;
if (!schema.type &&
(schema['properties'] ||
schema['patternProperties'] ||
schema['additionalProperties']))
return 'object';
if (!schema.type)
throw new Error(`Unknown schema type ${JSON.stringify(schema)}`);
if (Array.isArray(schema.type)) {
Object.assign(schema, {
type: undefined,
oneOf: schema.type.map((type) => ({ type })),
});
}
return schema.type === 'integer' ? 'number' : schema.type;
}
function normalizeSchema(schema) {
schema.originalType = schema.type;
schema.type = normalizeSchemaType(schema);
}
exports.normalizeSchema = normalizeSchema;