core icon indicating copy to clipboard operation
core copied to clipboard

Regression due to PR 7419 when using `@rtk-query/codegen-openapi` on `hydra:member` type

Open cpetit-sigma-fr opened this issue 4 months ago • 0 comments

API Platform version(s) affected: 4.2.2

Description

https://github.com/api-platform/core/pull/7419 introduces a regression for our project using @rtk-query/codegen-openapi as defining 'hydra:member': object[] instead of 'hydra:member': any makes Typescript consider type is object[] even if hydra:member is redefined as a correct type like FooBarJsonldBazCollection[] like this:

export type FooBarJsonldBazCollectionApiResponse =
  /** status 200 FooBarBaz */ HydraCollectionBaseSchema & {
    'hydra:member'?: FooBarJsonldBazCollection[]
  }

How to reproduce

  • Open http://localhost:8000/api/docs.jsonopenapi (with a running API platform (core) project)
  • if API is 4.2.1, HydraCollectionBaseSchema uses any for member
  • if API is 4.2.2, HydraCollectionBaseSchema uses object[] for member

Possible Solution

make this object[] change optional / configurable

Additional Context

For now, our workaround is to replace all occurences in each of our generated API files:

for api in src/redux/*Api.ts ; do
    echo "api='$api'"
    sed -i "s/'hydra:member': object\[\]/'hydra:member': any/g" $api
done

cpetit-sigma-fr avatar Oct 23 '25 14:10 cpetit-sigma-fr