Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
feat: schema in model is now optional (#23)
Browse files Browse the repository at this point in the history
If you don't have any schema you can omit it (e.g. for binary files).

closes #19
  • Loading branch information
tchock authored Mar 9, 2017
1 parent c3f669c commit 0ca8285
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ need the path of the described resource and models need the name of the model.
### Define the models

Models have additional information you have to define. Besides the model name, the description and
the summary, you need to define the *content type* for this model in addition to the *schema* that describes
the model. Both are mandatory:
the summary, you need to define the *content type* for this model in addition to the *schema* that
describes the model:

* `contentType`: the content type of the described request/response (like `"application/json"` or
`"application/xml"`).
`"application/xml"`). This is mandatory.
* `schema`: The JSON Schema that describes the model. In the examples below external files are
imported, but you can also define the schema inline using YAML format.

Expand Down
18 changes: 18 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ describe('ServerlessAWSDocumentation', function () {
});

it('should add models but not add them to http events', function () {
// also add a model with no schema
this.serverlessMock.variables.service.custom.documentation.models.push({
name: 'NoSchemaModel',
contentType: 'application/json',
description: 'the other test model schema',
});

this.plugin.beforeDeploy();
expect(this.serverlessMock.service.provider.compiledCloudFormationTemplate).toEqual({
Resources: {
Expand All @@ -132,6 +139,17 @@ describe('ServerlessAWSDocumentation', function () {
Schema: 'some even more complex schema',
},
},
NoSchemaModelModel: {
Type: 'AWS::ApiGateway::Model',
Properties: {
RestApiId: {
Ref: 'ApiGatewayRestApi',
},
ContentType: 'application/json',
Name: 'NoSchemaModel',
Schema: {},
},
},
ExistingResource: {
with: 'configuration',
},
Expand Down
2 changes: 1 addition & 1 deletion src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
},
ContentType: model.contentType,
Name: model.name,
Schema: model.schema,
Schema: model.schema || {},
},
};
},
Expand Down

0 comments on commit 0ca8285

Please sign in to comment.