feat: add specs generator & fix body params #49

Merged
blas merged 2 commits from feat/add-specs into main 2026-03-26 10:33:08 +00:00
3 changed files with 17 additions and 12 deletions
Showing only changes of commit d47afb6ff1 - Show all commits

View File

@@ -271,7 +271,11 @@ export function generateCleanArchitecture(
let returnType = 'void';
let returnBaseType = 'void';
let isListContainer = false;
const responseSchema = op.responses?.['200']?.content?.['application/json']?.schema;
const successCode = ['200', '201', '202', '203'].find((code) => op.responses?.[code]);
const responseSchema =
successCode !== undefined
? op.responses?.[successCode]?.content?.['application/json']?.schema
: undefined;
if (responseSchema) {
if (responseSchema.$ref) {
returnType = responseSchema.$ref.split('/').pop() || 'unknown';
@@ -283,6 +287,9 @@ export function generateCleanArchitecture(
}
}
const hasQueryParams = (op.parameters || []).some((p) => p.in === 'query');
const hasBodyParam = !!op.requestBody;
tagsMap[tag].push({
nickname: op.operationId || `${method}${pathKey.replace(/\//g, '_')}`,
summary: op.summary || '',
@@ -294,15 +301,17 @@ export function generateCleanArchitecture(
...p,
'-last': i === allParams.length - 1
})),
hasQueryParams: (op.parameters || []).some((p) => p.in === 'query'),
hasQueryParams,
queryParams: (op.parameters || [])
.filter((p) => p.in === 'query')
.map((p, i: number, arr: unknown[]) => ({
paramName: p.name,
'-last': i === arr.length - 1
})),
hasBodyParam: !!op.requestBody,
hasBodyParam,
bodyParam: 'body',
hasOptions: hasQueryParams || hasBodyParam,
hasBothParamsAndBody: hasQueryParams && hasBodyParam,
returnType: returnType !== 'void' ? returnType : false,
returnBaseType: returnBaseType !== 'void' ? returnBaseType : false,
returnTypeVarName: returnType !== 'void' ? toCamelCase(returnType) : false,

View File

@@ -115,6 +115,8 @@ export interface TagOperation {
queryParams: unknown[];
hasBodyParam: boolean;
bodyParam: string;
hasOptions: boolean;
hasBothParamsAndBody: boolean;
returnType: string | boolean;
returnBaseType: string | boolean;
returnTypeVarName: string | boolean;

View File

@@ -32,26 +32,20 @@ export class {{classname}}RepositoryImpl extends MRepository implements {{classn
{{#operation}}
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{^-last}}, {{/-last}}{{/allParams}}): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
{{#isListContainer}}
return this.{{httpMethod}}<{{{returnBaseType}}}Dto>('{{path}}'{{#hasQueryParams}}, {
params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }
}{{/hasQueryParams}}{{#hasBodyParam}}, {{bodyParam}}{{/hasBodyParam}})
return this.{{httpMethod}}<{{{returnBaseType}}}Dto>('{{path}}'{{#hasOptions}}, { {{#hasQueryParams}}params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }{{/hasQueryParams}}{{#hasBothParamsAndBody}}, {{/hasBothParamsAndBody}}{{#hasBodyParam}}body{{/hasBodyParam}} }{{/hasOptions}})
.pipe(
map((response) => response.{{#vendorExtensions}}{{x-response-property}}{{/vendorExtensions}}{{^vendorExtensions}}items{{/vendorExtensions}}.map({{{returnBaseTypeVarName}}}Mapper))
);
{{/isListContainer}}
{{^isListContainer}}
{{#returnType}}
return this.{{httpMethod}}<{{{returnType}}}Dto>('{{path}}'{{#hasQueryParams}}, {
params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }
}{{/hasQueryParams}}{{#hasBodyParam}}, {{bodyParam}}{{/hasBodyParam}})
return this.{{httpMethod}}<{{{returnType}}}Dto>('{{path}}'{{#hasOptions}}, { {{#hasQueryParams}}params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }{{/hasQueryParams}}{{#hasBothParamsAndBody}}, {{/hasBothParamsAndBody}}{{#hasBodyParam}}body{{/hasBodyParam}} }{{/hasOptions}})
.pipe(
map({{{returnTypeVarName}}}Mapper)
);
{{/returnType}}
{{^returnType}}
return this.{{httpMethod}}<void>('{{path}}'{{#hasQueryParams}}, {
params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }
}{{/hasQueryParams}}{{#hasBodyParam}}, {{bodyParam}}{{/hasBodyParam}});
return this.{{httpMethod}}<void>('{{path}}'{{#hasOptions}}, { {{#hasQueryParams}}params: { {{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}} }{{/hasQueryParams}}{{#hasBothParamsAndBody}}, {{/hasBothParamsAndBody}}{{#hasBodyParam}}body{{/hasBodyParam}} }{{/hasOptions}});
{{/returnType}}
{{/isListContainer}}
}