From b8019d82ccabf732a75c2f97c958b84efb1e43ef Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Mon, 25 Oct 2021 11:22:22 +0200 Subject: [PATCH] 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`. --- .../compile/events/apiGateway/index.js | 16 --- .../events/apiGateway/lib/requestValidator.js | 29 ----- .../programmatic/requestSchema/serverless.yml | 14 --- .../apiGateway/lib/requestValidator.test.js | 117 ------------------ 4 files changed, 176 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/index.js b/lib/plugins/aws/package/compile/events/apiGateway/index.js index ef920d3d77b..0d130dc0434 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/index.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/index.js @@ -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 }) => diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.js index 04414d1c7f8..69d4a536502 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.js @@ -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, - }, - }, - }); - } } }); }, diff --git a/test/fixtures/programmatic/requestSchema/serverless.yml b/test/fixtures/programmatic/requestSchema/serverless.yml index ec142d6142b..252fa5881cf 100644 --- a/test/fixtures/programmatic/requestSchema/serverless.yml +++ b/test/fixtures/programmatic/requestSchema/serverless.yml @@ -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' diff --git a/test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.test.js b/test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.test.js index 97924dcc01a..6a0b8e2fe03 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/requestValidator.test.js @@ -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', - }, - }); - }); }); });