Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Deal with empty interface in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Jun 22, 2020
1 parent 1b737fb commit 82b6d98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,10 @@ export const Poll${componentName} = (${
*/
export const generateInterface = (name: string, schema: SchemaObject) => {
const scalar = getScalar(schema);
return `${formatDescription(schema.description)}export interface ${pascal(name)} ${scalar}`;
const isEmptyInterface = scalar === "{}";
return `${formatDescription(schema.description)}${
isEmptyInterface ? "// tslint:disable-next-line:no-empty-interface\n" : ""
}export interface ${pascal(name)} ${scalar}`;
};

/**
Expand Down
13 changes: 13 additions & 0 deletions src/scripts/tests/import-open-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,19 @@ describe("scripts/import-open-api", () => {

expect(generateSchemasDefinition(schema)).toContain(`export type Wolf = Dog;`);
});

it("should deal with empty object", () => {
const schema = {
Wolf: {
type: "object",
properties: {},
additionalProperties: false,
},
};

expect(generateSchemasDefinition(schema)).toContain(`// tslint:disable-next-line:no-empty-interface`);
expect(generateSchemasDefinition(schema)).toContain(`export interface Wolf {}`);
});
});

describe("generateResponsesDefinition", () => {
Expand Down

0 comments on commit 82b6d98

Please sign in to comment.