owncloud / owncloud/libre-graph-api-php

Generated PHP has strange if-statements

Open
#1 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Example from https://github.com/owncloud/libre-graph-api-php/blob/main/lib/Api/TagsApi.php getTagsWithHttpInfo()

            switch($statusCode) {
            
                case 200:
                    if ('\OpenAPI\Client\Model\CollectionOfTags' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\OpenAPI\Client\Model\CollectionOfTags' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\CollectionOfTags', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            
            
                default:
                    if ('\OpenAPI\Client\Model\OdataError' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\OpenAPI\Client\Model\OdataError' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\OdataError', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            
            }

            $returnType = '\OpenAPI\Client\Model\CollectionOfTags';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

Note: the first PHP was generated by https://github.com/owncloud/libre-graph-api/pull/113

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

The example is in lib/Api/TagsApi.php, in getTagsWithHttpInfo(); start by comparing this generated method with the generation inputs or templates used by the PHP client. Determine the intended handling for CollectionOfTags, OdataError, and the return type, then verify that regenerated output no longer contains the reported conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.