YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.17k stars 323 forks source link

Generated JSON schema for specific type is missing properties #519

Open 0xJem opened 1 year ago

0xJem commented 1 year ago

I am trying to use TJS to generate a JSONSchema object, and have successfully used it in the past. However, a specific types file that I am passing is being generated as a JSONSchema object, but without properties. This is tripping up some code downstream from these steps.

Types file: https://github.com/OlympusDAO/subgraph-cache/blob/6a7da6cf6e8a0a47e30ad9efb75e68081f20821a/generated/BondPurchase_types.ts

Generated JSONSchema: https://github.com/OlympusDAO/subgraph-cache/blob/6a7da6cf6e8a0a47e30ad9efb75e68081f20821a/generated/BondPurchase.jsonschema

Note that there are definitions, but no properties.

This is the code used to generate the JSONSchema:

export const generateJSONSchema = async (type: string, typesFilename: string): Promise<$RefParser.JSONSchema> => {
  console.log(`Generating JSONSchema for object ${type}`);
  // Convert to JSONSchema
  const jsonSchemaProgram = TJS.getProgramFromFiles([resolve(typesFilename)], {
    strictNullChecks: true,
  });
  const jsonSchema = TJS.generateSchema(jsonSchemaProgram, type);
  if (!jsonSchema) {
    throw new Error(`Unable to generate JSONSchema for type ${type} and types file ${typesFilename}`);
  }

  // We need to de-reference types in the JSONSchema, otherwise the BigQuery schema library will complain
  const derefSchema = await $RefParser.dereference(jsonSchema as JSONSchema7);
  return derefSchema;
};
0xJem commented 1 year ago

However this types file is successfully converted into a JSONSchema:

https://github.com/OlympusDAO/subgraph-cache/blob/6a7da6cf6e8a0a47e30ad9efb75e68081f20821a/generated/MarketClosedEvent_types.ts

https://github.com/OlympusDAO/subgraph-cache/blob/6a7da6cf6e8a0a47e30ad9efb75e68081f20821a/generated/MarketClosedEvent.jsonschema