api-platform icon indicating copy to clipboard operation
api-platform copied to clipboard

Description/Summary not changeable for sub resources

Open amigian74 opened this issue 3 years ago • 2 comments

API Platform version(s) affected: 2.6.8

Description
Unfortunately the summary and the description for subresources is wrong, but I'm not able to change it. I've tried the following: ''' * @ApiProperty( * readableLink=false, * writableLink=false, * description="Retrieves signals from the Device resource", * openapiContext={ * "summary"="Retrieves signals from the Device resource", * "description"="Retrieves signals from the Device resource" * }, * attributes={ * "openapiContext"={ * "summary"="Retrieves signals from the Device resource", * "description"="Retrieves signals from the Device resource" * } * } * ) '''

How to reproduce
Just add the above

Possible Solution
I'm not sure if this is a bug or so by design. If it is this would be a nice feature.

Thx in advance

amigian74 avatar Mar 17 '22 08:03 amigian74

You need to place the openapi_context of your subresource in your parent class configuration.

For exemple, using yaml, in MyParent.yaml :

resources:
  App\Entity\MyParent:
    subresourceOperations:
       mychild_get_subresource:
          openapi_context:
             summary: Hey
             description: blablabla

Using attributes I think you need to put it in the ApiResource attribute of your parent class and under subresourceOperations property.

p5yk0 avatar Apr 14 '22 10:04 p5yk0

I achieved this with the following configuration:

# config/api/company.yaml
# -----
App\Entity\Company:
  attributes:
    order:
      createdAt: DESC

    normalization_context:
      groups: [ 'company:read' ]
      skip_null_values: false
    denormalization_context:
      groups: [ 'company:write' ]

    id:
      groups: [ 'company:read', 'company:write', 'user:read', 'user:write', 'site:read', 'documentSending:read', 'tag:read' ]
    name:
      groups: [ 'company:read', 'company:write', 'user:read', 'user:write', 'site:read', 'documentSending:read', 'tag:read' ]

  properties:
    # GET /api/companies/{id}/sites to get the list of the Sites related to a Company.
    sites:
      subresource:
        resourceClass: 'App\Entity\Site'
        collection: true

  subresourceOperations:
    sites_get_subresource:
      method: 'GET'
      openapi_context:
        tags: ['Companies', 'Sites']
        summary: The list of the sites of a company
        description: |
          Get all the sites for the specified company

        parameters:
          - in: path
            name: id
            description: 'Indicate the id of the **Company**'
            required: true
            deprecated: false
            allowEmptyValue: false
            schema:
              type: string
              format: uuid
              default: ''
            example: '_company_5'
            style: form
            explode: true
            allowReserved: false

  collectionOperations:
    get:
      method: 'GET'
      filters: [ 'company.search_filter', 'company_custom.search_filter' ]
      openapi_context:
        tags: ['Companies']
        summary: Retrieves all the companies

    api_companies_name:
      openapi_context:
        tags: ['Companies']
        summary: The list of the companies names
        description: |
          Get all the companies with only their `id` and `name`.

    post:
      openapi_context:
        tags: ['Companies']

  itemOperations:
    get:
      openapi_context:
        tags: ['Companies']
    put:
      openapi_context:
        tags: ['Companies']
    delete:
      openapi_context:
        tags: ['Companies']

b2p-fred avatar Apr 27 '22 04:04 b2p-fred