@@ -19,12 +19,7 @@ import {
1919 Node ,
2020} from 'ts-morph' ;
2121import { registerTypesFromSchema , schemaToType } from './process-schema.js' ;
22- import {
23- getDependents ,
24- maybeJsDocDescription ,
25- pascalCase ,
26- wordWrap ,
27- } from './utils.js' ;
22+ import { getDependents , pascalCase , wordWrap } from './utils.js' ;
2823
2924// the union/intersect helpers keep typescript happy due to ts-morph typings
3025function createIntersection ( ...types : ( string | undefined ) [ ] ) {
@@ -99,15 +94,6 @@ export async function processOpenApiDocument(
9994 moduleSpecifier : '@block65/rest-client' ,
10095 } ) ;
10196
102- commandsFile . addImportDeclaration ( {
103- namedImports : [
104- // legacy request method functions
105- 'RequestMethodCaller' ,
106- ] ,
107- moduleSpecifier : '@block65/rest-client' ,
108- isTypeOnly : true ,
109- } ) ;
110-
11197 commandsFile . addImportDeclaration ( {
11298 namedImports : [ 'Jsonifiable' ] ,
11399 moduleSpecifier : 'type-fest' ,
@@ -209,21 +195,14 @@ export async function processOpenApiDocument(
209195 typeof operationObject === 'object' &&
210196 'operationId' in operationObject
211197 ) {
212- /** @deprecated */
213- const func = commandsFile . addFunction ( {
214- name : camelcase (
215- `${ operationObject . operationId . replace ( / c o m m a n d $ / i, '' ) } Command` ,
216- ) ,
217- isExported : true ,
218- isAsync : false ,
219- } ) ;
220-
221198 const pathParameterNames : string [ ] = [ ] ;
222199
200+ const operationId = pascalCase (
201+ `${ operationObject . operationId . replace ( / c o m m a n d $ / i, '' ) } Command` ,
202+ ) ;
203+
223204 const classDeclaration = commandsFile . addClass ( {
224- name : pascalCase (
225- `${ operationObject . operationId . replace ( / c o m m a n d $ / i, '' ) } Command` ,
226- ) ,
205+ name : operationId ,
227206 isExported : true ,
228207 extends : 'Command' ,
229208 properties : [
@@ -241,8 +220,8 @@ export async function processOpenApiDocument(
241220
242221 const jsDocStructure = {
243222 description : `\n${ wordWrap (
244- operationObject . description || operationObject . operationId ,
245- ) } \n\n `,
223+ operationObject . description || operationId ,
224+ ) } \n`,
246225
247226 tags : [
248227 ...( operationObject . summary
@@ -253,18 +232,10 @@ export async function processOpenApiDocument(
253232 } ,
254233 ]
255234 : [ ] ) ,
256- ...( operationObject . deprecated
257- ? [
258- {
259- tagName : 'deprecated' ,
260- } ,
261- ]
262- : [ ] ) ,
263235 ] ,
264236 } ;
265237
266- const jsdoc = func . addJsDoc ( jsDocStructure ) ;
267- classDeclaration . addJsDoc ( jsDocStructure ) ;
238+ const jsdoc = classDeclaration . addJsDoc ( jsDocStructure ) ;
268239
269240 if ( operationObject . deprecated ) {
270241 jsdoc . addTag ( {
@@ -294,21 +265,16 @@ export async function processOpenApiDocument(
294265 const parameterName = camelcase ( resolvedParameter . name ) ;
295266
296267 if ( resolvedParameter . in === 'path' ) {
297- func . addParameter ( {
298- name : parameterName ,
299- type : 'string' ,
300- } ) ;
301-
302268 pathParameterNames . push ( parameterName ) ;
303269
304- jsdoc . addTag ( {
305- tagName : 'param' ,
306- text : wordWrap (
307- `${ parameterName } {String} ${
308- resolvedParameter . description || ''
309- } `,
310- ) . trim ( ) ,
311- } ) ;
270+ // jsdoc.addTag({
271+ // tagName: 'param',
272+ // text: wordWrap(
273+ // `${parameterName} {String} ${
274+ // resolvedParameter.description || ''
275+ // }`,
276+ // ).trim(),
277+ // });
312278 }
313279
314280 if ( resolvedParameter . in === 'query' ) {
@@ -350,8 +316,6 @@ export async function processOpenApiDocument(
350316 } )
351317 : undefined ;
352318
353- const hasRequiredQueryParam = queryParameters . some ( ( p ) => p . required ) ;
354-
355319 ensureImport ( queryType ) ;
356320
357321 const requestBodyObjectJson =
@@ -379,53 +343,15 @@ export async function processOpenApiDocument(
379343
380344 ensureImport ( bodyType ) ;
381345
382- const paramsParamName = 'parameters' ;
383-
384- if ( bodyType || queryType ) {
385- const paramsHasQuestionToken = ! bodyType && ! hasRequiredQueryParam ;
386-
387- const pathParamsProperties = [
388- ...( bodyType
389- ? [
390- {
391- name : 'body' ,
392- type : `${ bodyType . getName ( ) } ${
393- requestBodyIsArray ? '[]' : ''
394- } `,
395- hasQuestionToken : false ,
396- } ,
397- ]
398- : [ ] ) ,
399- ...( queryType
400- ? [
401- {
402- name : 'query' ,
403- type : queryType . getName ( ) ,
404- hasQuestionToken : ! hasRequiredQueryParam ,
405- } ,
406- ]
407- : [ ] ) ,
408- ] ;
409-
410- if ( pathParamsProperties . length > 0 ) {
411- func . addParameter ( {
412- name : paramsParamName ,
413- hasQuestionToken : paramsHasQuestionToken ,
414- type : Writers . objectType ( {
415- properties : pathParamsProperties ,
416- } ) ,
417- } ) ;
418- }
419- }
420-
421- if ( bodyType ) {
422- jsdoc . addTag ( {
423- tagName : 'param' ,
424- text : wordWrap (
425- `${ paramsParamName } .body {${ bodyType . getName ( ) } } ${ maybeJsDocDescription ( ) } ` ,
426- ) . trim ( ) ,
427- } ) ;
428- }
346+ // const paramsParamName = 'parameters';
347+ // if (bodyType) {
348+ // jsdoc.addTag({
349+ // tagName: 'param',
350+ // text: wordWrap(
351+ // `${paramsParamName}.body {${bodyType.getName()}} ${maybeJsDocDescription()}`,
352+ // ).trim(),
353+ // });
354+ // }
429355
430356 const paramsType =
431357 pathParameterNames . length > 0
@@ -483,29 +409,28 @@ export async function processOpenApiDocument(
483409 // });
484410 // }
485411
486- for ( const queryParam of queryParameters ) {
487- const queryParameterName = camelcase ( queryParam . name ) ;
488-
489- jsdoc . addTag ( {
490- tagName : 'param' ,
491- text : wordWrap (
492- `${ paramsParamName } .query.${ queryParameterName } ${
493- queryParam . required ? '' : '?'
494- } {String} ${ maybeJsDocDescription (
495- queryParam . deprecated && 'DEPRECATED' ,
496- queryParam . description ,
497- String ( queryParam . example || '' ) ,
498- ) } `,
499- ) . trim ( ) ,
500- } ) ;
501- }
412+ // for (const queryParam of queryParameters) {
413+ // const queryParameterName = camelcase(queryParam.name);
414+
415+ // jsdoc.addTag({
416+ // tagName: 'param',
417+ // text: wordWrap(
418+ // `${paramsParamName}.query.${queryParameterName}${
419+ // queryParam.required ? '' : '?'
420+ // } {String} ${maybeJsDocDescription(
421+ // queryParam.deprecated && 'DEPRECATED',
422+ // queryParam.description,
423+ // String(queryParam.example || ''),
424+ // )}`,
425+ // ).trim(),
426+ // });
427+ // }
502428
503429 // this is just like a 204 response.
504430 if (
505431 ! operationObject . responses ||
506432 Object . keys ( operationObject . responses ) . length === 0
507433 ) {
508- func . setReturnType ( 'RequestMethodCaller<void>' ) ;
509434 classDeclaration . getExtends ( ) ?. addTypeArgument ( 'void' ) ;
510435 }
511436
@@ -514,7 +439,6 @@ export async function processOpenApiDocument(
514439 ) . filter ( ( [ s ] ) => s . startsWith ( '2' ) ) ) {
515440 // early out if response is 204
516441 if ( statusCode === '204' ) {
517- func . setReturnType ( 'RequestMethodCaller<void>' ) ;
518442 classDeclaration . getExtends ( ) ?. addTypeArgument ( 'void' ) ;
519443 break ;
520444 }
@@ -556,27 +480,24 @@ export async function processOpenApiDocument(
556480 arrayRef ? '[]' : ''
557481 } `;
558482
559- const retVal = `RequestMethodCaller<${ outputTypeName } >` ;
560-
561- func . setReturnType ( retVal ) ;
562- classDeclaration . getExtends ( ) ?. addTypeArgument ( outputTypeName ) ;
483+ const retVal = `${ outputTypeName } ` ;
484+ classDeclaration . getExtends ( ) ?. addTypeArgument ( retVal ) ;
563485
564- jsdoc . addTag ( {
565- tagName : 'returns' ,
566- text : `{${ retVal } } HTTP ${ statusCode } ` ,
567- } ) ;
486+ // jsdoc.addTag({
487+ // tagName: 'returns',
488+ // text: `{${retVal}} HTTP ${statusCode}`,
489+ // });
568490 } else {
569- const retVal = 'RequestMethodCaller< void> ' ;
491+ const retVal = 'void' ;
570492
571- func . setReturnType ( retVal ) ;
572- classDeclaration . getExtends ( ) ?. addTypeArgument ( 'void' ) ;
493+ classDeclaration . getExtends ( ) ?. addTypeArgument ( retVal ) ;
573494
574- outputTypes . push ( 'void' ) ;
495+ outputTypes . push ( retVal ) ;
575496
576- jsdoc . addTag ( {
577- tagName : 'returns' ,
578- text : `{${ retVal } } HTTP ${ statusCode } ` ,
579- } ) ;
497+ // jsdoc.addTag({
498+ // tagName: 'returns',
499+ // text: `{${retVal}} HTTP ${statusCode}`,
500+ // });
580501 }
581502 }
582503
@@ -594,29 +515,6 @@ export async function processOpenApiDocument(
594515 . replaceAll ( / \{ ( \w + ) \} / g, camelcase )
595516 . replaceAll ( / { / g, '${' ) } \``;
596517
597- func . addVariableStatement ( {
598- declarationKind : VariableDeclarationKind . Const ,
599- declarations : [
600- {
601- name : 'req' ,
602- initializer : Writers . object ( {
603- method : Writers . assertion ( ( w ) => w . quote ( method ) , 'const' ) ,
604- pathname,
605- ...( queryType && {
606- query : `${ paramsParamName } ?.query` ,
607- } ) ,
608- ...( bodyType && { body : `${ paramsParamName } .body` } ) ,
609- } ) ,
610- } ,
611- ] ,
612- } ) ;
613-
614- func . addStatements ( ( writer ) => {
615- writer . writeLine (
616- 'return (requestMethod, options) => requestMethod(req, options);' ,
617- ) ;
618- } ) ;
619-
620518 const bodyName = 'body' ;
621519 const ctorArgName = ctor . getParameters ( ) [ 0 ] ?. getName ( ) || 'never' ;
622520 // const hasParams = paramsType && !isVoidKeyword(paramsType);
0 commit comments