fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore(ir): remove unused `hasOperationPathOrQueryAny`

-126
-112
packages/openapi-ts/src/ir/__tests__/operation.test.ts
··· 1 - import { describe, expect, it } from 'vitest'; 2 - 3 - import { hasOperationPathOrQueryAny } from '../operation'; 4 - import type { IR } from '../types'; 5 - 6 - describe('hasOperationPathOrQueryAny', () => { 7 - const baseOperationMeta = { 8 - method: 'get' as const, 9 - path: '/test' as const, 10 - }; 11 - 12 - const queryParam = ( 13 - name: string, 14 - type: IR.SchemaObject['type'] = 'string', 15 - ): IR.ParameterObject => ({ 16 - explode: true, 17 - location: 'query', 18 - name, 19 - schema: { type }, 20 - style: 'form', 21 - }); 22 - 23 - const pathParam = ( 24 - name: string, 25 - type: IR.SchemaObject['type'] = 'string', 26 - ): IR.ParameterObject => ({ 27 - explode: false, 28 - location: 'path', 29 - name, 30 - schema: { type }, 31 - style: 'simple', 32 - }); 33 - 34 - const op = (partial: Partial<IR.OperationObject>): IR.OperationObject => ({ 35 - id: partial.id ?? 'op', 36 - ...baseOperationMeta, 37 - ...partial, 38 - }); 39 - 40 - const scenarios: ReadonlyArray<{ 41 - expected: boolean; 42 - operation: IR.OperationObject; 43 - }> = [ 44 - { 45 - expected: false, 46 - operation: op({ id: 'noParams' }), 47 - }, 48 - { 49 - expected: false, 50 - operation: op({ 51 - id: 'emptyParams', 52 - parameters: {} as unknown as IR.OperationObject['parameters'], 53 - }), 54 - }, 55 - { 56 - expected: false, 57 - operation: op({ 58 - id: 'emptyPathAndQuery', 59 - parameters: { 60 - path: {}, 61 - query: {}, 62 - } as unknown as IR.OperationObject['parameters'], 63 - }), 64 - }, 65 - { 66 - expected: true, 67 - operation: op({ 68 - id: 'pathOnly', 69 - parameters: { 70 - path: { id: pathParam('id') }, 71 - } as unknown as IR.OperationObject['parameters'], 72 - }), 73 - }, 74 - { 75 - expected: true, 76 - operation: op({ 77 - id: 'queryOnly', 78 - parameters: { 79 - query: { q: queryParam('q') }, 80 - } as unknown as IR.OperationObject['parameters'], 81 - }), 82 - }, 83 - { 84 - expected: true, 85 - operation: op({ 86 - id: 'bothPathAndQuery', 87 - parameters: { 88 - path: { id: pathParam('id') }, 89 - query: { q: queryParam('q') }, 90 - } as unknown as IR.OperationObject['parameters'], 91 - }), 92 - }, 93 - { 94 - expected: false, 95 - operation: op({ 96 - body: { 97 - mediaType: 'application/json', 98 - required: true, 99 - schema: { type: 'object' }, 100 - }, 101 - id: 'bodyOnly', 102 - }), 103 - }, 104 - ]; 105 - 106 - it.each(scenarios)( 107 - 'path/query presence for $operation.id → $expected', 108 - ({ expected, operation }: (typeof scenarios)[number]) => { 109 - expect(hasOperationPathOrQueryAny(operation)).toEqual(expected); 110 - }, 111 - ); 112 - });
-14
packages/openapi-ts/src/ir/operation.ts
··· 21 21 return false; 22 22 }; 23 23 24 - export const hasOperationPathOrQueryAny = ( 25 - operation: IR.OperationObject, 26 - ): boolean => { 27 - const params = operation.parameters; 28 - if (!params) { 29 - return false; 30 - } 31 - 32 - if (params.path && Object.keys(params.path).length) return true; 33 - if (params.query && Object.keys(params.query).length) return true; 34 - 35 - return false; 36 - }; 37 - 38 24 export const createOperationKey = ({ 39 25 method, 40 26 path,