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

Commit be14829

Browse files
committed
Lint fixes 💄
1 parent d428797 commit be14829

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/DefinitionGenerator.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { JSONSchema7 } from 'json-schema';
12
// tslint:disable-next-line no-submodule-imports
23
import { validateSync as openApiValidatorSync } from 'swagger2openapi/validate';
34
import * as uuid from 'uuid';
5+
46
import { IDefinition, IDefinitionConfig, IOperation, IParameterConfig, IServerlessFunctionConfig } from './types';
57
import { clone, isIterable, merge, omit } from './utils';
6-
import { JSONSchema7 } from 'json-schema';
78

89
export class DefinitionGenerator {
910
// The OpenAPI version we currently validate against
@@ -51,38 +52,20 @@ export class DefinitionGenerator {
5152

5253
for (const definitionName of Object.keys(model.schema.definitions || {})) {
5354
const definition = model.schema.definitions[definitionName];
54-
if(typeof definition !== 'boolean'){
55-
this.definition.components.schemas[definitionName] = this.cleanSchema(this.updateReferences(definition))
55+
if (typeof definition !== 'boolean') {
56+
this.definition.components.schemas[definitionName] = this.cleanSchema(this.updateReferences(definition));
5657
}
5758
}
5859

5960
const schemaWithoutDefinitions = omit(model.schema, ['definitions']);
6061

61-
this.definition.components.schemas[model.name] = this.cleanSchema(this.updateReferences(schemaWithoutDefinitions))
62+
this.definition.components.schemas[model.name] = this.cleanSchema(this.updateReferences(schemaWithoutDefinitions));
6263
}
6364
}
6465

6566
return this;
6667
}
6768

68-
private updateReferences(schema: JSONSchema7): JSONSchema7 {
69-
const cloned = clone(schema) as JSONSchema7;
70-
71-
if(cloned.$ref) {
72-
cloned.$ref = cloned.$ref.replace('#/definitions', '#/components/schemas');
73-
} else {
74-
for(const key of Object.getOwnPropertyNames(cloned)) {
75-
const value = cloned[key];
76-
77-
if (typeof value === 'object') {
78-
cloned[key] = this.updateReferences(value);
79-
}
80-
}
81-
}
82-
83-
return cloned;
84-
}
85-
8669
public validate (): { valid: boolean, context: string[], warnings: any[], error?: any[] } {
8770
const payload: any = {};
8871

@@ -141,6 +124,28 @@ export class DefinitionGenerator {
141124
return cleanedSchema;
142125
}
143126

127+
/**
128+
* Walks through the schema object recursively and updates references to point to openapi's components
129+
* @param schema JSON Schema Object
130+
*/
131+
private updateReferences (schema: JSONSchema7): JSONSchema7 {
132+
const cloned = clone(schema) as JSONSchema7;
133+
134+
if (cloned.$ref) {
135+
cloned.$ref = cloned.$ref.replace('#/definitions', '#/components/schemas');
136+
} else {
137+
for (const key of Object.getOwnPropertyNames(cloned)) {
138+
const value = cloned[key];
139+
140+
if (typeof value === 'object') {
141+
cloned[key] = this.updateReferences(value);
142+
}
143+
}
144+
}
145+
146+
return cloned;
147+
}
148+
144149
/**
145150
* Generate Operation objects from the Serverless Config.
146151
*

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function isIterable (obj) {
1111
return typeof obj[Symbol.iterator] === 'function';
1212
}
1313

14-
export function omit<T extends Object> (obj: T, keys: string[]): T {
14+
export function omit<T extends object> (obj: T, keys: string[]): T {
1515
const cloned = clone(obj);
1616

17-
for(const key of keys) {
17+
for (const key of keys) {
1818
delete cloned[key];
1919
}
2020

0 commit comments

Comments
 (0)