quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

[BUG]: cant convert empty object to dts

Open jonnytest1 opened this issue 1 year ago • 0 comments

Issue Type

an empty object doesnt get converted to dts

Context (Environment, Version, Language)

Input Format: json schema Output Language: typescript

CLI, npm, or app.quicktype.io: Version: https://app.quicktype.io/

Description

Input Data

{ "id": "http://json-schema.org/geo", "$schema": "http://json-schema.org/draft-06/schema#", "type": "object", "properties":{} }

Expected Behaviour / Output

export type Name = {} // or whatever the typescsipt equivalent of an empty object is ^^

Current Behaviour / Output

breaks

workaround:

wrap in subobject:


if(schema.type=="object" && !schema.properties){
 jsonSchema = {
      type: "object",
      properties: {
        wrapper: jsonSchema
      },
      required: ["wrapper"],
      additionalProperties: false
    }
}

...

 lines[0] = ""
    lines[1] = lines[1].replace(/wrapper: ([^;]*);/, `export type ${mainTypeName} = $1;`).trim()
    lines[2] = ""
    return `
        ${lines.join("\n")}
    `.trim()


jonnytest1 avatar Aug 25 '24 13:08 jonnytest1