From 627dea983c6a4cf676c7d84b00a8ac8d7e85c020 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 5 Jan 2026 15:03:30 +0000 Subject: [PATCH] Bug 41520: Filter out record_table from AdditionalFieldValue API responses Bug 35451 added a record_table field to the additional_field_values database table for performance optimization (better joins). However, this field was not added to the OpenAPI schema, and with additionalProperties: false, the API validator rejects responses containing it. Rather than adding this internal implementation detail to the public API schema, this patch adds a custom to_api method to Koha::AdditionalFieldValue that filters out the record_table field. This approach: 1. Keeps the database optimization from Bug 35451 2. Prevents internal implementation details from cluttering the API 3. Maintains context that API consumers already have from parent objects 4. Fixes OpenAPI validation errors for ERM agreements, licenses, and packages using extended_attributes Test plan: 1. Create an ERM agreement with additional fields/extended attributes 2. Access the agreement via the API with extended_attributes embedded 3. Verify the response includes extended_attributes but not record_table 4. Confirm no OpenAPI validation warnings in plack-api-error.log 5. prove t/db_dependent/api/v1/erm_agreements.t 6. Verify all tests pass Signed-off-by: Jan Kissig Signed-off-by: David Nind Signed-off-by: Jonathan Druart --- Koha/AdditionalFieldValue.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Koha/AdditionalFieldValue.pm b/Koha/AdditionalFieldValue.pm index c8dfd7a1bda..b0870493787 100644 --- a/Koha/AdditionalFieldValue.pm +++ b/Koha/AdditionalFieldValue.pm @@ -28,6 +28,23 @@ sub field { return Koha::AdditionalField->_new_from_dbic( $self->_result()->field() ); } +=head3 to_api + +Overloaded to_api method to exclude internal fields from API representation + +=cut + +sub to_api { + my ( $self, $params ) = @_; + + my $json = $self->SUPER::to_api($params); + + # Remove internal database optimization fields that shouldn't be exposed via API + delete $json->{record_table}; + + return $json; +} + =head2 Internal methods =head3 _type -- 2.43.0