Skip to content

Commit

Permalink
chore(parser): move getOperationErrors to common parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 26, 2024
1 parent 7010340 commit f310f2b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
10 changes: 9 additions & 1 deletion src/openApi/common/parser/operation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import camelCase from 'camelcase';

import type { OperationResponse } from '../../../types/client';
import type { OperationError, OperationResponse } from '../../../types/client';
import type { Config } from '../../../types/config';
import { reservedWords } from '../../../utils/reservedWords';
import { sanitizeOperationName, sanitizeOperationParameterName } from '../../../utils/sanitize';
Expand Down Expand Up @@ -61,3 +61,11 @@ export const getOperationResponseCode = (value: string | 'default'): number | nu

return null;
};

export const getOperationErrors = (operationResponses: OperationResponse[]): OperationError[] =>
operationResponses
.filter(operationResponse => operationResponse.code >= 300 && operationResponse.description)
.map(response => ({
code: response.code,
description: response.description!,
}));
3 changes: 1 addition & 2 deletions src/openApi/v2/parser/getOperation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Operation, OperationParameters } from '../../../types/client';
import type { Config } from '../../../types/config';
import { getOperationName, getOperationResponseHeader } from '../../common/parser/operation';
import { getOperationErrors, getOperationName, getOperationResponseHeader } from '../../common/parser/operation';
import { toSortedByRequired } from '../../common/parser/sort';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiOperation } from '../interfaces/OpenApiOperation';
import { getOperationErrors } from './getOperationErrors';
import { getOperationParameters } from './getOperationParameters';
import { getOperationResponses } from './getOperationResponses';
import { getOperationResults } from './getOperationResults';
Expand Down
13 changes: 0 additions & 13 deletions src/openApi/v2/parser/getOperationErrors.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/openApi/v3/parser/getOperationErrors.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/openApi/v3/parser/operation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { Operation, OperationParameter, OperationParameters } from '../../../types/client';
import type { Config } from '../../../types/config';
import { getRef } from '../../common/parser/getRef';
import { getOperationName, getOperationResponseHeader } from '../../common/parser/operation';
import { getOperationErrors, getOperationName, getOperationResponseHeader } from '../../common/parser/operation';
import { toSortedByRequired } from '../../common/parser/sort';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiOperation } from '../interfaces/OpenApiOperation';
import type { OpenApiRequestBody } from '../interfaces/OpenApiRequestBody';
import { getOperationErrors } from './getOperationErrors';
import { getOperationParameters } from './getOperationParameters';
import { getOperationRequestBody } from './getOperationRequestBody';
import { getOperationResponses } from './getOperationResponses';
Expand Down

0 comments on commit f310f2b

Please sign in to comment.