Skip to content

Commit

Permalink
fix(opapi): handler generator supports nullable properties (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur authored May 23, 2024
1 parent 1602cf7 commit 6e7e100
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion opapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/opapi",
"version": "0.10.17",
"version": "0.10.18",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
12 changes: 3 additions & 9 deletions opapi/src/handler-generator/export-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ import fs from 'fs/promises'

type Module = { name: string; filename: string }

const fixSchema = (schema: JSONSchema7): JSONSchema7 => {
schema = jsonschema.replaceNullableWithUnion(schema as jsonschema.NullableJsonSchema)
schema = jsonschema.setDefaultAdditionalProperties(schema, false)
return schema
}

const toTs = async (originalSchema: JSONSchema7, name: string): Promise<string> => {
let { title, ...schema } = originalSchema
schema = fixSchema(schema)
schema = jsonschema.setDefaultAdditionalProperties(schema, false)

type jsonSchemaToTsInput = Parameters<typeof compile>[0]
const typeCode = await compile(schema as jsonSchemaToTsInput, name, {
Expand All @@ -34,8 +28,8 @@ export const exportSchemas = (schemas: Record<string, JSONSchema7>) => async (ou
const jsonFiles: Module[] = []
const typeFiles: Module[] = []

for (const schema of Object.entries(schemas)) {
const [name, jsonSchema] = schema
for (const [name, schema] of Object.entries(schemas)) {
const jsonSchema = jsonschema.replaceNullableWithUnion(schema)

// json file
const jsonFileName = `${name}.j`
Expand Down

0 comments on commit 6e7e100

Please sign in to comment.