Skip to content

Commit 1a6cde6

Browse files
committed
add nullable to schema-definition
1 parent 166ad34 commit 1a6cde6

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
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.3",
3+
"version": "0.1.4",
44
"description": "OpenAPI interface generator for Next.js",
55
"keywords": [
66
"next",

src/core/openapi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type SchemaDefinition = {
33
format?: "date" | "unknown",
44
description: string,
55
readOnly: boolean,
6+
nullable: boolean,
67
$ref?: string,
78
items?: SchemaDefinition | SchemaDefinition[],
89
oneOf?: SchemaDefinition[],

src/core/resolvers/property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SchemaDefinition } from "~/core/openapi";
2-
import { resolveSchema } from "./schema-definition";
2+
import { resolveSchemaWithNull } from "./schema-definition";
33

44
export type ModelProperty = {
55
content: string,
@@ -11,7 +11,7 @@ export default function resolveProperties(collection: Record<string, SchemaDefin
1111
const isRequired = required.includes(propertyName);
1212
const content = [
1313
`${propertyName}${isRequired ? "" : "?"}:`,
14-
`${resolveSchema(property)},`,
14+
`${resolveSchemaWithNull(property)},`,
1515
];
1616
if (property.readOnly) content.unshift("readonly");
1717
return {

src/core/resolvers/schema-definition.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export function resolveSchema(definition: SchemaDefinition): string {
5757
return "unknown";
5858
}
5959

60+
export function resolveSchemaWithNull(definition: SchemaDefinition) {
61+
if (definition.nullable) {
62+
return `${resolveSchema(definition)} | null`
63+
}
64+
resolveSchema(definition)
65+
}
66+
6067
export function simplifySchema(resolvedSchema: string) {
6168
return resolvedSchema.replace(/\[|\]/g, "");
6269
}

0 commit comments

Comments
 (0)