From 998902e9d94c85a604a7725829dd42fe87da7dda Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Mon, 2 Oct 2023 19:35:40 +0200 Subject: [PATCH 01/12] Added config for each path. --- .gitignore | 1 + src/templates/core/ApiQuery.hbs | 5 +++++ src/templates/core/ApiResult.hbs | 2 +- src/templates/exportService.hbs | 4 ++++ src/utils/registerHandlebarTemplates.ts | 17 ++++++++++------- src/utils/writeClientCore.ts | 1 + src/utils/writeClientServices.ts | 1 + 7 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 src/templates/core/ApiQuery.hbs diff --git a/.gitignore b/.gitignore index 2b7422568..33028cc75 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ test/e2e/generated samples/generated samples/swagger-codegen-cli-v2.jar samples/swagger-codegen-cli-v3.jar +temp \ No newline at end of file diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs new file mode 100644 index 000000000..5e1abb6be --- /dev/null +++ b/src/templates/core/ApiQuery.hbs @@ -0,0 +1,5 @@ +{{>header}} + +export type ApiQuery = { + readonly path: string; +}; \ No newline at end of file diff --git a/src/templates/core/ApiResult.hbs b/src/templates/core/ApiResult.hbs index a768b8c5a..501c25708 100644 --- a/src/templates/core/ApiResult.hbs +++ b/src/templates/core/ApiResult.hbs @@ -6,4 +6,4 @@ export type ApiResult = { readonly status: number; readonly statusText: string; readonly body: any; -}; +}; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index d6bccbbeb..4c8353f79 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -1,5 +1,6 @@ {{>header}} +import type { ApiQuery } from '../core/ApiQuery' {{#equals @root.httpClient 'angular'}} {{#if @root.exportClient}} import { Injectable } from '@angular/core'; @@ -48,6 +49,9 @@ export class {{{name}}}{{{@root.postfix}}} { {{/if}} {{#each operations}} + static {{{name}}}Options: ApiQuery<{{>result}}> = { + path: '{{path}}', + } /** {{#if deprecated}} * @deprecated diff --git a/src/utils/registerHandlebarTemplates.ts b/src/utils/registerHandlebarTemplates.ts index bf77cbdc1..ec153735f 100644 --- a/src/utils/registerHandlebarTemplates.ts +++ b/src/utils/registerHandlebarTemplates.ts @@ -2,23 +2,26 @@ import Handlebars from 'handlebars/runtime'; import { HttpClient } from '../HttpClient'; import templateClient from '../templates/client.hbs'; +import templateCoreApiError from '../templates/core/ApiError.hbs'; +import templateCoreApiQuery from '../templates/core/ApiQuery.hbs'; +import templateCoreApiRequestOptions from '../templates/core/ApiRequestOptions.hbs'; +import templateCoreApiResult from '../templates/core/ApiResult.hbs'; +import templateCoreBaseHttpRequest from '../templates/core/BaseHttpRequest.hbs'; +import templateCancelablePromise from '../templates/core/CancelablePromise.hbs'; +import templateCoreHttpRequest from '../templates/core/HttpRequest.hbs'; +import templateCoreSettings from '../templates/core/OpenAPI.hbs'; import angularGetHeaders from '../templates/core/angular/getHeaders.hbs'; import angularGetRequestBody from '../templates/core/angular/getRequestBody.hbs'; import angularGetResponseBody from '../templates/core/angular/getResponseBody.hbs'; import angularGetResponseHeader from '../templates/core/angular/getResponseHeader.hbs'; import angularRequest from '../templates/core/angular/request.hbs'; import angularSendRequest from '../templates/core/angular/sendRequest.hbs'; -import templateCoreApiError from '../templates/core/ApiError.hbs'; -import templateCoreApiRequestOptions from '../templates/core/ApiRequestOptions.hbs'; -import templateCoreApiResult from '../templates/core/ApiResult.hbs'; import axiosGetHeaders from '../templates/core/axios/getHeaders.hbs'; import axiosGetRequestBody from '../templates/core/axios/getRequestBody.hbs'; import axiosGetResponseBody from '../templates/core/axios/getResponseBody.hbs'; import axiosGetResponseHeader from '../templates/core/axios/getResponseHeader.hbs'; import axiosRequest from '../templates/core/axios/request.hbs'; import axiosSendRequest from '../templates/core/axios/sendRequest.hbs'; -import templateCoreBaseHttpRequest from '../templates/core/BaseHttpRequest.hbs'; -import templateCancelablePromise from '../templates/core/CancelablePromise.hbs'; import fetchGetHeaders from '../templates/core/fetch/getHeaders.hbs'; import fetchGetRequestBody from '../templates/core/fetch/getRequestBody.hbs'; import fetchGetResponseBody from '../templates/core/fetch/getResponseBody.hbs'; @@ -37,14 +40,12 @@ import functionIsString from '../templates/core/functions/isString.hbs'; import functionIsStringWithValue from '../templates/core/functions/isStringWithValue.hbs'; import functionIsSuccess from '../templates/core/functions/isSuccess.hbs'; import functionResolve from '../templates/core/functions/resolve.hbs'; -import templateCoreHttpRequest from '../templates/core/HttpRequest.hbs'; import nodeGetHeaders from '../templates/core/node/getHeaders.hbs'; import nodeGetRequestBody from '../templates/core/node/getRequestBody.hbs'; import nodeGetResponseBody from '../templates/core/node/getResponseBody.hbs'; import nodeGetResponseHeader from '../templates/core/node/getResponseHeader.hbs'; import nodeRequest from '../templates/core/node/request.hbs'; import nodeSendRequest from '../templates/core/node/sendRequest.hbs'; -import templateCoreSettings from '../templates/core/OpenAPI.hbs'; import templateCoreRequest from '../templates/core/request.hbs'; import xhrGetHeaders from '../templates/core/xhr/getHeaders.hbs'; import xhrGetRequestBody from '../templates/core/xhr/getRequestBody.hbs'; @@ -98,6 +99,7 @@ export interface Templates { apiError: Handlebars.TemplateDelegate; apiRequestOptions: Handlebars.TemplateDelegate; apiResult: Handlebars.TemplateDelegate; + apiQuery: Handlebars.TemplateDelegate, cancelablePromise: Handlebars.TemplateDelegate; request: Handlebars.TemplateDelegate; baseHttpRequest: Handlebars.TemplateDelegate; @@ -130,6 +132,7 @@ export const registerHandlebarTemplates = (root: { apiError: Handlebars.template(templateCoreApiError), apiRequestOptions: Handlebars.template(templateCoreApiRequestOptions), apiResult: Handlebars.template(templateCoreApiResult), + apiQuery: Handlebars.template(templateCoreApiQuery), cancelablePromise: Handlebars.template(templateCancelablePromise), request: Handlebars.template(templateCoreRequest), baseHttpRequest: Handlebars.template(templateCoreBaseHttpRequest), diff --git a/src/utils/writeClientCore.ts b/src/utils/writeClientCore.ts index 6d35849d2..f3767e393 100644 --- a/src/utils/writeClientCore.ts +++ b/src/utils/writeClientCore.ts @@ -41,6 +41,7 @@ export const writeClientCore = async ( await writeFile(resolve(outputPath, 'ApiError.ts'), i(templates.core.apiError(context), indent)); await writeFile(resolve(outputPath, 'ApiRequestOptions.ts'), i(templates.core.apiRequestOptions(context), indent)); await writeFile(resolve(outputPath, 'ApiResult.ts'), i(templates.core.apiResult(context), indent)); + await writeFile(resolve(outputPath, 'ApiQuery.ts'), i(templates.core.apiQuery(context), indent)); await writeFile(resolve(outputPath, 'CancelablePromise.ts'), i(templates.core.cancelablePromise(context), indent)); await writeFile(resolve(outputPath, 'request.ts'), i(templates.core.request(context), indent)); diff --git a/src/utils/writeClientServices.ts b/src/utils/writeClientServices.ts index 2f95341d2..bea0dc581 100644 --- a/src/utils/writeClientServices.ts +++ b/src/utils/writeClientServices.ts @@ -33,6 +33,7 @@ export const writeClientServices = async ( clientName?: string ): Promise => { for (const service of services) { + console.log(service) const file = resolve(outputPath, `${service.name}${postfix}.ts`); const templateResult = templates.exports.service({ ...service, From cc01bf9d951d6156729cd60eaf20149831bd4694 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Mon, 2 Oct 2023 19:56:08 +0200 Subject: [PATCH 02/12] Added more meta. --- src/templates/core/ApiQuery.hbs | 6 +++++- src/templates/exportService.hbs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs index 5e1abb6be..fd6b26182 100644 --- a/src/templates/core/ApiQuery.hbs +++ b/src/templates/core/ApiQuery.hbs @@ -1,5 +1,9 @@ {{>header}} -export type ApiQuery = { +export type ApiQuery = { readonly path: string; + readonly method: string; + readonly name: string; + readonly inputs: string[]; + params?: R }; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index 4c8353f79..89e78b096 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -37,6 +37,15 @@ import { request as __request } from '../core/request'; providedIn: 'root', }) {{/equals}} + +{{#each operations}} +export type {{{name}}}Input = { + {{#each parameters}} + {{{name}}}{{>isRequired}}: {{>type}} + {{/each}} +} +{{/each}} + export class {{{name}}}{{{@root.postfix}}} { {{#if @root.exportClient}} @@ -49,8 +58,15 @@ export class {{{name}}}{{{@root.postfix}}} { {{/if}} {{#each operations}} - static {{{name}}}Options: ApiQuery<{{>result}}> = { + static {{{name}}}Options: ApiQuery<{{>result}}, {{{name}}}Input> = { path: '{{path}}', + method: '{{method}}', + name: '{{name}}', + inputs: [ + {{#each parameters}} + '{{{name}}}', + {{/each}} + ] } /** {{#if deprecated}} From 74d63cd61acf9147c004e1f1ea35a203e8d7b528 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Mon, 2 Oct 2023 20:11:34 +0200 Subject: [PATCH 03/12] Added param translator. --- src/templates/core/ApiQuery.hbs | 3 ++- src/templates/exportService.hbs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs index fd6b26182..cf7bc2001 100644 --- a/src/templates/core/ApiQuery.hbs +++ b/src/templates/core/ApiQuery.hbs @@ -5,5 +5,6 @@ export type ApiQuery = { readonly method: string; readonly name: string; readonly inputs: string[]; - params?: R + readonly paramTranslator: { [key: string]: string } + params?: R; }; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index 89e78b096..50fddf48d 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -66,7 +66,12 @@ export class {{{name}}}{{{@root.postfix}}} { {{#each parameters}} '{{{name}}}', {{/each}} - ] + ], + paramTranslator: { + {{#each parametersQuery}} + '{{{name}}}': '{{{prop}}}', + {{/each}} + } } /** {{#if deprecated}} From 3429fc4e094b5860e85fb4617aeab853e295dd91 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Wed, 4 Oct 2023 08:02:19 +0200 Subject: [PATCH 04/12] Added path params to translator. --- src/templates/exportService.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index 50fddf48d..f73b6e1e6 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -71,6 +71,9 @@ export class {{{name}}}{{{@root.postfix}}} { {{#each parametersQuery}} '{{{name}}}': '{{{prop}}}', {{/each}} + {{#each parametersPath}} + '{{{name}}}': '{{{prop}}}', + {{/each}} } } /** From 89a425d5563fd08a7b343d150ed998141311aa17 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Wed, 4 Oct 2023 08:49:52 +0200 Subject: [PATCH 05/12] Added query and path params. --- src/templates/core/ApiQuery.hbs | 5 +++-- src/templates/exportService.hbs | 32 +++++++++++++++++++++++++++----- src/utils/writeClientServices.ts | 4 +++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs index cf7bc2001..8237fe854 100644 --- a/src/templates/core/ApiQuery.hbs +++ b/src/templates/core/ApiQuery.hbs @@ -1,10 +1,11 @@ {{>header}} export type ApiQuery = { - readonly path: string; + readonly url: string; readonly method: string; readonly name: string; readonly inputs: string[]; - readonly paramTranslator: { [key: string]: string } + readonly query?: { [key: string]: string } + readonly path?: { [key: string]: string } params?: R; }; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index f73b6e1e6..e8f881e30 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -40,9 +40,23 @@ import { request as __request } from '../core/request'; {{#each operations}} export type {{{name}}}Input = { - {{#each parameters}} - {{{name}}}{{>isRequired}}: {{>type}} - {{/each}} + {{#if parametersQuery}} + query: { + {{#each parametersQuery}} + {{{name}}}{{>isRequired}}: {{>type}} + {{/each}} + }, + {{/if}} + {{#if parametersPath}} + path: { + {{#each parametersPath}} + {{{name}}}{{>isRequired}}: {{>type}} + {{/each}} + }, + {{/if}} + {{#if parametersBody}} + body: {{>type parametersBody}}, + {{/if}} } {{/each}} @@ -58,8 +72,9 @@ export class {{{name}}}{{{@root.postfix}}} { {{/if}} {{#each operations}} + static {{{name}}}Options: ApiQuery<{{>result}}, {{{name}}}Input> = { - path: '{{path}}', + url: '{{path}}', method: '{{method}}', name: '{{name}}', inputs: [ @@ -67,15 +82,22 @@ export class {{{name}}}{{{@root.postfix}}} { '{{{name}}}', {{/each}} ], - paramTranslator: { + {{#if parametersQuery}} + query: { {{#each parametersQuery}} '{{{name}}}': '{{{prop}}}', {{/each}} + }, + {{/if}} + {{#if parametersPath}} + path: { {{#each parametersPath}} '{{{name}}}': '{{{prop}}}', {{/each}} } + {{/if}} } + /** {{#if deprecated}} * @deprecated diff --git a/src/utils/writeClientServices.ts b/src/utils/writeClientServices.ts index bea0dc581..c0f2fc4b5 100644 --- a/src/utils/writeClientServices.ts +++ b/src/utils/writeClientServices.ts @@ -33,7 +33,9 @@ export const writeClientServices = async ( clientName?: string ): Promise => { for (const service of services) { - console.log(service) + service.operations.map(o => { + console.log(o.parametersBody) + }) const file = resolve(outputPath, `${service.name}${postfix}.ts`); const templateResult = templates.exports.service({ ...service, From e62baae9b6547911f66a72e37b625dde8869cf02 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Wed, 4 Oct 2023 08:54:02 +0200 Subject: [PATCH 06/12] Reversed props. --- src/templates/exportService.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index e8f881e30..b15c4e262 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -85,14 +85,14 @@ export class {{{name}}}{{{@root.postfix}}} { {{#if parametersQuery}} query: { {{#each parametersQuery}} - '{{{name}}}': '{{{prop}}}', + '{{{prop}}}': '{{{name}}}', {{/each}} }, {{/if}} {{#if parametersPath}} path: { {{#each parametersPath}} - '{{{name}}}': '{{{prop}}}', + '{{{prop}}}': '{{{name}}}', {{/each}} } {{/if}} From e6bdb10f16639a6ef0c51dc2bbd9dbe08a2da8eb Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Fri, 13 Oct 2023 11:21:44 +0200 Subject: [PATCH 07/12] Added title to models. --- src/client/interfaces/Model.d.ts | 1 + src/openApi/v3/parser/getModel.ts | 3 +++ src/openApi/v3/parser/getModelProperties.ts | 1 + src/templates/partials/schemaEnum.hbs | 11 +++++++++++ src/templates/partials/schemaGeneric.hbs | 3 +++ src/templates/partials/schemaInterface.hbs | 3 +++ src/utils/writeClientSchemas.ts | 5 +++++ src/utils/writeClientServices.ts | 4 +++- 8 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/client/interfaces/Model.d.ts b/src/client/interfaces/Model.d.ts index 5f0318942..7eb96b7e1 100644 --- a/src/client/interfaces/Model.d.ts +++ b/src/client/interfaces/Model.d.ts @@ -8,6 +8,7 @@ export interface Model extends Schema { base: string; template: string | null; link: Model | null; + title: string | null; description: string | null; deprecated?: boolean; default?: string; diff --git a/src/openApi/v3/parser/getModel.ts b/src/openApi/v3/parser/getModel.ts index 9e9c60a98..2e361f635 100644 --- a/src/openApi/v3/parser/getModel.ts +++ b/src/openApi/v3/parser/getModel.ts @@ -22,6 +22,7 @@ export const getModel = ( base: 'any', template: null, link: null, + title: definition.title || null, description: definition.description || null, deprecated: definition.deprecated === true, isDefinition, @@ -62,12 +63,14 @@ export const getModel = ( if (definition.enum && definition.type !== 'boolean') { const enumerators = getEnum(definition.enum); const extendedEnumerators = extendEnum(enumerators, definition); + if (extendedEnumerators.length) { model.export = 'enum'; model.type = 'string'; model.base = 'string'; model.enum.push(...extendedEnumerators); model.default = getModelDefault(definition, model); + return model; } } diff --git a/src/openApi/v3/parser/getModelProperties.ts b/src/openApi/v3/parser/getModelProperties.ts index 6e25ca833..c27b9c36e 100644 --- a/src/openApi/v3/parser/getModelProperties.ts +++ b/src/openApi/v3/parser/getModelProperties.ts @@ -36,6 +36,7 @@ export const getModelProperties = ( | 'properties' > = { name: escapeName(propertyName), + title: property.title || null, description: property.description || null, deprecated: property.deprecated === true, isDefinition: false, diff --git a/src/templates/partials/schemaEnum.hbs b/src/templates/partials/schemaEnum.hbs index eaba3fc5f..3467ce55c 100644 --- a/src/templates/partials/schemaEnum.hbs +++ b/src/templates/partials/schemaEnum.hbs @@ -9,4 +9,15 @@ {{#if isNullable}} isNullable: {{{isNullable}}}, {{/if}} +{{#if enum}} + enums: [ + {{#each enum}} + { + name: '{{{name}}}', + type: '{{{type}}}', + value: {{{value}}}, + }, + {{/each}} + ], +{{/if}} } diff --git a/src/templates/partials/schemaGeneric.hbs b/src/templates/partials/schemaGeneric.hbs index 23580a673..0aa380c1d 100644 --- a/src/templates/partials/schemaGeneric.hbs +++ b/src/templates/partials/schemaGeneric.hbs @@ -2,6 +2,9 @@ {{#if type}} type: '{{{type}}}', {{/if}} +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if description}} description: `{{{escapeDescription description}}}`, {{/if}} diff --git a/src/templates/partials/schemaInterface.hbs b/src/templates/partials/schemaInterface.hbs index 3417c5fb9..ef52efe09 100644 --- a/src/templates/partials/schemaInterface.hbs +++ b/src/templates/partials/schemaInterface.hbs @@ -1,4 +1,7 @@ { +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if description}} description: `{{{escapeDescription description}}}`, {{/if}} diff --git a/src/utils/writeClientSchemas.ts b/src/utils/writeClientSchemas.ts index e1c885f64..79c5ea5d1 100644 --- a/src/utils/writeClientSchemas.ts +++ b/src/utils/writeClientSchemas.ts @@ -26,6 +26,11 @@ export const writeClientSchemas = async ( indent: Indent ): Promise => { for (const model of models) { + //console.log(model) + if (model.name === 'JaxMetaType') { + console.log(model) + } + const file = resolve(outputPath, `$${model.name}.ts`); const templateResult = templates.exports.schema({ ...model, diff --git a/src/utils/writeClientServices.ts b/src/utils/writeClientServices.ts index c0f2fc4b5..3f809c269 100644 --- a/src/utils/writeClientServices.ts +++ b/src/utils/writeClientServices.ts @@ -33,9 +33,11 @@ export const writeClientServices = async ( clientName?: string ): Promise => { for (const service of services) { + /* service.operations.map(o => { - console.log(o.parametersBody) + console.log(o) }) + */ const file = resolve(outputPath, `${service.name}${postfix}.ts`); const templateResult = templates.exports.service({ ...service, From 13ddaff94c7316bd42bf94c74522cf2b9cd632c3 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Fri, 13 Oct 2023 11:25:48 +0200 Subject: [PATCH 08/12] Fixed int enums. --- src/templates/partials/schemaEnum.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/partials/schemaEnum.hbs b/src/templates/partials/schemaEnum.hbs index 3467ce55c..10230e631 100644 --- a/src/templates/partials/schemaEnum.hbs +++ b/src/templates/partials/schemaEnum.hbs @@ -13,7 +13,7 @@ enums: [ {{#each enum}} { - name: '{{{name}}}', + name: "{{{name}}}", type: '{{{type}}}', value: {{{value}}}, }, From bc01faa7aa1cb0ec79b14a385c17f0e5dfe1487a Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Fri, 13 Oct 2023 11:46:29 +0200 Subject: [PATCH 09/12] Added more title to models. --- src/templates/partials/schemaArray.hbs | 3 +++ src/templates/partials/schemaComposition.hbs | 3 +++ src/templates/partials/schemaDictionary.hbs | 3 +++ src/templates/partials/schemaEnum.hbs | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/templates/partials/schemaArray.hbs b/src/templates/partials/schemaArray.hbs index 44871265b..a3f33d013 100644 --- a/src/templates/partials/schemaArray.hbs +++ b/src/templates/partials/schemaArray.hbs @@ -7,6 +7,9 @@ type: '{{{base}}}', }, {{/if}} +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if isReadOnly}} isReadOnly: {{{isReadOnly}}}, {{/if}} diff --git a/src/templates/partials/schemaComposition.hbs b/src/templates/partials/schemaComposition.hbs index 050f6696d..06580cfb9 100644 --- a/src/templates/partials/schemaComposition.hbs +++ b/src/templates/partials/schemaComposition.hbs @@ -1,5 +1,8 @@ { type: '{{export}}', +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if description}} description: `{{{escapeDescription description}}}`, {{/if}} diff --git a/src/templates/partials/schemaDictionary.hbs b/src/templates/partials/schemaDictionary.hbs index 1e755f7af..61d7857ca 100644 --- a/src/templates/partials/schemaDictionary.hbs +++ b/src/templates/partials/schemaDictionary.hbs @@ -7,6 +7,9 @@ type: '{{{base}}}', }, {{/if}} +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if isReadOnly}} isReadOnly: {{{isReadOnly}}}, {{/if}} diff --git a/src/templates/partials/schemaEnum.hbs b/src/templates/partials/schemaEnum.hbs index 10230e631..21df29b03 100644 --- a/src/templates/partials/schemaEnum.hbs +++ b/src/templates/partials/schemaEnum.hbs @@ -1,5 +1,8 @@ { type: 'Enum', +{{#if title}} + title: `{{{escapeDescription title}}}`, +{{/if}} {{#if isReadOnly}} isReadOnly: {{{isReadOnly}}}, {{/if}} From 856e111f325c27965d99a8f8959a7f617f90d3a3 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Fri, 13 Oct 2023 12:28:01 +0200 Subject: [PATCH 10/12] Removed functions. --- src/templates/core/ApiQuery.hbs | 1 + src/templates/exportService.hbs | 105 ++----------------------------- src/utils/writeClientServices.ts | 16 +++-- 3 files changed, 16 insertions(+), 106 deletions(-) diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs index 8237fe854..634f5d14e 100644 --- a/src/templates/core/ApiQuery.hbs +++ b/src/templates/core/ApiQuery.hbs @@ -8,4 +8,5 @@ export type ApiQuery = { readonly query?: { [key: string]: string } readonly path?: { [key: string]: string } params?: R; + readonly bodyJsonModel?: string; }; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index b15c4e262..c2f4a4914 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -94,108 +94,11 @@ export class {{{name}}}{{{@root.postfix}}} { {{#each parametersPath}} '{{{prop}}}': '{{{name}}}', {{/each}} - } + }, + {{/if}} + {{#if parametersBody}} + bodyJsonModel: '${{>type parametersBody}}', {{/if}} - } - - /** - {{#if deprecated}} - * @deprecated - {{/if}} - {{#if summary}} - * {{{escapeComment summary}}} - {{/if}} - {{#if description}} - * {{{escapeComment description}}} - {{/if}} - {{#unless @root.useOptions}} - {{#if parameters}} - {{#each parameters}} - * @param {{{name}}} {{#if description}}{{{escapeComment description}}}{{/if}} - {{/each}} - {{/if}} - {{/unless}} - {{#each results}} - * @returns {{{type}}} {{#if description}}{{{escapeComment description}}}{{/if}} - {{/each}} - * @throws ApiError - */ - {{#if @root.exportClient}} - {{#equals @root.httpClient 'angular'}} - public {{{name}}}({{>parameters}}): Observable<{{>result}}> { - return this.httpRequest.request({ - {{else}} - public {{{name}}}({{>parameters}}): CancelablePromise<{{>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}}> { - return __request(OpenAPI, { - {{/equals}} - {{/if}} - method: '{{{method}}}', - url: '{{{path}}}', - {{#if parametersPath}} - path: { - {{#each parametersPath}} - '{{{prop}}}': {{{name}}}, - {{/each}} - }, - {{/if}} - {{#if parametersCookie}} - cookies: { - {{#each parametersCookie}} - '{{{prop}}}': {{{name}}}, - {{/each}} - }, - {{/if}} - {{#if parametersHeader}} - headers: { - {{#each parametersHeader}} - '{{{prop}}}': {{{name}}}, - {{/each}} - }, - {{/if}} - {{#if parametersQuery}} - query: { - {{#each parametersQuery}} - '{{{prop}}}': {{{name}}}, - {{/each}} - }, - {{/if}} - {{#if parametersForm}} - formData: { - {{#each parametersForm}} - '{{{prop}}}': {{{name}}}, - {{/each}} - }, - {{/if}} - {{#if parametersBody}} - {{#equals parametersBody.in 'formData'}} - formData: {{{parametersBody.name}}}, - {{/equals}} - {{#equals parametersBody.in 'body'}} - body: {{{parametersBody.name}}}, - {{/equals}} - {{#if parametersBody.mediaType}} - mediaType: '{{{parametersBody.mediaType}}}', - {{/if}} - {{/if}} - {{#if responseHeader}} - responseHeader: '{{{responseHeader}}}', - {{/if}} - {{#if errors}} - errors: { - {{#each errors}} - {{{code}}}: `{{{escapeDescription description}}}`, - {{/each}} - }, - {{/if}} - }); } {{/each}} diff --git a/src/utils/writeClientServices.ts b/src/utils/writeClientServices.ts index 3f809c269..2f6afbdcf 100644 --- a/src/utils/writeClientServices.ts +++ b/src/utils/writeClientServices.ts @@ -33,11 +33,17 @@ export const writeClientServices = async ( clientName?: string ): Promise => { for (const service of services) { - /* - service.operations.map(o => { - console.log(o) - }) - */ + if (service.name === 'Meta') { + console.log(service) + /* + service.operations.map(o => { + console.log(o.name) + console.log(o.parametersBody) + }) + */ + } + + const file = resolve(outputPath, `${service.name}${postfix}.ts`); const templateResult = templates.exports.service({ ...service, From 12d7ff865e8a59f2e27bfa6b5a86f7ef2779b082 Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Tue, 17 Oct 2023 13:13:13 +0200 Subject: [PATCH 11/12] Added output json model. --- src/templates/core/ApiQuery.hbs | 1 + src/templates/exportService.hbs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/templates/core/ApiQuery.hbs b/src/templates/core/ApiQuery.hbs index 634f5d14e..5ddddc163 100644 --- a/src/templates/core/ApiQuery.hbs +++ b/src/templates/core/ApiQuery.hbs @@ -9,4 +9,5 @@ export type ApiQuery = { readonly path?: { [key: string]: string } params?: R; readonly bodyJsonModel?: string; + readonly outputJsonModel?: string; }; \ No newline at end of file diff --git a/src/templates/exportService.hbs b/src/templates/exportService.hbs index c2f4a4914..ff61fa6d3 100644 --- a/src/templates/exportService.hbs +++ b/src/templates/exportService.hbs @@ -99,6 +99,7 @@ export class {{{name}}}{{{@root.postfix}}} { {{#if parametersBody}} bodyJsonModel: '${{>type parametersBody}}', {{/if}} + outputJsonModel: '${{>result}}', } {{/each}} From 88b02565f57958c64d041f0cfd096902ca52484f Mon Sep 17 00:00:00 2001 From: Kristian Grimsby Date: Tue, 25 Jun 2024 11:47:22 +0200 Subject: [PATCH 12/12] Made readonly optoinal always. --- src/templates/partials/exportInterface.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/partials/exportInterface.hbs b/src/templates/partials/exportInterface.hbs index b61e26441..d0034765d 100644 --- a/src/templates/partials/exportInterface.hbs +++ b/src/templates/partials/exportInterface.hbs @@ -20,7 +20,7 @@ export type {{{name}}} = { {{/if}} */ {{/ifdef}} - {{>isReadOnly}}{{{name}}}{{>isRequired}}: {{>type parent=../name}}; + {{>isReadOnly}}{{{name}}}{{#if isReadOnly}}?{{else}}{{>isRequired}}{{/if}}: {{>type parent=../name}}; {{/each}} }; {{#if enums}}