quicktype
quicktype copied to clipboard
[BUG]: cant convert empty object to dts
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()