From outputSchema
to outputSchemas
Why?
Before version 0.25.0, in the ApiGatewayContract
, the outputSchema
key was used to specify the output schema of an Api Gateway integration.
However, some users reported that they needed multiple output schemas for a single integration to handle different status codes, for error responses for example.
Thus, we decided to add a outputSchemas
to allow that and remove the outputSchema
key, which introduced a breaking change.
For more context, check out:
How?
Migrating from outputSchema
to outputSchemas
is quite straightforward:
-
Upgrade
@swarmion/serverless-contracts
to version0.25.0
or higher -
In your contract packages, in the files defining your contracts
- Add the
HttpStatusCodes
type to the imports:
+ import { HttpStatusCodes } from '@swarmion/serverless-contracts';
- Update the
ApiGatewayContract
to useoutputSchemas
instead ofoutputSchema
:
- outputSchema,
+ outputSchemas: {
+ [HttpStatusCodes.OK]: outputSchema,
+ }, - Add the
-
In your backend services handlers defined with the
getHandler
feature, update the return type of your implementation to provide a body and a status code:
const handler = getHandler(contract)(async (event) => {
/// your implementation
- return body;
+ return { body, statusCode: HttpStatusCodes.OK };
});
-
In your services using the consumer features:
- If you use the
getAxiosRequest
feature, nothing changes - If you use the
getFetchRequest
feature, if you want to keep the same behavior as before, you should now access thebody
key of its return value:
const response = await getFetchRequest(contract, fetch, options);
- return response;
+ return response.body; - If you use the