Skip to content

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

Open
@Radha-rog

Description

@Radha-rog

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: OAI/OpenAPI-Specification#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnnouncementProject/release related announcements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions