Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !11321

[typescript] Default auth method support and optional param object when all params optional

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/davidgamero/default-auth-method-support into master 3 years ago
  • Overview 0
  • Commits 23
  • Pipelines 0
  • Changes 30

Created by: davidgamero

Add an optional default?: SecurityAuthentication field to the AuthMethodsConfiguration type that populates a similarly typed optional field on the AuthMethods type. This enables passing a custom object satisfying the SecurityAuthentication interface for authentication purposes in the config either when a client is created or overriding at api call time via config param.

Also carry over optional singleParameter when all params optional from here

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov

Compare
  • master (base)

and
  • latest version
    b22e5b0c
    23 commits, 2 years ago

30 files
+ 762
- 276

    Preferences

    File browser
    Compare changes
modules/…/…/…‎/…/typescript‎
a‎pi‎
api.mu‎stache‎ +13 -5
au‎th‎
auth.m‎ustache‎ +12 -0
ty‎pes‎
ObjectParam‎API.mustache‎ +1 -1
samples/openapi3/…/‎…/typescript/builds‎
composed‎-schemas‎
ap‎is‎
Defaul‎tApi.ts‎ +18 -2
au‎th‎
aut‎h.ts‎ +3 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +3 -3
def‎ault‎
ap‎is‎
PetA‎pi.ts‎ +67 -26
Store‎Api.ts‎ +26 -5
UserA‎pi.ts‎ +61 -20
au‎th‎
aut‎h.ts‎ +3 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +2 -2
de‎no‎
ap‎is‎
PetA‎pi.ts‎ +67 -26
Store‎Api.ts‎ +26 -5
UserA‎pi.ts‎ +61 -20
au‎th‎
aut‎h.ts‎ +3 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +2 -2
inve‎rsify‎
ap‎is‎
PetA‎pi.ts‎ +35 -26
Store‎Api.ts‎ +10 -5
UserA‎pi.ts‎ +29 -20
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +2 -2
jqu‎ery‎
ap‎is‎
PetA‎pi.ts‎ +67 -26
Store‎Api.ts‎ +26 -5
UserA‎pi.ts‎ +61 -20
au‎th‎
aut‎h.ts‎ +3 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +2 -2
object‎_params‎
ap‎is‎
PetA‎pi.ts‎ +67 -26
Store‎Api.ts‎ +26 -5
UserA‎pi.ts‎ +61 -20
au‎th‎
aut‎h.ts‎ +3 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +2 -2
modules/openapi-generator/src/main/resources/typescript/api/api.mustache
+ 13
- 5
  • View file @ b22e5b0c

  • Edit in single-file editor

  • Open in Web IDE


// TODO: better import syntax?
import { BaseAPIRequestFactory, RequiredError } from './baseapi{{extensionForDeno}}';
import {BaseAPIRequestFactory, RequiredError} from './baseapi{{extensionForDeno}}';
import {Configuration} from '../configuration{{extensionForDeno}}';
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http{{extensionForDeno}}';
import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http{{extensionForDeno}}';
{{#platforms}}
{{#node}}
import * as FormData from "form-data";
@@ -11,6 +11,7 @@ import { URLSearchParams } from 'url';
import {ObjectSerializer} from '../models/ObjectSerializer{{extensionForDeno}}';
import {ApiException} from './exception{{extensionForDeno}}';
import {canConsumeForm, isCodeInRange} from '../util{{extensionForDeno}}';
import {SecurityAuthentication} from '../auth/auth';
{{#useInversify}}
import { injectable } from "inversify";
@@ -151,15 +152,22 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
{{/bodyParam}}
{{#hasAuthMethods}}
let authMethod = null;
let authMethod: SecurityAuthentication | undefined;
{{/hasAuthMethods}}
{{#authMethods}}
// Apply auth methods
authMethod = _config.authMethods["{{name}}"]
if (authMethod) {
await authMethod.applySecurityAuthentication(requestContext);
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
{{/authMethods}}
{{^useInversify}}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
{{/useInversify}}
return requestContext;
}
modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache
+ 12
- 0
  • View file @ b22e5b0c

  • Edit in single-file editor

  • Open in Web IDE


@@ -107,6 +107,9 @@ export class {{#lambda.pascalcase}}{{name}}{{/lambda.pascalcase}}Authentication
{{/authMethods}}
export type AuthMethods = {
{{^useInversify}}
"default"?: SecurityAuthentication,
{{/useInversify}}
{{#authMethods}}
"{{name}}"?: SecurityAuthentication{{^-last}},{{/-last}}
{{/authMethods}}
@@ -114,6 +117,9 @@ export type AuthMethods = {
{{#useInversify}}
export const authMethodServices = {
{{^useInversify}}
"default"?: SecurityAuthentication,
{{/useInversify}}
{{#authMethods}}
"{{name}}": {{#lambda.pascalcase}}{{name}}{{/lambda.pascalcase}}Authentication{{^-last}},{{/-last}}
{{/authMethods}}
@@ -126,6 +132,9 @@ export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
export type OAuth2Configuration = { accessToken: string };
export type AuthMethodsConfiguration = {
{{^useInversify}}
"default"?: SecurityAuthentication,
{{/useInversify}}
{{#authMethods}}
"{{name}}"?: {{#isApiKey}}ApiKeyConfiguration{{/isApiKey}}{{#isBasicBasic}}HttpBasicConfiguration{{/isBasicBasic}}{{#isBasicBearer}}HttpBearerConfiguration{{/isBasicBearer}}{{#isOAuth}}OAuth2Configuration{{/isOAuth}}{{^-last}},{{/-last}}
{{/authMethods}}
@@ -141,6 +150,9 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
if (!config) {
return authMethods;
}
{{^useInversify}}
authMethods["default"] = config["default"]
{{/useInversify}}
{{#authMethods}}
if (config["{{name}}"]) {
modules/openapi-generator/src/main/resources/typescript/types/ObjectParamAPI.mustache
+ 1
- 1
  • View file @ b22e5b0c

  • Edit in single-file editor

  • Open in Web IDE


@@ -47,7 +47,7 @@ export class Object{{classname}} {
{{/summary}}
* @param param the request object
*/
public {{nickname}}(param: {{classname}}{{operationIdCamelCase}}Request, options?: Configuration): {{#useRxJS}}Observable{{/useRxJS}}{{^useRxJS}}Promise{{/useRxJS}}<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
public {{nickname}}(param: {{classname}}{{operationIdCamelCase}}Request{{^hasRequiredParams}} = {}{{/hasRequiredParams}}, options?: Configuration): {{#useRxJS}}Observable{{/useRxJS}}{{^useRxJS}}Promise{{/useRxJS}}<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
return this.api.{{nickname}}({{#allParams}}param.{{paramName}}, {{/allParams}} options){{^useRxJS}}.toPromise(){{/useRxJS}};
}
samples/openapi3/client/petstore/typescript/builds/composed-schemas/apis/DefaultApi.ts
+ 18
- 2
  • View file @ b22e5b0c

  • Edit in single-file editor

  • Open in Web IDE


// TODO: better import syntax?
import { BaseAPIRequestFactory, RequiredError } from './baseapi';
import {BaseAPIRequestFactory, RequiredError} from './baseapi';
import {Configuration} from '../configuration';
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {canConsumeForm, isCodeInRange} from '../util';
import {SecurityAuthentication} from '../auth/auth';
import { Cat } from '../models/Cat';
@@ -44,6 +45,11 @@ export class DefaultApiRequestFactory extends BaseAPIRequestFactory {
);
requestContext.setBody(serializedBody);
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
@@ -74,6 +80,11 @@ export class DefaultApiRequestFactory extends BaseAPIRequestFactory {
);
requestContext.setBody(serializedBody);
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
@@ -104,6 +115,11 @@ export class DefaultApiRequestFactory extends BaseAPIRequestFactory {
);
requestContext.setBody(serializedBody);
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
samples/openapi3/client/petstore/typescript/builds/composed-schemas/auth/auth.ts
+ 3
- 0
  • View file @ b22e5b0c

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,6 +24,7 @@ export interface TokenProvider {
export type AuthMethods = {
"default"?: SecurityAuthentication,
}
export type ApiKeyConfiguration = string;
@@ -32,6 +33,7 @@ export type HttpBearerConfiguration = { tokenProvider: TokenProvider };
export type OAuth2Configuration = { accessToken: string };
export type AuthMethodsConfiguration = {
"default"?: SecurityAuthentication,
}
/**
@@ -44,6 +46,7 @@ export function configureAuthMethods(config: AuthMethodsConfiguration | undefine
if (!config) {
return authMethods;
}
authMethods["default"] = config["default"]
return authMethods;
}
\ No newline at end of file
0 Assignees
None
Assign to
0 Reviewers
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
Lock merge request
Unlocked
1
1 participant
Administrator
Reference:
Source branch: github/fork/davidgamero/default-auth-method-support

Menu

Explore Projects Groups Snippets