Skip to content

Commit

Permalink
fix: Use original Swagger object and fix references (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed Aug 8, 2019
1 parent 41292d5 commit 6867544
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/generators/MethodGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class MethodGenerator {
console.warn(`No reference found for "${schema.$ref}".`);
return TypeScriptType.EMPTY_OBJECT;
}
const definition = schema.$ref.replace('#/definitions', '');
const definition = schema.$ref.replace('#/definitions/', '');
properties = this.spec.definitions[definition].properties;
requiredProperties = this.spec.definitions[definition].required;
schemaType = this.spec.definitions[definition].type as string;
Expand Down
5 changes: 4 additions & 1 deletion src/validator/SwaggerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import {OpenAPIV2} from 'openapi-types';
import SwaggerParser from 'swagger-parser';

export async function validateConfig(swaggerJson: OpenAPIV2.Document): Promise<void> {
await SwaggerParser.validate(swaggerJson);
// let's create a copy because swagger-parser modifies the object,
// see https://github.com/APIDevTools/swagger-parser/issues/77
const swaggerJsonCopy = JSON.parse(JSON.stringify(swaggerJson));
await SwaggerParser.validate(swaggerJsonCopy);
}

0 comments on commit 6867544

Please sign in to comment.