Skip to content

Commit 0db4a65

Browse files
committed
fix empty schemas issue
1 parent ffe126b commit 0db4a65

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omer-x/next-openapi-interface-generator",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "OpenAPI interface generator for Next.js",
55
"keywords": [
66
"next",

src/core/openapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type HttpMethod = "get" | "post" | "patch" | "put" | "delete";
5757

5858
export type OpenAPI = {
5959
components: {
60-
schemas: Record<string, SchemaComponent>,
60+
schemas?: Record<string, SchemaComponent>,
6161
},
6262
paths: Record<string, Record<HttpMethod, Operation>>,
6363
};

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import generateSwaggerJson from "./core/swagger";
2222
const outputDir = path.resolve(process.cwd(), outputFolder);
2323

2424
const data = generateSwaggerJson(sourceDir);
25-
for (const [schemaName, schema] of Object.entries(data.components.schemas)) {
26-
if (schema.type === "object") {
27-
const properties = resolveProperties(schema.properties, schema.required ?? []);
28-
const importedSchemas = resolveSchemasFromProps(schema.properties);
29-
const content = generateSchema(schemaName, properties, importedSchemas);
30-
await createFile(content, `${schemaName}.ts`, outputDir, "schemas");
25+
if (data.components.schemas) {
26+
for (const [schemaName, schema] of Object.entries(data.components.schemas)) {
27+
if (schema.type === "object") {
28+
const properties = resolveProperties(schema.properties, schema.required ?? []);
29+
const importedSchemas = resolveSchemasFromProps(schema.properties);
30+
const content = generateSchema(schemaName, properties, importedSchemas);
31+
await createFile(content, `${schemaName}.ts`, outputDir, "schemas");
32+
}
3133
}
3234
}
3335

0 commit comments

Comments
 (0)