OpenAPITools / OpenAPITools/openapi-generator
[BUG] enum parameters are no longer enum types since 4.0.0-beta3
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I am using a custom mustache template to generate an alternative controller whose operations use nullable enums for optional enum query parameters. This has been working fine until 4.0.0 beta2, but has started breaking from beta3 (and is still broken in the 4.0.0 release). As far as I have narrowed down the issue, the {{isEnum}} expression no longer evaluates to true. This happens at least when used in the context of a query parameter, but still works fine for models. From the code differences between the two releases I could not find out why it has stopped working for (query) parameters
As a result of the above, my custom mustache template dataTypeNullable:
{{&dataType}}{{#isEnum}}{{^required}}?{{/required}}{{/isEnum}}
no longer functions as desired when used in the context of generating operation parameters for my controllers. If this isn't a bug, it would be much appreciated if someone could point me in the direction of a fix!
openapi-generator version
OK <= 4.0.0-beta2
NOK > 4.0.0-beta2
Minimal OpenAPI declaration to reproduce
openapi: "3.0.0"
info:
version: 1.0.0
title: "Example API"
servers:
- url: http://example/
paths:
/:
get:
parameters:
- in: query
name: param
schema:
$ref: "#/components/schemas/SomeEnum"
required: false
operationId: exampleOperation
responses:
default:
description: "not implemented error"
components:
schemas:
SomeEnum:
type: string
enum:
- item1
- item2
Command line used for generation
We have been using the generator as part of a multi-stage docker build, as follows (although I am pretty sure this doesn't matter).
FROM openapitools/openapi-generator-cli:v4.0.0-beta2 AS generator
WORKDIR /local
COPY . .
RUN /usr/local/bin/docker-entrypoint.sh generate \
-DpackageName=TestService \
-DdebugOperations=true \
-i test-service.yaml \
-g aspnetcore \
-o out/
Steps to reproduce
- Run the 4.0.0-beta2 generator with
debugOperationsset to true and capture the debug log - Run the 4.0.0-beta3 generator with
debugOperationsset to true and capture the debug log - Diff the log and obtain something like this.
- Observe that the
isEnumproperty of theparamparameter has moved fromtruetofalsebetween beta2 and beta3.
Suggest a fix
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 comparing the debugOperations output for test-service.yaml between 4.0.0-beta2 and beta3, focusing on the query parameter's isEnum value. Trace how the referenced SomeEnum schema is represented for operation parameters and how the dataTypeNullable template consumes it. Done means isEnum is true for the nullable enum query parameter and the custom template produces the intended output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100