in src/jsii2schema.ts [276:331]
export function schemaForInterface(type: jsiiReflect.Type | undefined, ctx: SchemaContext) {
if (!type || !(type instanceof jsiiReflect.InterfaceType)) {
return undefined; // skip
}
if (type.allMethods.length > 0) {
return undefined;
}
ctx = ctx.child('interface', type.fqn);
const ifctx = ctx;
return ctx.define(type.fqn, () => {
const properties: any = {};
const required = new Array<string>();
for (const prop of type.allProperties) {
ctx = ifctx.child(prop.optional ? 'optional' : 'required' + ' property', prop.name);
const schema = schemaForTypeReference(prop.type, ctx);
if (!schema) {
// if prop is not serializable but optional, we can still serialize
// but without this property.
if (prop.optional) {
ctx.warning('optional proprety omitted because it cannot be schematized');
continue;
}
// error
ctx.error('property cannot be schematized');
return undefined;
}
properties[prop.name] = schema;
const docstring = prop.docs.toString();
if (docstring) {
properties[prop.name].description = docstring;
}
if (!prop.optional) {
required.push(prop.name);
}
}
return {
type: 'object',
title: type.name,
additionalProperties: false,
properties,
required: required.length > 0 ? required : undefined,
};
});
}