[BUG] [PHP] generateAliasAsModel leads to invalid parameter types on models.
Created by: neclimdul
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
Documented types are incorrect when a model property is a list of another model and the child model is an "alias" of array.
I think the php generator is treating the model as a model regardless and prefixing the namespace but maybe but some other core part of the generator is collapsing it to an array leaving this invalid type? I thought I had a theory from the name generation and the php generator not listing array
as a primitive but that seems to not cause problems. At least I can rationalize exactly where the bug would be.
Then I noticed generateAliasAsModel
being mentioned in verbose output. I can confirm that adding --generate-alias-as-model fixed the type.
openapi-generator version
tested with 5.
OpenAPI declaration file content or url
swagger: '2.0'
info:
description: Marketo Rest API
version: '1.0'
title: Marketo Rest API
termsOfService: 'https://www.marketo.com/company/legal/'
contact:
name: Marketo Developer Relations
url: 'http://developers.marketo.com'
email: developerfeedback@marketo.com
license:
name: API License Agreement
url: 'http://developers.marketo.com/api-license/'
host: 'localhost:8080'
basePath: /
schemes:
- https
tags:
- name: Leads
description: Leads Controller
paths:
/rest/v1/leads/describe2.json:
get:
tags:
- Leads
summary: Describe Lead2
description: 'Returns list of searchable fields on lead objects in the target instance. Required Permissions: Read-Only Lead, Read-Write Lead'
operationId: describeUsingGET_6
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
$ref: '#/definitions/LeadAttribute2'
definitions:
LeadAttribute2:
type: object
required:
- name
- searchableFields
- fields
properties:
name:
type: string
description: '"API Lead"'
searchableFields:
type: array
description: List of searchable fields
items:
$ref: '#/definitions/LeadAttribute2SearchableFields'
fields:
type: array
description: Description of searchable fields
items:
$ref: '#/definitions/LeadAttribute2Fields'
LeadAttribute2SearchableFields:
type: array
description: List of searchable fields
items:
type: string
description: Searchable field
LeadAttribute2Fields:
type: object
required:
- name
properties:
name:
type: string
description: REST API name of field
Generation Details
docker run --rm -v $PWD:/source -v ${PWD}/tmp:/output/ openapitools/openapi-generator-cli:v5.0.1 generate -i test.yaml -g php -o /output
Steps to reproduce
Running the generator, the LeadAttribute2.php model ends up with the following incorrectly typed code:
<?php
* Gets searchable_fields
*
* @return \OpenAPI\Client\Model\array[]
*/
public function getSearchableFields()
{
return $this->container['searchable_fields'];
}
/**
* Sets searchable_fields
*
* @param \OpenAPI\Client\Model\array[] $searchable_fields List of searchable fields
*
* @return self
*/
public function setSearchableFields($searchable_fields)
{
$this->container['searchable_fields'] = $searchable_fields;
return $this;
}
Related issues/PRs
generateAliasAsModel does have some other bugs in the queue that seem similar but I didn't see one that quite matched this. I could be wrong though.
Suggest a fix
abstract php generator might need to take into account the generateAliasAsModel option when prepending namespace somewhere? I'm not sure how to test this so I'm not sure how to narrow down the problem.