in src/models/typeDefinition.ts [219:307]
constructor(name: string, contract: SchemaObjectContract, isRequired: boolean, nested: boolean = false, definitions: object = {}) {
super(name, contract, isRequired);
this.kind = "object";
if (contract.$ref) { // reference
const refName = this.getTypeNameFromRef(contract.$ref);
this.type = new TypeDefinitionPropertyTypeReference(refName);
this.description = definitions[refName] ? definitions[refName].description ?? "" : "";
return;
}
if (contract.type === "array" && contract.items) {
if (contract.items.$ref) {
const arrayProperty = new TypeDefinitionPrimitiveProperty("[]", contract, isRequired);
arrayProperty.type = new TypeDefinitionPropertyTypeArrayOfReference(this.getTypeNameFromRef(contract.items.$ref));
this.properties = [arrayProperty];
} else if (contract.items.properties) {
const { props, hasReadOnly } = this.processProperties(contract.items, nested, definitions, "[]");
this.properties = props;
this.readOnly = hasReadOnly;
}
this.kind = "array";
return;
}
if (contract.items) { // indexer
let type = new TypeDefinitionPropertyTypePrimitive("object");
if (contract.items.type) {
type = new TypeDefinitionPropertyTypePrimitive(contract.items.type);
}
if (contract.items.$ref) {
type = new TypeDefinitionPropertyTypeReference(this.getTypeNameFromRef(contract.items.$ref));
}
this.properties = [new TypeDefinitionIndexerProperty(type)];
this.kind = "indexer";
return;
}
if (contract.enum) { // enumeration
this.enum = contract.enum;
this.kind = "enum";
}
if (contract.properties) { // complex type
const { props, hasReadOnly } = this.processProperties(contract, nested, definitions);
this.properties = props;
this.readOnly = hasReadOnly;
}
if (contract.allOf ||
contract.anyOf ||
contract.oneOf
) {
const { combinationType, combinationArray } = this.destructCombination(contract);
const processedCombinationPropertiesObject: ProcessedCombinationPropertiesObject = {
combinationReferenceObjectsArray: [],
combinationReferencesNames: [],
combinationOtherProperties: {},
combinationRequiredPropereties: contract.required || []
};
let processedTypeDefinitionsArray: TypeDefinition[] = [];
const combinationPropertiesProcessed = this.processCombinationProperties(combinationArray, definitions, processedCombinationPropertiesObject);
processedTypeDefinitionsArray = combinationPropertiesProcessed.combinationReferenceObjectsArray;
if (Object.keys(combinationPropertiesProcessed.combinationOtherProperties).length > 0) {
processedTypeDefinitionsArray.push(
new TypeDefinition(
"Other properties",
{
properties: combinationPropertiesProcessed.combinationOtherProperties,
required: combinationPropertiesProcessed.combinationRequiredPropereties
},
definitions
)
);
}
this.kind = "combination";
this.type = new TypeDefinitionPropertyTypeCombination(combinationType, combinationPropertiesProcessed.combinationReferencesNames);
this.properties = processedTypeDefinitionsArray;
}
}