Skip to content

Commit

Permalink
adding TweedBaseContext as required parameter in generated client
Browse files Browse the repository at this point in the history
  • Loading branch information
tomertweed committed Oct 30, 2024
1 parent 31aaf72 commit b807cc8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 21 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/client/interfaces/OperationParameter.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Model } from './Model';

export interface OperationParameter extends Model {
in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie';
in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie' | 'param';
prop: string;
mediaType: string | null;
}
21 changes: 21 additions & 0 deletions src/openApi/v2/parser/getOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ export const getOperation = (
});
}

operation.parameters.push({
name: 'context',
type: 'TweedBaseContext',
in: 'param',
base: 'TweedBaseContext',
description: 'Tweed context for context propagation',
export: 'generic',
isDefinition: false,
isNullable: false,
isReadOnly: false,
isRequired: true,
link: null,
mediaType: null,
prop: '',
properties: [],
enum: [],
enums: [],
imports: [],
template: null,
});

operation.parameters = operation.parameters.sort(sortByRequired);

return operation;
Expand Down
20 changes: 20 additions & 0 deletions src/openApi/v3/parser/getOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ export const getOperation = (
}

operation.parameters = operation.parameters.sort(sortByRequired);
operation.parameters.push({
name: 'context',
type: 'TweedBaseContext',
in: 'param',
base: 'TweedBaseContext',
description: 'Tweed context for context propagation',
export: 'generic',
isDefinition: false,
isNullable: false,
isReadOnly: false,
isRequired: true,
link: null,
mediaType: null,
prop: '',
properties: [],
enum: [],
enums: [],
imports: [],
template: null,
});

return operation;
};
6 changes: 4 additions & 2 deletions src/templates/core/ApiRequestOptions.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{>header}}
import { TweedBaseContext } from "@paytweed/context";


import { TweedBaseContext } from '@paytweed/context';

export type ApiRequestOptions = {
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
readonly url: string;
readonly context: TweedContext
readonly context: TweedBaseContext
readonly path?: Record<string, any>;
readonly cookies?: Record<string, any>;
readonly headers?: Record<string, any>;
Expand Down
4 changes: 2 additions & 2 deletions src/templates/core/BaseHttpRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ApiRequestOptions } from './ApiRequestOptions';
import type { OpenAPIConfig } from './OpenAPI';
{{else}}
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { CancelablePromise } from './CancelablePromise';
import { AxiosResponse } from '@paytweed/http-client';
import type { OpenAPIConfig } from './OpenAPI';
{{/equals}}

Expand All @@ -26,6 +26,6 @@ export abstract class BaseHttpRequest {
{{#equals @root.httpClient 'angular'}}
public abstract request<T>(options: ApiRequestOptions): Observable<T>;
{{else}}
public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
public abstract request<T>(options: ApiRequestOptions): Promise<AxiosResponse<T>>;
{{/equals}}
}
8 changes: 5 additions & 3 deletions src/templates/exportService.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import type { {{{this}}} } from '../models/{{{this}}}';

{{/if}}
{{#notEquals @root.httpClient 'angular'}}
import type { CancelablePromise } from '../core/CancelablePromise';
import { AxiosResponse } from '@paytweed/http-client';
import { TweedBaseContext } from '@paytweed/context';
{{/notEquals}}
{{#if @root.exportClient}}
{{#equals @root.httpClient 'angular'}}
Expand Down Expand Up @@ -75,20 +76,21 @@ export class {{{name}}}{{{@root.postfix}}} {
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
return this.httpRequest.request({
{{else}}
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
public {{{name}}}({{>parameters}}): Promise<AxiosResponse<{{>result}}>> {
return this.httpRequest.request({
{{/equals}}
{{else}}
{{#equals @root.httpClient 'angular'}}
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
return __request(OpenAPI, this.http, {
{{else}}
public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
public static {{{name}}}({{>parameters}}): Promise<AxiosResponse<{{>result}}>> {
return __request(OpenAPI, {
{{/equals}}
{{/if}}
method: '{{{method}}}',
url: '{{{path}}}',
context,
{{#if parametersPath}}
path: {
{{#each parametersPath}}
Expand Down

0 comments on commit b807cc8

Please sign in to comment.