Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

Commit 553e820

Browse files
Brendan Abbottnfour
authored andcommitted
Lowercase method, reorganise operation object for better readability (as a consumer)
1 parent ca22125 commit 553e820

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Operation now supports `deprecated` and `tags` properties.
1414
- Parameters now support the `content` property.
1515
- Updated various build dependencies.
16+
- OpenAPI definition will now be smaller in most cases, choosing to omit optional properties instead of using empty defaults.
1617

1718
## Fixed
1819

1920
- Handle when `models` is not iterable.
21+
- Handle when `models` have no `schema`.
22+
- Always lowercase the HTTP method to conform to OpenAPI spec.
2023

2124
## [v0.2.1] - 2017-07-07
2225

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ cookieParams:
240240

241241
#### `requestModels`
242242

243-
The `requestModels` property allows you to define models for the HTTP Request of the function event. You can define a different model for each different `Content-Type`. You can define a reference to the relevant request model named in the `models` section of your configuration (see [Defining Models](#defining-models) section).
243+
The `requestModels` property allows you to define models for the HTTP Request of the function event. You can define a different model for each different `Content-Type`. You can define a reference to the relevant request model named in the `models` section of your configuration (see [Defining Models](#models) section).
244244

245245
```yml
246246
requestModels:
@@ -269,7 +269,7 @@ methodResponse:
269269

270270
##### `responseModels`
271271

272-
The `responseModels` property allows you to define models for the HTTP Response of the function event. You can define a different model for each different `Content-Type`. You can define a reference to the relevant response model named in the `models` section of your configuration (see [Defining Models](#defining-models) section).
272+
The `responseModels` property allows you to define models for the HTTP Response of the function event. You can define a different model for each different `Content-Type`. You can define a reference to the relevant response model named in the `models` section of your configuration (see [Defining Models](#models) section).
273273

274274
```yml
275275
responseModels:

src/DefinitionGenerator.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class DefinitionGenerator {
4545

4646
if (isIterable(models)) {
4747
for (const model of models) {
48+
if (!model.schema) {
49+
continue;
50+
}
51+
4852
this.definition.components.schemas[model.name] = this.cleanSchema(
4953
dereference(model.schema),
5054
);
@@ -81,7 +85,7 @@ export class DefinitionGenerator {
8185
// Build OpenAPI path configuration structure for each method
8286
const pathConfig = {
8387
[`/${httpEventConfig.path}`]: {
84-
[httpEventConfig.method]: this.getOperationFromConfig(
88+
[httpEventConfig.method.toLowerCase()]: this.getOperationFromConfig(
8589
funcConfig._functionName,
8690
httpEventConfig.documentation,
8791
),
@@ -120,16 +124,31 @@ export class DefinitionGenerator {
120124
* @param documentationConfig
121125
*/
122126
private getOperationFromConfig (funcName: string, documentationConfig): IOperation {
123-
return {
127+
const operationObj: IOperation = {
124128
operationId: funcName,
125-
tags: documentationConfig.tags || [],
126-
deprecated: documentationConfig.deprecated || false,
127-
summary: documentationConfig.summary || '',
128-
description: documentationConfig.description || '',
129-
parameters: this.getParametersFromConfig(documentationConfig),
130-
requestBody: this.getRequestBodiesFromConfig(documentationConfig),
131-
responses: this.getResponsesFromConfig(documentationConfig),
132129
};
130+
131+
if (documentationConfig.summary) {
132+
operationObj.summary = documentationConfig.summary;
133+
}
134+
135+
if (documentationConfig.description) {
136+
operationObj.description = documentationConfig.description;
137+
}
138+
139+
if (documentationConfig.tags) {
140+
operationObj.tags = documentationConfig.tags;
141+
}
142+
143+
if (documentationConfig.deprecated) {
144+
operationObj.deprecated = true;
145+
}
146+
147+
operationObj.parameters = this.getParametersFromConfig(documentationConfig);
148+
operationObj.requestBody = this.getRequestBodiesFromConfig(documentationConfig);
149+
operationObj.responses = this.getResponsesFromConfig(documentationConfig);
150+
151+
return operationObj;
133152
}
134153

135154
/**

0 commit comments

Comments
 (0)