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

[BUG] Typescript client does not make use of auth configuration #9020

Closed
4 tasks done
neuroretransmit opened this issue Mar 19, 2021 · 1 comment
Closed
4 tasks done

Comments

@neuroretransmit
Copy link

neuroretransmit commented Mar 19, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
    • Any spec with the below security scheme should do
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
Description

Generated typescript client does not apply Authorization header.

openapi-generator version

5.0.1

OpenAPI declaration file content or url
...
components:
  securitySchemes:
    bearer-key:
      scheme: bearer
      type: apiKey
      name: Authorization
      in: header
Generation Details

Gradle plugin

task openApiTsClientGenerate(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
  generatorName = "typescript"
  inputSpec = "$openapiSpec"
  outputDir = "$openapiAxiosGeneratedDir"

  configOptions = [
    npmName: "@generated/ts-client",
    npmVersion: "${project.version}",
    title: "${project.name} TypeScript client"
  ]
}
Steps to reproduce

Specifying an Authorization header for auth doesn't appear to be applied request. The following will return 401 Unauthorized and no Authorization header is shown in the XHR request

OAS I used to find this bug.

components:
  securitySchemes:
    bearer-key:
      scheme: bearer
      type: apiKey
      name: Authorization
      in: header

Usage in project

import { UsersApi, createConfiguration, AuthMethodsConfiguration, server1 } from '@generated/ts-client';

const config = createConfiguration({ 
          baseServer: server1,
          authMethods: {
            "bearer-key": "Bearer " + authToken
          }
        });

// Using the following or passing config to individual requests will result in `401 Unauthorized`
const usersApi = new UsersApi(config);

A generated client method to show that auth configuration is unused

public async deletePost(postId: string, options?: Configuration): Promise<RequestContext> {
		let config = options || this.configuration;
		
        // verify required parameter 'postId' is not null or undefined
        if (postId === null || postId === undefined) {
            throw new RequiredError('Required parameter postId was null or undefined when calling deletePost.');
        }

		
		// Path Params
    	const localVarPath = '/posts/{postId}'
            .replace('{' + 'postId' + '}', encodeURIComponent(String(postId)));

		// Make Request Context
    	const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
        requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")

        // Query Params
	
		// Header Params
	
		// Form Params


		// Body Params

        // Apply auth methods

        return requestContext;
    }
Related issues/PRs

#4633

Suggest a fix

Still need to investigate, just a report for now.

@neuroretransmit neuroretransmit changed the title [BUG] Typescript client does not make use of configuration [BUG] Typescript client does not make use of auth configuration Mar 19, 2021
@neuroretransmit
Copy link
Author

Apologies, closing the issue. The securityScheme's name was mismatched between method and declaration. As long as they are equal it is generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant