Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: cant convert empty object to dts #2642

Open
jonnytest1 opened this issue Aug 25, 2024 · 0 comments
Open

[BUG]: cant convert empty object to dts #2642

jonnytest1 opened this issue Aug 25, 2024 · 0 comments
Labels

Comments

@jonnytest1
Copy link

jonnytest1 commented Aug 25, 2024

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 jonnytest1 added the bug label Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant