pub struct FieldResolver { /* private fields */ }Expand description
Resolves fixture field paths to language-specific accessor expressions.
Implementations§
Source§impl FieldResolver
impl FieldResolver
Sourcepub fn new(
fields: &HashMap<String, String>,
optional: &HashSet<String>,
result_fields: &HashSet<String>,
array_fields: &HashSet<String>,
method_calls: &HashSet<String>,
) -> Self
pub fn new( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, ) -> Self
Create a new resolver from the e2e config’s fields aliases,
fields_optional set, result_fields set, fields_array set,
and fields_method_calls set.
Sourcepub fn new_with_error_aliases(
fields: &HashMap<String, String>,
optional: &HashSet<String>,
result_fields: &HashSet<String>,
array_fields: &HashSet<String>,
method_calls: &HashSet<String>,
error_field_aliases: &HashMap<String, String>,
) -> Self
pub fn new_with_error_aliases( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, ) -> Self
Create a new resolver that also includes error-path field aliases.
error_field_aliases maps fixture sub-field names (the part after "error.")
to the actual field names on the error type, enabling accessor_for_error to
resolve fields like "status_code" against the error value.
Sourcepub fn new_with_php_getters(
fields: &HashMap<String, String>,
optional: &HashSet<String>,
result_fields: &HashSet<String>,
array_fields: &HashSet<String>,
method_calls: &HashSet<String>,
error_field_aliases: &HashMap<String, String>,
php_getter_map: PhpGetterMap,
) -> Self
pub fn new_with_php_getters( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, php_getter_map: PhpGetterMap, ) -> Self
Create a new resolver that also knows which PHP fields need getter-method syntax.
php_getter_map carries a per-(type_name, field_name) classification: the PHP
accessor renderer emits ->getCamelCase() when (owner_type, field) is
recorded as needing a getter, and ->camelCase property syntax otherwise.
This matches the ext-php-rs 0.15.x behaviour where #[php(getter)] is used for
non-scalar fields (Named structs, Vec#[php(prop)] is
used for scalar-compatible fields.
Keying by (type, field) — not bare field name — is essential because the same
field name can have different scalarness on different types. The map also carries
per-type field→nested-type mappings so the renderer can walk a path like
outer.inner.content through the IR, advancing the current-type cursor at each
segment.
Sourcepub fn with_swift_root_type(&self, root_type: Option<String>) -> Self
pub fn with_swift_root_type(&self, root_type: Option<String>) -> Self
Return a clone of this resolver with the Swift first-class map’s
root_type replaced.
Used by Swift e2e codegen to thread a per-fixture (per-call) root type
into the render_swift_with_first_class_map dispatcher. Each fixture’s
call returns a different IR type (e.g. ChatCompletionResponse vs
FileObject), and the first-class/opaque classification of the root
drives whether path segments are emitted with property access or
method-call access. Setting it per-fixture avoids picking a single
workspace-wide default that breaks half the fixtures.
Sourcepub fn new_with_swift_first_class(
fields: &HashMap<String, String>,
optional: &HashSet<String>,
result_fields: &HashSet<String>,
array_fields: &HashSet<String>,
method_calls: &HashSet<String>,
error_field_aliases: &HashMap<String, String>,
swift_first_class_map: SwiftFirstClassMap,
) -> Self
pub fn new_with_swift_first_class( fields: &HashMap<String, String>, optional: &HashSet<String>, result_fields: &HashSet<String>, array_fields: &HashSet<String>, method_calls: &HashSet<String>, error_field_aliases: &HashMap<String, String>, swift_first_class_map: SwiftFirstClassMap, ) -> Self
Create a new resolver that also knows the Swift first-class/opaque
classification per IR type. Mirrors new_with_php_getters but for the
Swift render_swift_with_first_class_map path.
Sourcepub fn resolve<'a>(&'a self, fixture_field: &'a str) -> &'a str
pub fn resolve<'a>(&'a self, fixture_field: &'a str) -> &'a str
Resolve a fixture field path to the actual struct path. Falls back to the field itself if no alias exists.
Sourcepub fn leaf_is_vec_via_swift_map(&self, field: &str) -> bool
pub fn leaf_is_vec_via_swift_map(&self, field: &str) -> bool
True when the leaf segment of field is a Vec<T> field on any IR type.
Used by swift codegen to keep .count straight on method-call accessors
(result.output() returns RustVec — .count works directly, no
.toString() needed). The check is on the bare leaf name, so it is best-
effort when distinct types share a field name with different kinds.
Sourcepub fn is_optional(&self, field: &str) -> bool
pub fn is_optional(&self, field: &str) -> bool
Check if a resolved field path is optional.
Sourcepub fn has_alias(&self, fixture_field: &str) -> bool
pub fn has_alias(&self, fixture_field: &str) -> bool
Check if a fixture field has an explicit alias mapping.
Sourcepub fn has_explicit_field(&self, field_name: &str) -> bool
pub fn has_explicit_field(&self, field_name: &str) -> bool
Check whether field_name is configured as an explicit result field.
Returns true only when the caller has populated result_fields AND the
field name is present. Empty result_fields always returns false — use
is_valid_for_result for the default-allow semantics.
Sourcepub fn is_valid_for_result(&self, fixture_field: &str) -> bool
pub fn is_valid_for_result(&self, fixture_field: &str) -> bool
Check whether a fixture field path is valid for the configured result type.
Sourcepub fn is_collection_root(&self, field: &str) -> bool
pub fn is_collection_root(&self, field: &str) -> bool
Check if a field name is the root of a collection type (i.e., the field
itself returns a Vec/array, even though it is not in fields_array
directly).
fields_array tracks traversal paths like choices[0].message.tool_calls
— the array element paths — not the bare collection accessor (choices).
fields_optional may also contain paths like data[0].url that reveal
data is a collection root.
Returns true when any entry in array_fields or optional_fields
starts with {field}[, indicating that field is the top-level
collection getter.
Sourcepub fn tagged_union_split(
&self,
fixture_field: &str,
) -> Option<(String, String, String)>
pub fn tagged_union_split( &self, fixture_field: &str, ) -> Option<(String, String, String)>
Check if a resolved field path traverses a tagged-union variant.
Returns Some((prefix, variant, suffix)) where:
prefixis the path up to (but not including) the tagged-union field (e.g.,"metadata.format")variantis the tagged-union accessor segment (e.g.,"excel")suffixis the remaining path after the variant (e.g.,"sheet_count")
Returns None if no tagged-union segment exists in the path.
Sourcepub fn has_map_access(&self, fixture_field: &str) -> bool
pub fn has_map_access(&self, fixture_field: &str) -> bool
Check if a resolved field path contains a non-numeric map access.
Sourcepub fn accessor(
&self,
fixture_field: &str,
language: &str,
result_var: &str,
) -> String
pub fn accessor( &self, fixture_field: &str, language: &str, result_var: &str, ) -> String
Generate a language-specific accessor expression.
Sourcepub fn accessor_for_error(
&self,
sub_field: &str,
language: &str,
err_var: &str,
) -> String
pub fn accessor_for_error( &self, sub_field: &str, language: &str, err_var: &str, ) -> String
Generate a language-specific accessor expression for an error-path field.
Used when assertion_type == "error" and the fixture declares a field
like "error.status_code". The caller strips the "error." prefix and
passes the sub-field name (e.g. "status_code") here.
Resolves against error_field_aliases (instead of the success-path
aliases). Falls back to direct field access (i.e. err_var.status_code)
when no alias exists.
For Rust, uses render_rust_with_optionals so that fields in
method_calls emit parentheses (e.g. err.status_code() when
"status_code" is in fields_method_calls).
Sourcepub fn has_error_aliases(&self) -> bool
pub fn has_error_aliases(&self) -> bool
Check whether a sub-field (the part after "error.") has an entry in
error_field_aliases or if there are any error aliases at all.
When there are no error aliases configured, callers fall back to
direct field access, which is the safe default for known public fields
like status_code on LiterLlmError.
Trait Implementations§
Source§impl Clone for FieldResolver
impl Clone for FieldResolver
Source§fn clone(&self) -> FieldResolver
fn clone(&self) -> FieldResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more