OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-axios] allOf is not compatible with enum query params
Nobody has claimed this yet.
- 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?
Description
When I use "allOf" in a query parameter (enum), the generated "AxiosParamCreator" uses the enum value in a wrong manner.
openapi-generator version
7.7.0
OpenAPI declaration file content or url
The following definition will cause the error
CustomFieldTypeEnum:
type: string
enum:
- asset
- work_order
- spare_part
CustomFieldsTypeQuery:
name: type
in: query
description: Custom Field Type to filter, possible values are in schema CustomFieldTypeEnum
schema:
allOf:
- $ref: ../../enums/CustomFieldTypeEnum.yaml
- example:
asset
get:
tags:
- Custom Fields
summary: Fetch custom fields
description: Fetch custom fields
operationId: fetchCustomFields
parameters:
- $ref: ../components/parameters/custom-fields/CustomFieldsTypeQuery.yaml
Generation Details
generate `
-g typescript-axios `
-i C:\Visualstudio\connectavo-api-cmms-openapi\openapi-api-cmms-v2\openapi-api-cmms-bundled.yaml `
-o C:\Visualstudio\experiment\v2-typescript-axios `
--additional-properties=npmName=v2-axios `
--additional-properties=npmVersion=0.0.0-alpha
The code would be generated:
if (type !== undefined) {
for (const [key, value] of Object.entries(type)) {
localVarQueryParameter[key] = value;
}
}
When the user calls the method and passes in CustomFieldTypeEnum.WorkOrder, the code above will split each character in the enum and result in {0=w&1=o&2=r&3=k&4=_&5=o&6=r&7=d&8=e&9=r}
Steps to reproduce
Call the generated method by running:
const customFieldsApi = new CustomFieldsApi(config);
customFieldsApi
.fetchCustomFields(CustomFieldTypeEnum.WorkOrder)
It will generate a wrong request URL (see following screenshot), where the correct expectation should be type=work_order (instead of w, o, r, k, _, o, r, d, e, r with 0123456789)
Suggest a fix
As a temporal work-around, I had to remove "allOf"
CustomFieldsTypeQuery:
name: type
in: query
description: Custom Field Type to filter, possible values are in schema CustomFieldTypeEnum
schema:
$ref: ../../enums/CustomFieldTypeEnum.yaml
To make "allOf" work again, I think, in the generated code, the enum should be generated in the same way (as if "allOf" was not being used):
if (type !== undefined) {
localVarQueryParameter['type'] = type;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided OpenAPI declaration and the typescript-axios generation command, then inspect the generated AxiosParamCreator handling of the allOf enum query parameter. Done means calling fetchCustomFields with CustomFieldTypeEnum.WorkOrder produces type=work_order rather than character-indexed query parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100