OpenAPITools / OpenAPITools/openapi-generator

[BUG] [PHP] php-ze-ph generated operation cannot access description

Open
#3,152 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: PHP
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

php-ze-ph module templates use {{description}} variable in api.mustache to provide description for each operation. However this description won't be available in template, since guard {{#description}} does not twig:

{{#description}}
     * {{description}}
{{/description}}
openapi-generator version

4.0.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
    description: 'Test description'
    version: 1.0.0
    title: 'Test'
paths:
    /example_item:
        post:
            tags:
                - ExampleItem
            operationId: addExampleItem
            summary: 'Add new example item'
            description: 'Adds example item to the system'
            requestBody:
              description: 'Example item to add'
              content:
                  application/json:
                      schema:
                          $ref: '#/components/schemas/ExampleItem'

            responses:
                201:
                    description: 'Item created'
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ExampleItem'
components:
  schemas:
    ExampleItem:
        type: object
        required:
            - example_string
        properties:
            id:
                type: integer
                readOnly: true
                example: 1
            example_string:
                type: string
                maxLength: 6
                pattern: '[0-9]{4,6}'
                example: 'Some string contents'
Command line used for generation
npx openapi-generator generate -Dapis='/example_item' -i spec/openapi/api-v1.yml -g php-ze-ph -o .
Steps to reproduce
  • Create /example_item path operation with a summary and description
  • Run above command line
  • Open src/App/Handler/ExampleItem.php file
  • You will see pasted summary but not description in generated PHP code. Below Add new example item should be Adds example item to the system
/**
 * @PHA\Route(pattern="/example_item")
 */
class ExampleItem
{
    /**
     * Add new example item
     * @PHA\Post()
     * TODO check if consumer is valid, if it has correct priority and if it can be moved to class annotation
     * @PHA\Consumer(name=PHConsumer\Json::class, mediaType="application/json")
     * @PHA\Attribute(name=PHAttribute\Transfer::class, options={"type":\App\DTO\ExampleItem::class,"objectAttr":"bodyData"})
     * TODO check if producer is valid, if it has correct priority and if it can be moved to class annotation
     * @PHA\Producer(name=PHProducer\Transfer::class, mediaType="application/json")
     * @param ServerRequestInterface $request
     *
     * @throws PHException\HttpCode 501 if the method is not implemented
     *
     * @return \App\DTO\ExampleItem
     */
    public function addExampleItem(ServerRequestInterface $request): \App\DTO\ExampleItem
    {
        //TODO implement method
        /** @var \App\DTO\ExampleItem $bodyData */
        $bodyData = $request->getAttribute("bodyData");
        throw new PHException\HttpCode(501, "Not implemented");
    }
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/php-ze-ph/api.mustache and compare the summary and description guards used for each operation. Regenerate the supplied OpenAPI example with the shown php-ze-ph command, then verify that src/App/Handler/ExampleItem.php includes “Adds example item to the system” beneath the summary.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.