OpenAPITools / OpenAPITools/openapi-generator

[BUG][php-nextgen] for some collections multiple Model files are generated

Open
#17,143 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

php-nextgen generates for some collections multiple Model files that are similar but not the same, and I cannot see why
e.g. I get CollectionOfDrives.php and CollectionOfDrives1.php
diff:

diff CollectionOfDrives.php CollectionOfDrives1.php
3c3
<  * CollectionOfDrives
---
>  * CollectionOfDrives1
37c37
<  * CollectionOfDrives Class Doc Comment
---
>  * CollectionOfDrives1 Class Doc Comment
44c44
< class CollectionOfDrives implements ModelInterface, ArrayAccess, JsonSerializable
---
> class CollectionOfDrives1 implements ModelInterface, ArrayAccess, JsonSerializable
53c53
<     protected static string $openAPIModelName = 'Collection_of_drives';
---
>     protected static string $openAPIModelName = 'Collection_of_drives_1';
61,62c61
<         'value' => '\OpenAPI\Client\Model\Drive[]',
<         'at_odata_next_link' => 'string'
---
>         'value' => '\OpenAPI\Client\Model\Drive[]'
71,72c70
<         'value' => null,
<         'at_odata_next_link' => null
---
>         'value' => null
81,82c79
<         'value' => false,
< 		'at_odata_next_link' => false
---
>         'value' => false
171,172c168
<         'value' => 'value',
<         'at_odata_next_link' => '@odata.nextLink'
---
>         'value' => 'value'
181,182c177
<         'value' => 'setValue',
<         'at_odata_next_link' => 'setAtOdataNextLink'
---
>         'value' => 'setValue'
191,192c186
<         'value' => 'getValue',
<         'at_odata_next_link' => 'getAtOdataNextLink'
---
>         'value' => 'getValue'
252d245
<         $this->setIfExists('at_odata_next_link', $data ?? [], null);
282,285d274
<         if (!is_null($this->container['value']) && (count($this->container['value']) > 100)) {
<             $invalidProperties[] = "invalid value for 'value', number of items must be less than or equal to 100.";
<         }
< 
323,326d311
< 
<         if ((count($value) > 100)) {
<             throw new InvalidArgumentException('invalid value for $value when calling CollectionOfDrives., number of items must be less than or equal to 100.');
<         }
328,354d312
< 
<         return $this;
<     }
< 
<     /**
<      * Gets at_odata_next_link
<      *
<      * @return string|null
<      */
<     public function getAtOdataNextLink(): ?string
<     {
<         return $this->container['at_odata_next_link'];
<     }
< 
<     /**
<      * Sets at_odata_next_link
<      *
<      * @param string|null $at_odata_next_link at_odata_next_link
<      *
<      * @return $this
<      */
<     public function setAtOdataNextLink(?string $at_odata_next_link): static
<     {
<         if (is_null($at_odata_next_link)) {
<             throw new InvalidArgumentException('non-nullable at_odata_next_link cannot be null');
<         }
<         $this->container['at_odata_next_link'] = $at_odata_next_link;

diff CollectionOfDriveItems.php CollectionOfDriveItems1.php
3c3
<  * CollectionOfDriveItems
---
>  * CollectionOfDriveItems1
37c37
<  * CollectionOfDriveItems Class Doc Comment
---
>  * CollectionOfDriveItems1 Class Doc Comment
44c44
< class CollectionOfDriveItems implements ModelInterface, ArrayAccess, JsonSerializable
---
> class CollectionOfDriveItems1 implements ModelInterface, ArrayAccess, JsonSerializable
53c53
<     protected static string $openAPIModelName = 'Collection_of_driveItems';
---
>     protected static string $openAPIModelName = 'Collection_of_driveItems_1';
61,62c61
<         'value' => '\OpenAPI\Client\Model\DriveItem[]',
<         'at_odata_next_link' => 'string'
---
>         'value' => '\OpenAPI\Client\Model\DriveItem[]'
71,72c70
<         'value' => null,
<         'at_odata_next_link' => null
---
>         'value' => null
81,82c79
<         'value' => false,
< 		'at_odata_next_link' => false
---
>         'value' => false
171,172c168
<         'value' => 'value',
<         'at_odata_next_link' => '@odata.nextLink'
---
>         'value' => 'value'
181,182c177
<         'value' => 'setValue',
<         'at_odata_next_link' => 'setAtOdataNextLink'
---
>         'value' => 'setValue'
191,192c186
<         'value' => 'getValue',
<         'at_odata_next_link' => 'getAtOdataNextLink'
---
>         'value' => 'getValue'
252d245
<         $this->setIfExists('at_odata_next_link', $data ?? [], null);
282,285d274
<         if (!is_null($this->container['value']) && (count($this->container['value']) > 100)) {
<             $invalidProperties[] = "invalid value for 'value', number of items must be less than or equal to 100.";
<         }
< 
323,326d311
< 
<         if ((count($value) > 100)) {
<             throw new InvalidArgumentException('invalid value for $value when calling CollectionOfDriveItems., number of items must be less than or equal to 100.');
<         }
328,354d312
< 
<         return $this;
<     }
< 
<     /**
<      * Gets at_odata_next_link
<      *
<      * @return string|null
<      */
<     public function getAtOdataNextLink(): ?string
<     {
<         return $this->container['at_odata_next_link'];
<     }
< 
<     /**
<      * Sets at_odata_next_link
<      *
<      * @param string|null $at_odata_next_link at_odata_next_link
<      *
<      * @return $this
<      */
<     public function setAtOdataNextLink(?string $at_odata_next_link): static
<     {
<         if (is_null($at_odata_next_link)) {
<             throw new InvalidArgumentException('non-nullable at_odata_next_link cannot be null');
<         }
<         $this->container['at_odata_next_link'] = $at_odata_next_link;
diff CollectionOfEducationUser.php CollectionOfEducationUser1.php
3c3
<  * CollectionOfEducationUser
---
>  * CollectionOfEducationUser1
37c37
<  * CollectionOfEducationUser Class Doc Comment
---
>  * CollectionOfEducationUser1 Class Doc Comment
44c44
< class CollectionOfEducationUser implements ModelInterface, ArrayAccess, JsonSerializable
---
> class CollectionOfEducationUser1 implements ModelInterface, ArrayAccess, JsonSerializable
53c53
<     protected static string $openAPIModelName = 'Collection_of_educationUser';
---
>     protected static string $openAPIModelName = 'Collection_of_educationUser_1';
61c61
<         'value' => '\OpenAPI\Client\Model\EducationUser[]'
---
>         'value' => '\OpenAPI\Client\Model\EducationClass[]'
293c293
<      * @return \OpenAPI\Client\Model\EducationUser[]|null
---
>      * @return \OpenAPI\Client\Model\EducationClass[]|null
303c303
<      * @param \OpenAPI\Client\Model\EducationUser[]|null $value value
---
>      * @param \OpenAPI\Client\Model\EducationClass[]|null $value value
openapi-generator version

7.2.0-SNAPSHOT
docker tag openapitools/openapi-generator-cli@sha256:9f4bbfbaa0c83023e4029fa1278276c158f0985df2a3e115514d85feadb8c4f0

OpenAPI declaration file content or url

https://github.com/owncloud/libre-graph-api/blob/main/api/openapi-spec/v1.0.yaml

Generation Details

docker run --rm -v $PWD:/local openapitools/openapi-generator-cli@sha256:9f4bbfbaa0c83023e4029fa1278276c158f0985df2a3e115514d85feadb8c4f0 generate --enable-post-process-file -i /local/api/openapi-spec/v1.0.yaml --additional-properties=packageName=libregraph --git-user-id=owncloud --git-repo-id=libre-graph-api-php -g php-nextgen -o /local/out/php-nextgen

Steps to reproduce
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

Run the documented docker generation command against the linked libre-graph-api v1.0.yaml specification and compare the duplicate CollectionOf* model files. Start at the php-nextgen generator entry point and add a regression check showing that each collection produces one model with the expected fields; done means the suffixed duplicates are no longer generated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, php
Domain
backend-api-design, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.