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

Can you implement JSON output of schema.d.ts file? #113

Open
selodev opened this issue Jul 5, 2020 · 7 comments
Open

Can you implement JSON output of schema.d.ts file? #113

selodev opened this issue Jul 5, 2020 · 7 comments

Comments

@selodev
Copy link

selodev commented Jul 5, 2020

Such as
--options
Specify a json option file that should be loaded. If not specified TypeDoc will look for 'schema.json' in the current directory.

--json <path/to/output.json>
Specifies the location and file name a json file describing the project is written to. When specified no documentation will be generated.

https://github.com/TypeStrong/typedoc repository is an example of json output.

@Eyas
Copy link
Collaborator

Eyas commented Jul 5, 2020

By JSON output, do you mean a https://json-schema.org/ definition of the Schema, or something else?

@selodev
Copy link
Author

selodev commented Jul 5, 2020

Hi yes, that would be great. There is a lot of work done by you to generate schema.d.ts file. Why not also create a json object representation of the entire schema.d.ts file, so that we can use it in our projects such as creating ui components based on the json file.
https://github.com/ccpu/ts-to-json is an another example.

@Eyas
Copy link
Collaborator

Eyas commented Jul 7, 2020

Hmm. There are separate libraries that create JSONschema for Schema.org as-is. They're useful especially if you have a .json file you want to represent as a specific SDO type.

Is your use case different? Do you want JSONschema representing actual SDO JSON-LD? or JSONschema consumable by TypeDoc for documentation on the "schema-dts" types themselves (including WithContext, etc)?

@selodev
Copy link
Author

selodev commented Jul 9, 2020

I pretty much want some what JSON-LD that I can loop over without having the reshape https://schema.org/version/latest/all-layers.jsonld. I know you guys created all the interfaces by extracting or converting https://schema.org/version/latest/all-layers.jsonld to ts-dts, I wanted to stick the way you shaped the interfaces and I wanted to be able to the use extractions the way you did, so I have full blown schema with its relations but again stick to the interfaces. So pretty much a json-ld representation of the schema.d.ts so I can create components based on the same relation in the schema.d.ts like in https://json-ld.org/#developers. Sorry I am having hard time to explain.

@selodev
Copy link
Author

selodev commented Jul 12, 2020 via email

@Eyas
Copy link
Collaborator

Eyas commented Jul 12, 2020 via email

@TigerC10
Copy link

TigerC10 commented Mar 2, 2024

There are separate libraries that create JSONschema for Schema.org as-is. They're useful especially if you have a .json file you want to represent as a specific SDO type.

@Eyas can you detail where those libraries are? My Google-fu is too weak to locate those projects.

Personally, I'd have loved to have found a Typebox implementation of Schema.org types. I did try modifying transform.ts:

import * as Codegen from '@sinclair/typebox-codegen';

// ...

  for (const cls of sorted) {
    if (cls.deprecated && !includeDeprecated) continue;

    for (const node of cls.toNode(context, properties)) {
      const result = printer.printNode(EmitHint.Unspecified, node, source);

      // await write(result);
      const code = Codegen.TypeScriptToTypeBox.Generate(result);
      // const model = Codegen.TypeScriptToModel.Generate(result);
      // const code = Codegen.ModelToJsonSchema.Generate(model); // This fails because the code generator needs the dependencies in scope
      await write(code);
      await write('\n');
    }
    await write('\n');
  }

This... Sorta worked. I was able to get a typebox file output from schema-dts-gen this way, however at transpile/run time there are too many calls to the program stack. That suggests some infinite looping due to the awkward hierarchy created by typescript. E.g. the Text type is a union of its subtypes like PronounceableText, but PronounceableText includes a property of the Text type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants