OpenAPITools / OpenAPITools/openapi-generator
Question: How to add accept or contentType header as method parameter in generated webclient method?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi
We have defined our OAS(openapi.yml) with one GET operation where response can different contents for status 200 like this:
DummyResponse:
description: Dummy response
content:
"application/json":
schema:
$ref: "#/components/schemas/DummyObject"
"application/json;version=2":
schema:
$ref: "#/components/schemas/DummyObjectV2"
"application/json;version=3":
schema:
$ref: "#/components/schemas/DummyObjectV3"
When springboot application starts and swagger page is opened we are able to choose concrete value from combobox like this:
Now we want to generate apiclient via openapi-generator-maven-plugin(4.3.1) with following config:
<interfaceOnly>false</interfaceOnly>
<useOptional>true</useOptional>
<skipDefaultInterface>true</skipDefaultInterface>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>webclient</library>
with result that method will contains accept header as parameter:
Object getDummy(List accept) or Object getDummy(String accept)
Of course we can define accept header in yaml file and put it as parameter but then we have duplicated field in rendered swagger
components:
parameters:
Accept:
name: accept
in: header
required: false
schema:
type: array
items:
type: string
default: ["application/json"]
Can somebody help me how to call our generated method via webclient with full control which accept header to be passed?
thanks
brpalo
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 with the openapi-generator-maven-plugin configuration and the webclient library generation that produces the getDummy method. Trace how the OpenAPI response content types are represented in the generated method signature and compare them with the requested accept parameter. Done means documenting or implementing a supported way to pass the desired Accept header without duplicating it as an explicit OpenAPI header parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100