Skip to content

Commit

Permalink
feat(AWS API Gateway): Remove support for request.schema
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Support for `http.request.schema` has been removed and replaced
with `http.request.schemas`.
  • Loading branch information
pgrzesik authored and medikoo committed Jan 27, 2022
1 parent 03b77c0 commit b8019d8
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 176 deletions.
16 changes: 0 additions & 16 deletions lib/plugins/aws/package/compile/events/apiGateway/index.js
Expand Up @@ -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' }] },
Expand Down Expand Up @@ -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 }) =>
Expand Down
Expand Up @@ -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,
},
},
});
}
}
});
},
Expand Down
14 changes: 0 additions & 14 deletions test/fixtures/programmatic/requestSchema/serverless.yml
@@ -1,5 +1,4 @@
service: service
disabledDeprecations: AWS_API_GATEWAY_SCHEMAS

provider:
name: aws
Expand Down Expand Up @@ -50,23 +49,10 @@ 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
request:
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'
Expand Up @@ -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];
Expand All @@ -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',
},
});
});
});
});

Expand Down

0 comments on commit b8019d8

Please sign in to comment.