Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Radha-rog opened this issue Dec 7, 2021 · 1 comment
Labels
Announcement Project/release related announcements

Comments

@Radha-rog
Copy link

Radha-rog commented Dec 7, 2021

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

@Radha-rog Radha-rog added the Announcement Project/release related announcements label Dec 7, 2021
@Laurens-W
Copy link
Contributor

You are using the wrong reference as a response header.
See https://swagger.io/specification/#components-object
And https://swagger.io/specification/#header-object

For example

401:
  description: unauthorized
  headers:
    authorization:
      $ref: '#/components/headers/authorizationHeader'

combined with

components:
  headers:
    authorizationHeader:
      description: desc
      schema:
        type: string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Announcement Project/release related announcements
Projects
None yet
Development

No branches or pull requests

2 participants