Api-platform: Action documentation

Created on 27 May 2017  路  2Comments  路  Source: api-platform/api-platform

Let's say I create a custom action under AppBundle/Action. How can I make it show up in api docs?

question

Most helpful comment

This is an example I use:

# src/AppBundle/Resources/config/api_resources/resources.yml
AppBundle\Entity\Dictionary\Word:
  collectionOperations:
    get:
      method: 'GET' # nothing more to add if we want to keep the default controller
      normalization_context:
        groups: ['list_words']
  itemOperations:
    get:
      method: 'GET'
      normalization_context:
        groups: ['get_word']
    rhymeform:
      route_name: 'rhymeform'
      swagger_context:
        parameters:
          -
            name: id
            in: path
            required: true
            type: string
        responses:
          200:
            description: "rhymeform of the word"
            schema:
              type: "object"
              required: ["rhymeform"]
              properties:
                rhymeform:
                  type: "string"
          404:
            description: "Resource not found"
        summary: "Retrieve the rhymeform of a word"
        consumes: ["application/json", "text/html"]
        produces: ["application/json"]
    syllables:
      route_name: 'syllables'
      swagger_context:
        parameters:
          -
            name: id
            in: path
            required: true
            type: string
        responses:
          200:
            description: "syllables of the word separated by dash"
            schema:
              type: "object"
              required: ["syllables"]
              properties:
                syllables:
                  type: "string"
          404:
            description: "Resource not found"
        summary: "Retrieve the syllables of a word"
        consumes: ["application/json", "text/html"]
        produces: ["application/json"]

Same can be achieved with annotations.
More about the schema can be found in the swagger documentation.

All 2 comments

This is an example I use:

# src/AppBundle/Resources/config/api_resources/resources.yml
AppBundle\Entity\Dictionary\Word:
  collectionOperations:
    get:
      method: 'GET' # nothing more to add if we want to keep the default controller
      normalization_context:
        groups: ['list_words']
  itemOperations:
    get:
      method: 'GET'
      normalization_context:
        groups: ['get_word']
    rhymeform:
      route_name: 'rhymeform'
      swagger_context:
        parameters:
          -
            name: id
            in: path
            required: true
            type: string
        responses:
          200:
            description: "rhymeform of the word"
            schema:
              type: "object"
              required: ["rhymeform"]
              properties:
                rhymeform:
                  type: "string"
          404:
            description: "Resource not found"
        summary: "Retrieve the rhymeform of a word"
        consumes: ["application/json", "text/html"]
        produces: ["application/json"]
    syllables:
      route_name: 'syllables'
      swagger_context:
        parameters:
          -
            name: id
            in: path
            required: true
            type: string
        responses:
          200:
            description: "syllables of the word separated by dash"
            schema:
              type: "object"
              required: ["syllables"]
              properties:
                syllables:
                  type: "string"
          404:
            description: "Resource not found"
        summary: "Retrieve the syllables of a word"
        consumes: ["application/json", "text/html"]
        produces: ["application/json"]

Same can be achieved with annotations.
More about the schema can be found in the swagger documentation.

@angelov-todor thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vatri picture vatri  路  3Comments

ad3n picture ad3n  路  4Comments

ajaunasse picture ajaunasse  路  3Comments

dunglas picture dunglas  路  3Comments

MLKiiwy picture MLKiiwy  路  4Comments