api-platform / create-client

Generate React or Vue.js-based Progressive Web Apps from an Hydra-enabled API. Also support React Native.
https://api-platform.com/docs/client-generator/
MIT License
370 stars 132 forks source link

Generating Typescript interfaces requires a GET collection operation. #309

Closed Crovitche-1623 closed 5 months ago

Crovitche-1623 commented 2 years ago

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')"]
    ]
    ...
J3m5 commented 5 months ago

This issue has been fixed in the api-doc-parser package Once we have published a new version, ressources without a Get collection operation wont be generated and an error will simply be logged.

I'm closing this issue for now.