fn expand_valueof()

in compiler-rs/clients_schema/src/transform/expand_generics.rs [321:385]


    fn expand_valueof(
        value: &ValueOf,
        mappings: &GenericMapping,
        model: &IndexedModel,
        ctx: &mut Ctx,
    ) -> anyhow::Result<ValueOf> {
        match value {
            ValueOf::ArrayOf(ref arr) => {
                let value = expand_valueof(&arr.value, mappings, model, ctx)?;
                Ok(ArrayOf { value: Box::new(value) }.into())
            }

            ValueOf::DictionaryOf(dict) => {
                let key = expand_valueof(&dict.key, mappings, model, ctx)?;
                let value = expand_valueof(&dict.value, mappings, model, ctx)?;
                Ok(DictionaryOf {
                    single_key: dict.single_key,
                    key: Box::new(key),
                    value: Box::new(value),
                }
                .into())
            }

            ValueOf::InstanceOf(inst) => {
                // If this is a generic parameter, return its mapping
                if let Some(p) = mappings.get(&inst.typ) {
                    return Ok(p.clone());
                }

                // Inline or unwrap if required by the config
                if ctx.config.inline.contains(&inst.typ) {
                    return inline_generic_type(inst, mappings, model, ctx);
                }
                if ctx.config.unwrap.contains(&inst.typ) {
                    return unwrap_generic_type(inst, mappings, model, ctx);
                }

                // Expand generic parameters, if any
                let args = inst
                    .generics
                    .iter()
                    .map(|arg| expand_valueof(arg, mappings, model, ctx))
                    .collect::<Result<Vec<_>, _>>()?;

                Ok(InstanceOf {
                    typ: expand_type(&inst.typ, args, model, ctx)?,
                    generics: Vec::new(),
                }
                .into())
            }

            ValueOf::UnionOf(u) => {
                let items = u
                    .items
                    .iter()
                    .map(|item| expand_valueof(item, mappings, model, ctx))
                    .collect::<Result<Vec<_>, _>>()?;
                Ok(UnionOf { items }.into())
            }

            ValueOf::UserDefinedValue(_) => Ok(value.clone()),

            ValueOf::LiteralValue(_) => Ok(value.clone()),
        }
    }