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

Create Typscript schema with external references #555

Open
MarcoLeko opened this issue Oct 16, 2023 · 0 comments
Open

Create Typscript schema with external references #555

MarcoLeko opened this issue Oct 16, 2023 · 0 comments

Comments

@MarcoLeko
Copy link

I'm trying to create a static typescipt typings base on this JSON schema from google: https://developers.google.com/actions/media/tools/schema_livetv.json

In order to test things locally I've copy-pasted the content of this endpoint into an output.json (removed the comments in this file)

and ran the following:

json2ts -i output.json -o ./types/schema-dts/index.d.ts --unreachableDefinitions

but it seems that json2ts is not able to read the references from the json file, here is one small piece of the json content from that google-endpoint:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "allOf": [
    {
      "if": {
        "properties": {
          "@type": {
            "const": "MediaService"
          }
        }
      },
      "then": {
        "$ref": "#/definitions/generics/MediaService"
      }
    },
    ... // cut out more entries for the sake of clarity
  ]
}

and this is basically the output that is generated out of that:

export type Output = {
  [k: string]: unknown;
} & {
  "@type"?:
    | "MediaService"
    | "TVSeries"
    | "TVEpisode"
    | "TVSeason"
    | "Movie"
    | "BroadcastService"
    | "Organization"
    | "TelevisionChannel"
    | "CableOrSatelliteService"
    | "BroadcastEvent"
    | "SportsEvent";
  [k: string]: unknown;
};

So what I would expect to happen is that json2ts would be able to read from the reference in the json file of "MediaService" which would be in that case this ref "#/definitions/generics/MediaService" which would be at the end this url https://developers.google.com/actions/media/tools/schema_livetv.json#/definitions/generics/MediaService

and then to create the according type definition. I've seen there is a way to set a configuration of $refOptions in the cli commands, but I'm completely clueless how to be able to use this option.

If there is feedback of how I could create the types of this json schema definition in an alternative way - please let me know! :)

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

1 participant