create-client
create-client copied to clipboard
Generating Typescript interfaces requires a GET collection operation.
API Platform version(s) affected: 2.6.6
Description
A GET collection operation (not item operation as specified in error) is required to generate Typescript interfaces. If it's missing, this error occurs:
Error: Unable to find the URL for "https://localhost:9000/docs.jsonld#Entrypoint/entity", make sure your api resource has at least one GET item operation declared.
Why is this operation required ?
How to reproduce
Create an Api Resource without a GET collection operation and run this command:
NODE_TLS_REJECT_UNAUTHORIZED=0 npx @api-platform/client-generator --generator typescript https://localhost:9000/ src/
Workaround
Make the operation accessible to administrators using a security_access:
#[ApiResource(
collectionOperations: [
// this collection operation is required to generate Typescript Interfaces
'get' => ["security" => "is_granted('ROLE_ADMIN')"]
]
...