OpenAPITools / OpenAPITools/openapi-generator
Generated code doen't have any information about response headers
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I have following open api specification description:
openapi: 3.0.3
...
/foo:
get:
operationId: foo
parameters:
- name: bar
in: query
required: true
schema:
type: string
responses:
200:
description: description
content:
application/json:
schema:
type: array
items:
type: string
headers:
myheader1:
description: myheader1 desc
schema:
type: string
myheader2:
description: myheader2 desc
schema:
type: integer
401:
description: "Unauthorized"
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
The generated code is:
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-01-24T14:16:01.056664+03:00[Europe/London]")
@Validated
@Tag(name = "Default", description = "the Default API")
@RequestMapping("${openapi.directoryServiceManager.base-path:/api/v1}")
public interface DefaultApi {
/**
* GET /foo
*
* @param bar (required)
* @return description (status code 200)
* or Unauthorized (status code 401)
*/
@Operation(
operationId = "foo",
responses = {
@ApiResponse(responseCode = "200", description = "description", content = {
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = String.class)))
}),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDto.class))
})
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/foo",
produces = { "application/json" }
)
ResponseEntity<List<String>> foo(
@NotNull
@Parameter(name = "bar", description = "", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "bar", required = true) String bar
);
}
As you can see where is no information about response headers(myheader1 and myheader2)
I would expect that
ApiResponse should have headers argument added
Is there way to fix it ?
More information about environment:
buildscript {
dependencies {
classpath("org.openapitools:openapi-generator-gradle-plugin:5.0.0")
}
}
plugins {
java
kotlin("jvm")
kotlin("plugin.spring") version "1.8.21"
id("org.springframework.boot") version "3.1.4"
id("org.openapi.generator") version "6.3.0"
}
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
The issue provides an OpenAPI example and generated SpringCodegen interface; start by regenerating that example and tracing how response annotations are produced. Verify completion by checking that myheader1 and myheader2 appear in the generated @ApiResponse headers metadata, including their string and integer schemas.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100