OpenAPITools / OpenAPITools/openapi-generator

[BUG] url-encoded-request Parameter with extensible enum

Open
#19,281 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

When generating an API Controller using url-encoded-request Parameter and extensible enums, the annotations are wrong and input parameter cannot be read

openapi-generator version

id "org.openapi.generator" version "7.7.0"

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: 1.0.0
  title: FBDE API
paths:
  /v1/my/api:
    post:
      description: My description
      operationId: myApi
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              properties:
                myParam:
                  description: My parameter description
                  allOf:
                    - $ref: '#/components/schemas/MyExtensibleEnum'
                      # TODO multiple allOf do not work with generator plugin < 6.5+
                      # https://github.com/OpenAPITools/openapi-generator/issues/10010#issuecomment-1482326673
                    - type: string
                      x-extensible-enum:
                        - NOT_SPECIFIED
      responses:
        '200':
          description: ok
components:
  schemas:
    MyExtensibleEnum:
      type: string
      x-extensible-enum:
        - ONE
        - TWO
        - THREE
Generation Details
openApiGenerate  {
	generatorName = "spring"
	inputSpec = openapi.yaml
	configOptions = [
			dateLibrary: "java11",
			interfaceOnly: "true",
			hideGenerationTimestamp: "true",
			oas3: "true",
			useTags: "true",
			documentationProvider: "springdoc",
			openApiNullable: "false",
			containerDefaultToNull: "false"
	]
}
Steps to reproduce
./gradlew clean openApiGenerate

Generatred code has following annotations:

@Parameter(name = "myParam", description = "My parameter description") @Valid @RequestPart(value = "myParam", required = false) String myParam,

It should be like this:

@Parameter(name = "myParam", description = "My parameter description") @Valid @RequestParam(value = "myParam", required = false) String myParam,

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/10010

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 with the openapi.yaml reproduction and run ./gradlew clean openApiGenerate using the Spring generator configuration shown. Inspect the generated API controller for the application/x-www-form-urlencoded parameter and compare its annotations with the expected @RequestParam output. Done means the generated parameter uses @RequestParam while retaining the documented name, validation, and required setting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.