You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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 APIversion: '1.0'title: Marketo Rest APItermsOfService: 'https://www.marketo.com/company/legal/'contact:
name: Marketo Developer Relationsurl: 'http://developers.marketo.com'email: [email protected]license:
name: API License Agreementurl: 'http://developers.marketo.com/api-license/'host: 'localhost:8080'basePath: /schemes:
- httpstags:
- name: Leadsdescription: Leads Controllerpaths:
/rest/v1/leads/describe2.json:
get:
tags:
- Leadssummary: Describe Lead2description: 'Returns list of searchable fields on lead objects in the target instance. Required Permissions: Read-Only Lead, Read-Write Lead'operationId: describeUsingGET_6consumes:
- application/jsonproduces:
- application/jsonresponses:
'200':
description: OKschema:
$ref: '#/definitions/LeadAttribute2'definitions:
LeadAttribute2:
type: objectrequired:
- name
- searchableFields
- fieldsproperties:
name:
type: stringdescription: '"API Lead"'searchableFields:
type: arraydescription: List of searchable fieldsitems:
$ref: '#/definitions/LeadAttribute2SearchableFields'fields:
type: arraydescription: Description of searchable fieldsitems:
$ref: '#/definitions/LeadAttribute2Fields'LeadAttribute2SearchableFields:
type: arraydescription: List of searchable fieldsitems:
type: stringdescription: Searchable fieldLeadAttribute2Fields:
type: objectrequired:
- nameproperties:
name:
type: stringdescription: REST API name of field
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.
The text was updated successfully, but these errors were encountered:
This isn't just a documentation problem as might be suggested by the summary, the "fix" of turning on the model aliases actually trades one problem for a different one because this is all tied to serialization. Now the type is "valid" but the serialization has to deal with the fact that we're converting an array into an object and it doesn't know how to do it. Probably one of the related bugs I mentioned.
I've pulled up the generator code and I still can't rationalize where this is a bug with the PHP codegen specifically. The AbstractPhpCodegen doesn't do anything with the alias option so the fact that its triggering the problem suggests to me its somewhere else.
After a lot of tracing and digging and writing tests I'm fairly confident that fix is pretty straight forward. The PHP languageSpecificPrimitives doesn't include array which seems to trigger a slew of problems.
The dataType doesn't seem to get populated correctly.
The template can't properly detect that the type is a primitive.
You can see in Make php's array primitive #10093 this was actually creating bad docs in the sample with things like [**float[][]**](array.md) linking to no-existent documentation.
Bug Report Checklist
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
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:
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.
The text was updated successfully, but these errors were encountered: