Skip to content

Commit 500ba7d

Browse files
author
Максим Калин
committed
feat: add optional object in prop if all non required
1 parent 02c4b15 commit 500ba7d

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.27.0",
3+
"version": "0.27.1",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"homepage": "https://github.com/kimiyori/openapi-typescript-codegen",
66
"license": "MIT",
@@ -46,7 +46,6 @@
4646
"eslint:fix": "eslint . --fix",
4747
"prepare": "npm run clean && npm run release",
4848
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b",
49-
"docker": "docker build -t eeelenbaas/openapi-typescript-codegen .",
5049
"publish-to-nexus": "npm --no-git-tag-version version patch && npm publish"
5150
},
5251
"dependencies": {

rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const handlebarsPlugin = () => ({
3030
knownHelpersOnly: true,
3131
knownHelpers: {
3232
ifdef: true,
33+
isAnyRequired: true,
3334
equals: true,
3435
notEquals: true,
3536
containsSpaces: true,

src/templates/exportService.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class {{{name}}}{{{@root.postfix}}} {
7575
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
7676
return this.httpRequest.request({
7777
{{else}}
78-
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
78+
public {{{name}}}({{>parameters}}{{isAnyRequired parameters ' = {}'}}): CancelablePromise<{{>result}}> {
7979
return this.httpRequest.request({
8080
{{/equals}}
8181
{{else}}

src/utils/registerHandlebarHelpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Enum } from '../client/interfaces/Enum';
66
import type { Model } from '../client/interfaces/Model';
77
import type { HttpClient } from '../HttpClient';
88
import { unique } from './unique';
9+
import { OperationParameter } from '../client/interfaces/OperationParameter';
910

1011
export const registerHandlebarHelpers = (root: {
1112
httpClient: HttpClient;
@@ -19,7 +20,9 @@ export const registerHandlebarHelpers = (root: {
1920
}
2021
return options.inverse(this);
2122
});
22-
23+
Handlebars.registerHelper('isAnyRequired', (value: OperationParameter[], returnValue: string) => {
24+
return value.some(v => v.isRequired) ? '' : returnValue;
25+
});
2326
Handlebars.registerHelper(
2427
'equals',
2528
function (this: any, a: string, b: string, options: Handlebars.HelperOptions): string {

0 commit comments

Comments
 (0)