Skip to content

Commit

Permalink
fix: handle empty response in MSW mocks (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlismelderis-mckinsey authored Jun 26, 2024
1 parent 7efca63 commit c2fff70
Show file tree
Hide file tree
Showing 158 changed files with 219 additions and 5,222 deletions.
12 changes: 6 additions & 6 deletions packages/mock/src/msw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ export const ${handlerName} = (${
: ${getResponseMockFunctionName}())`
: null
},
{
status: ${status === 'default' ? 200 : status.replace(/XX$/, '00')},
headers: {
'Content-Type': '${isTextPlain ? 'text/plain' : 'application/json'}',
{ status: ${status === 'default' ? 200 : status.replace(/XX$/, '00')},
${
isReturnHttpResponse
? `headers: { 'Content-Type': ${isTextPlain ? "'text/plain'" : "'application/json'"} }`
: ''
}
}
)
})
})
}\n`;

Expand Down
23 changes: 4 additions & 19 deletions samples/angular-app/src/api/endpoints/pets/pets.msw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down Expand Up @@ -42,25 +42,15 @@ export const getListPetsMockHandler = (
: overrideResponse
: getListPetsResponseMock(),
),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
},
{ status: 200, headers: { 'Content-Type': 'application/json' } },
);
});
};

export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 201,
headers: {
'Content-Type': 'application/json',
},
});
return new HttpResponse(null, { status: 201 });
});
};

Expand All @@ -81,12 +71,7 @@ export const getShowPetByIdMockHandler = (
: overrideResponse
: getShowPetByIdResponseMock(),
),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
},
{ status: 200, headers: { 'Content-Type': 'application/json' } },
);
});
};
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/endpoints/pets/pets.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/createPetsBody.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/listPetsParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/pet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/src/api/model/pets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
30 changes: 5 additions & 25 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down Expand Up @@ -155,25 +155,15 @@ export const getListPetsMockHandler = (
: overrideResponse
: getListPetsResponseMock(),
),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
},
{ status: 200, headers: { 'Content-Type': 'application/json' } },
);
});
};

export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 201,
headers: {
'Content-Type': 'application/json',
},
});
return new HttpResponse(null, { status: 201 });
});
};

Expand All @@ -194,12 +184,7 @@ export const getListPetsNestedArrayMockHandler = (
: overrideResponse
: getListPetsNestedArrayResponseMock(),
),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
},
{ status: 200, headers: { 'Content-Type': 'application/json' } },
);
});
};
Expand All @@ -221,12 +206,7 @@ export const getShowPetByIdMockHandler = (
: overrideResponse
: getShowPetByIdResponseMock(),
),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
},
{ status: 200, headers: { 'Content-Type': 'application/json' } },
);
});
};
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/createPetsBody.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/listPetsNestedArrayParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/listPetsParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/pet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/petCallingCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/petCountry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/petsArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/api/model/petsNestedArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/hono/src/petstore.context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/hono/src/petstore.schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/hono/src/petstore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/hono/src/petstore.validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/hono/src/petstore.zod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/cat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/catType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/dachshund.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/dog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/dogType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/labradoodle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/pet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion samples/next-app-with-fetch/app/gen/models/petCountry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.30.2 🍺
* Generated by orval v6.31.0 🍺
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
Expand Down
Loading

0 comments on commit c2fff70

Please sign in to comment.