Skip to content

Commit

Permalink
Include default response in typegen
Browse files Browse the repository at this point in the history
Fixes #59
  • Loading branch information
anttiviljami committed Sep 21, 2024
1 parent 046b9ff commit 1c3dbc6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/resources/example-pet-api.openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ paths:
responses:
'200':
description: List of pets in database
default:
description: unexpected error
parameters:
- name: limit
in: query
Expand Down
2 changes: 1 addition & 1 deletion src/typegen/typegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('generateTypesForDocument', () => {
});

test('types responses', () => {
expect(clientOperationTypes).toMatch(`OperationResponse<Paths.GetPets.Responses.$200>`);
expect(clientOperationTypes).toMatch(`OperationResponse<Paths.GetPets.Responses.$200 | Paths.GetPets.Responses.Default>`);
expect(clientOperationTypes).toMatch('OperationResponse<Paths.CreatePet.Responses.$201>');
expect(clientOperationTypes).toMatch('OperationResponse<Paths.GetPetById.Responses.$200>');
expect(clientOperationTypes).toMatch('OperationResponse<Paths.ReplacePetById.Responses.$200>');
Expand Down
2 changes: 1 addition & 1 deletion src/typegen/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function generateMethodForClientOperation(

// return type
const responseTypePaths = _.chain(exportTypes)
.filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/2`))
.filter(({ schemaRef }) => schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/2`) || schemaRef.startsWith(`#/paths/${normalizedOperationId}/responses/default`))
.map(({ path }) => path)
.value();
const responseType = !_.isEmpty(responseTypePaths) ? responseTypePaths.join(' | ') : 'any';
Expand Down

0 comments on commit 1c3dbc6

Please sign in to comment.