documentSchemaObject method Null safety

  1. @override
APISchemaObject documentSchemaObject(
  1. APIDocumentContext context
)
override

Returns an APISchemaObject that represents this property.

Used during documentation.

Implementation

@override
APISchemaObject documentSchemaObject(APIDocumentContext context) {
  final relatedType =
      context.schema.getObjectWithType(inverse!.entity.instanceType);

  if (relationshipType == ManagedRelationshipType.hasMany) {
    return APISchemaObject.array(ofSchema: relatedType)
      ..isReadOnly = true
      ..isNullable = true;
  } else if (relationshipType == ManagedRelationshipType.hasOne) {
    return relatedType
      ..isReadOnly = true
      ..isNullable = true;
  }

  final destPk = destinationEntity.primaryKeyAttribute!;
  return APISchemaObject.object({
    destPk.name: ManagedPropertyDescription._typedSchemaObject(destPk.type!)
  })
    ..title = name;
}