diff --git a/packages/core/src/getters/res-req-types.ts b/packages/core/src/getters/res-req-types.ts index e5c7c9ac9..29fb99c3c 100644 --- a/packages/core/src/getters/res-req-types.ts +++ b/packages/core/src/getters/res-req-types.ts @@ -1,5 +1,7 @@ import { keyword } from 'esutils'; +import type { ValueIteratee } from 'lodash'; import uniqBy from 'lodash.uniqby'; + import { MediaTypeObject, ReferenceObject, @@ -48,6 +50,7 @@ export const getResReqTypes = ( name: string, context: ContextSpecs, defaultType = 'unknown', + uniqueKey: ValueIteratee = 'value', ): ResReqTypesValue[] => { const typesArray = responsesOrRequests .filter(([_, res]) => Boolean(res)) @@ -213,7 +216,7 @@ export const getResReqTypes = ( return uniqBy( typesArray.flatMap((it) => it), - 'value', + uniqueKey, ); }; diff --git a/packages/core/src/getters/response.ts b/packages/core/src/getters/response.ts index 43bfc10b5..38c7bc082 100644 --- a/packages/core/src/getters/response.ts +++ b/packages/core/src/getters/response.ts @@ -37,6 +37,7 @@ export const getResponse = ({ operationName, context, 'void', + (type) => type.key.startsWith('2') + type.value, ); const filteredTypes = contentType diff --git a/tests/configs/swr.config.ts b/tests/configs/swr.config.ts index 499a0fca8..20de0fa69 100644 --- a/tests/configs/swr.config.ts +++ b/tests/configs/swr.config.ts @@ -167,4 +167,15 @@ export default defineConfig({ target: '../specifications/enums.yaml', }, }, + errors: { + output: { + target: '../generated/swr/errors/endpoints.ts', + schemas: '../generated/swr/errors/model', + client: 'swr', + mock: true, + }, + input: { + target: '../specifications/errors.yaml', + }, + }, }); diff --git a/tests/specifications/errors.yaml b/tests/specifications/errors.yaml new file mode 100644 index 000000000..0559d3267 --- /dev/null +++ b/tests/specifications/errors.yaml @@ -0,0 +1,37 @@ +openapi: '3.0.0' +info: + version: 1.0.0 + title: Swagger Errors + license: + name: MIT +paths: + /error: + get: + summary: Get an Error Item + operationId: createItems + responses: + '200': + description: Success + content: + application/json: + schema: + $ref: '#/components/schemas/Item' + '400': + description: Error + content: + application/json: + schema: + $ref: '#/components/schemas/Item' + default: + description: Error + content: + application/json: + schema: + $ref: '#/components/schemas/Item' +components: + schemas: + Item: + type: object + properties: + prop: + type: string