feat(AWS API Gateway): Remove support for request.schema

BREAKING CHANGE: Support for `http.request.schema` has been removed and replaced
with `http.request.schemas`.
This commit is contained in:
Piotr Grzesik 2021-10-25 11:22:22 +02:00 committed by Mariusz Nowak
parent b5e6857c83
commit dcc9fc0cab
4 changed files with 0 additions and 176 deletions

View File

@ -114,10 +114,6 @@ const requestSchema = {
additionalProperties: false,
},
passThrough: { enum: ['NEVER', 'WHEN_NO_MATCH', 'WHEN_NO_TEMPLATES'] },
schema: {
type: 'object',
additionalProperties: { anyOf: [{ type: 'object' }, { type: 'string' }] },
},
schemas: {
type: 'object',
additionalProperties: { anyOf: [{ type: 'object' }, { type: 'string' }] },
@ -256,18 +252,6 @@ class AwsCompileApigEvents {
);
}
if (
this.serverless.service.provider.name === 'aws' &&
Object.values(this.serverless.service.functions).some(({ events }) =>
events.some(({ http }) => _.get(http, 'request.schema'))
)
) {
this.serverless._logDeprecation(
'AWS_API_GATEWAY_SCHEMAS',
'Starting with next major version, "http.request.schema" property will be replaced by "http.request.schemas".'
);
}
if (
this.serverless.service.provider.name === 'aws' &&
Object.values(this.serverless.service.functions).some(({ events }) =>

View File

@ -98,35 +98,6 @@ module.exports = {
template.Properties.RequestModels = template.Properties.RequestModels || {};
template.Properties.RequestModels[contentType] = { Ref: modelLogicalId };
}
} else if (event.http.request && event.http.request.schema) {
// Old functionality
for (const [contentType, schema] of _.entries(event.http.request.schema)) {
const modelLogicalId = this.provider.naming.getEndpointModelLogicalId(
resourceName,
event.http.method,
contentType
);
if (!validatorLogicalId) {
const requestValidator = this.createRequestValidator();
validatorLogicalId = requestValidator.validatorLogicalId;
}
template.Properties.RequestValidatorId = { Ref: validatorLogicalId };
template.Properties.RequestModels = template.Properties.RequestModels || {};
template.Properties.RequestModels[contentType] = { Ref: modelLogicalId };
Object.assign(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
[modelLogicalId]: {
Type: 'AWS::ApiGateway::Model',
Properties: {
RestApiId: this.provider.getApiGatewayRestApiId(),
ContentType: contentType,
Schema: schema,
},
},
});
}
}
});
},

View File

@ -1,5 +1,4 @@
service: service
disabledDeprecations: AWS_API_GATEWAY_SCHEMAS
provider:
name: aws
@ -50,12 +49,6 @@ functions:
name: TestMethodModel
description: 'Test Method Model Desc'
schema: '${file(dummySchema.json)}'
- http:
path: test-deprecated-simple
method: get
request:
schema:
application/json: '${file(dummySchema.json)}'
- http:
path: test-multiple
method: get
@ -63,10 +56,3 @@ functions:
schemas:
application/json: '${file(dummySchema.json)}'
text/plain: 'foo'
- http:
path: test-deprecated-multiple
method: get
request:
schema:
application/json: '${file(dummySchema.json)}'
text/plain: 'foo'

View File

@ -287,54 +287,6 @@ describe('#compileRequestValidators() - schemas', () => {
});
});
it('should support existing request:schema property for regression', () => {
const modelLogicalId = naming.getEndpointModelLogicalId(
'TestDashdeprecatedDashsimple',
'get',
'application/json'
);
const validatorLogicalId = naming.getValidatorLogicalId();
const methodLogicalId = naming.getMethodLogicalId('TestDashdeprecatedDashsimple', 'get');
const methodResource = cfResources[methodLogicalId];
expect(methodResource.Properties).to.have.property('RequestModels');
expect(methodResource.Properties).to.have.property('RequestValidatorId');
expect(methodResource.Properties.RequestModels['application/json']).to.deep.equal({
Ref: modelLogicalId,
});
expect(methodResource.Properties.RequestValidatorId).to.deep.equal({
Ref: validatorLogicalId,
});
const modelResource = cfResources[modelLogicalId];
expect(modelResource).to.deep.equal({
Type: 'AWS::ApiGateway::Model',
Properties: {
ContentType: 'application/json',
RestApiId: {
Ref: 'ApiGatewayRestApi',
},
Schema: {
$schema: 'http://json-schema.org/draft-04/schema#',
definitions: {},
properties: {
id: {
pattern: '[0-9]+',
title: 'ID for object',
type: 'number',
},
},
required: ['id'],
title: 'Test Validation Schema',
type: 'object',
},
},
});
});
it('should create validator with that includes `service` and `stage`', () => {
const validatorLogicalId = naming.getValidatorLogicalId();
const validatorResource = cfResources[validatorLogicalId];
@ -343,75 +295,6 @@ describe('#compileRequestValidators() - schemas', () => {
`${serviceName}-${stage} | Validate request body and querystring parameters`
);
});
it('should support multiple request:schema property for regression', () => {
const modelJsonLogicalId = naming.getEndpointModelLogicalId(
'TestDashdeprecatedDashmultiple',
'get',
'application/json'
);
const modelPlainTextLogicalId = naming.getEndpointModelLogicalId(
'TestDashdeprecatedDashmultiple',
'get',
'text/plain'
);
const validatorLogicalId = naming.getValidatorLogicalId();
const methodLogicalId = naming.getMethodLogicalId('TestDashdeprecatedDashmultiple', 'get');
const methodResource = cfResources[methodLogicalId];
expect(methodResource.Properties).to.have.property('RequestModels');
expect(methodResource.Properties).to.have.property('RequestValidatorId');
expect(methodResource.Properties.RequestModels['application/json']).to.deep.equal({
Ref: modelJsonLogicalId,
});
expect(methodResource.Properties.RequestModels['text/plain']).to.deep.equal({
Ref: modelPlainTextLogicalId,
});
expect(methodResource.Properties.RequestValidatorId).to.deep.equal({
Ref: validatorLogicalId,
});
const modelJsonResource = cfResources[modelJsonLogicalId];
const modelPlainTextResource = cfResources[modelPlainTextLogicalId];
expect(modelJsonResource).to.deep.equal({
Type: 'AWS::ApiGateway::Model',
Properties: {
ContentType: 'application/json',
RestApiId: {
Ref: 'ApiGatewayRestApi',
},
Schema: {
$schema: 'http://json-schema.org/draft-04/schema#',
definitions: {},
properties: {
id: {
pattern: '[0-9]+',
title: 'ID for object',
type: 'number',
},
},
required: ['id'],
title: 'Test Validation Schema',
type: 'object',
},
},
});
expect(modelPlainTextResource).to.deep.equal({
Type: 'AWS::ApiGateway::Model',
Properties: {
ContentType: 'text/plain',
RestApiId: {
Ref: 'ApiGatewayRestApi',
},
Schema: 'foo',
},
});
});
});
});