schema-generator icon indicating copy to clipboard operation
schema-generator copied to clipboard

[enhancement] don't make abstract classes and embeddables api resources

Open Evertt opened this issue 8 years ago • 2 comments

Right now if I have this schema.yml

types:
    Thing:
        properties:
            name: ~

    Person:
        properties:
            familyName: ~

    Country:
        parent: false
        embeddable: true
        properties:
            address: { range: "Text" }

    PostalAddress:
        parent: false
        properties:
            addressCountry: { range: "Country", embedded: true }

It will generate all the entities and all entities are marked as an api resource in the class annotations. The only problem is that you don't want Thing and Country to be api resources. Thing is an abstract class so it can't even be initialized. And since Country is an embeddable it isn't linked to any database table so you can never fetch any countries from the api.

Evertt avatar May 08 '17 14:05 Evertt

You can disable some API resources (src/AppBundle/Resources/config/api_resources/resources.yml):

AppBundle\Entity\Thing:
    collectionOperations: {}
    itemOperations: {}
...

comxd avatar Jan 08 '18 21:01 comxd

Sorry for bumping this old issue.

Am I correct in assuming that setting a class as abstract, at least in the past, prevented it from becoming an ApiResource?

https://github.com/api-platform/schema-generator/issues/159

It seems that this is no longer the case. I have been helping myself with

        attributes:
            -   ApiResource: { operations: [ ] }

Is it "ok" to do it this way or is it rather not so good?

stiivo avatar Dec 30 '22 13:12 stiivo