OpenAPITools / OpenAPITools/openapi-generator

[Announcement]Solution required : Generate client api to get Response header

Open
#11,061 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Announcement
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi Team

I am really not sure if its a Bug or new feature or I am missing anything.

I have defined the swagger in order to get the authorization token from the response header which can be used for next api call. However when I generate the client code out of swagger, it return only response body as null and not the header. I Have tried all the search but nothing was helpful.

Technology: Spring boot

Note: I have already raised the issue here but they asked me to raise under right repository. Link for the initial issue: https://github.com/OAI/OpenAPI-Specification/discussions/2815

Part of the swagger definition,

/token':
post:
tags:
- Token
parameters:
- $ref: '#/components/parameters/Authorization'
description: Used to generate token to call other api
operationId: generateToken
responses:
'200':
description: OK
headers:
authorization:
schema:
$ref: '#/components/securitySchemes/BearerAuth'

components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
parameters:
Authorization:
in: header
name: Authorization
description: Bearer token to access the one view API's.
schema:
type: string
required: true

Moreover, there is no response for this api, so the generated client api is throwing exception at catch block since return value is null. how can that be fixed?

try {
return CompletableFuture.completedFuture(
null
);
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}

My sample client generator config,

version used :
openapi.generator.version :4.3.1

org.openapitools openapi-generator-maven-plugin ${openapi.generator.version} XXX generate ${project.basedir}/src/main/resources/swagger-spec/client/XXX-api.yaml
          <generatorName>java</generatorName>
          <library>native</library>
          <output>${project.basedir}</output>
  
          <generateApis>true</generateApis>
          <generateApiTests>false</generateApiTests>
          <generateApiDocumentation>false</generateApiDocumentation>
          <generateModels>true</generateModels>
          <generateModelTests>false</generateModelTests>
          <generateModelDocumentation>false</generateModelDocumentation>
          <generateSupportingFiles>true</generateSupportingFiles>
          <apiPackage>XYZ</apiPackage>
          <invokerPackage>XYZ</invokerPackage>
          <modelPackage>XYZ</modelPackage>
          <addCompileSourceRoot>true</addCompileSourceRoot>
  
          <configOptions>
              <java8>true</java8>
              <dateLibrary>java8</dateLibrary>
              <delegatePattern>true</delegatePattern>
              <useBeanValidation>true</useBeanValidation>
              <performBeanValidation>true</performBeanValidation>
              <configPackage>XYZ</configPackage>
              <interfaceOnly>true</interfaceOnly>
              <sortParamsByRequiredFlag>false</sortParamsByRequiredFlag>
              <debugOperations>true</debugOperations>
              <debugModels>true</debugModels>
              <debugOpenAPI>true</debugOpenAPI>
              <asyncNative>true</asyncNative>
              <debugSupportingFiles>true</debugSupportingFiles>
          </configOptions>
      </configuration>
  </execution>

Please guide to resolve the issue as its blocking my work

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 Swagger YAML for XXX-api.yaml and the Maven generator configuration using OpenAPI Generator 4.3.1, then regenerate the native Java client and inspect generateToken. Done means the generated client exposes the authorization response header and handles the successful no-body response without failing because the return value is null.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.