OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Missing allowed enum values of query parameters

Open
#20,487 0 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

Running the following command, the interface classes created don't contain the list of allowed values of the enum parameters in query string.

java -jar openapi-generator-cli-7.10.0.jar generate -i swaggerAnagrafe.yaml -g spring --api-package it.realeites.anagrafe.api --model-package it.realeites.anagrafe.model --group-id it.realeites.anagrafe --artifact-id APIAnagrafeRealeItes --artifact-version 1.0 -o APIAnagrafeRealeItes-SERVER --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true --skip-validate-spec --additional-properties=useSpringBoot3=true,java.version=21

You can find below a portion of my swagger file containing a GET API with an enum query param (codiceCompagnia) and also the java code generated. As you can see the allowed values of the param codiceCompagnia (RMA and ITA) are not described in the java code.

Java code generated

    default ResponseEntity<RispostaAmministratoreCondomini> elencoCondominiV10(@NotNull @Parameter(name = "codiceCompagnia", description = "Codice della compagnia", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "codiceCompagnia", required = true) String codiceCompagnia) {

The right code should something like this: I have only add the string ", in = ParameterIn.QUERY,schema=@Schema(allowableValues={ "RMA", "ITA" })" after the parameter "required = true".

public ResponseEntity<RispostaAmministratoreCondomini> elencoCondominiV10(@NotNull @Parameter(name = "codiceCompagnia", description = "Codice della compagnia", required = true, in = ParameterIn.QUERY,schema=@Schema(allowableValues={ "RMA", "ITA" })) @Valid @RequestParam(value = "codiceCompagnia", required = true) String codiceCompagnia) {

This issue does not trigger the check of the value entered in the input parameter.

openapi-generator version

7.11.0

OpenAPI declaration file content or url
  /condomini/v1.0:
    get:
      description: Restituisce l'elenco dei condomini associati all'amministratore
      operationId: elencoCondomini_v10
      parameters:
      - name: canale
        in: query
        description: Canale di richiamo del servizio
        required: true
        schema:
          type: string
      - name: codiceCompagnia    
        in: query
        description: Codice della compagnia
        required: true
        schema:
          type: string
          enum:
          - RMA
          - ITA
Generation Details
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

Start by running the provided openapi-generator-cli command with the shown OpenAPI declaration and inspect the generated Spring interface for the codiceCompagnia query parameter. Compare its @Parameter annotation with the expected allowableValues entries for RMA and ITA. Done means generated Java output preserves the enum values and the behavior is covered by the generator's relevant regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.