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

Commit

Permalink
#209 Support empty schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlaff authored and fabien0102 committed Jan 11, 2020
1 parent 3ff62a8 commit cadcc6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ export const getObject = (item: SchemaObject): string => {
// Consolidation of item.properties & item.additionalProperties
let output = "{\n";
if (item.properties) {
output +=
Object.entries(item.properties)
.map(([key, prop]: [string, ReferenceObject | SchemaObject]) => {
const doc = isReference(prop) ? "" : formatDescription(prop.description, 2);
const isRequired = (item.required || []).includes(key);
const processedKey = IdentifierRegexp.test(key) ? key : `"${key}"`;
return ` ${doc}${processedKey}${isRequired ? "" : "?"}: ${resolveValue(prop)}`;
})
.join(";\n") + ";";
output += Object.entries(item.properties)
.map(([key, prop]: [string, ReferenceObject | SchemaObject]) => {
const doc = isReference(prop) ? "" : formatDescription(prop.description, 2);
const isRequired = (item.required || []).includes(key);
const processedKey = IdentifierRegexp.test(key) ? key : `"${key}"`;
return ` ${doc}${processedKey}${isRequired ? "" : "?"}: ${resolveValue(prop)};`;
})
.join("\n");
}

if (item.additionalProperties) {
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/tests/import-open-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ describe("scripts/import-open-api", () => {
}"
`);
});
it("should handle empty properties", () => {
const item = {
properties: {},
};
expect(getObject(item)).toMatchInlineSnapshot(`"any"`);
});
});

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

0 comments on commit cadcc6c

Please sign in to comment.