code here:
import * as TJSG from 'ts-json-schema-generator';
const tsSchemaPath = 'demo.ts';
const generatorTsSchema = TJSG.createGenerator({
path: tsSchemaPath,
skipTypeCheck: true,
topRef: false,
expose: 'all',
}).createSchema('paths');
console.log('generator:',generatorTsSchema);
demo.ts typescript file
export interface paths {
'/root/getQueryParam-v3/{id}': {
get: {
parameters: {
query: {
queryParam19?: {
a: Record<string, never>;
b: Record<string, never>;
};
queryParam20?: Record<string, never>;
queryParam21?: Record<string, never>;
queryParam22?: components['schemas']['recordTest.89e6481d'];
queryParam23?: components['schemas']['Date.8c67fa4a'];
};
};
};
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
'recordTest.89e6481d': {
a: components['schemas']['Record<string,string>.992e92f3'];
b: components['schemas']['Record<any,any>.992e92f3'];
c: components['schemas']['Record<string,never>.992e92f3'];
/** Format: date-time */
d: string;
};
'Record<string,string>.992e92f3': Record<string, never>;
'Record<any,any>.992e92f3': Record<string, never>;
'Record<string,never>.992e92f3': Record<string, never>;
/** Format: date-time */
'Date.8c67fa4a': string;
};
}
out put console.log:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"/root/getQueryParam-v3/{id}": {
"type": "object",
"properties": {
"get": {
"type": "object",
"properties": {
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "object",
"properties": {
"queryParam19": {
"type": "object",
"properties": {
"a": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"b": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
}
},
"required": ["a", "b"],
"additionalProperties": false
},
"queryParam20": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"queryParam21": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"queryParam22": {
"type": "object",
"properties": {
"a": {
"$ref": "#/definitions/components"
},
"b": {
"$ref": "#/definitions/components"
},
"c": {
"$ref": "#/definitions/components"
},
"d": {
"type": "string",
"description": "Format: date-time"
}
},
"required": ["a", "b", "c", "d"],
"additionalProperties": false
},
"queryParam23": {
"type": "string",
"description": "Format: date-time"
}
},
"additionalProperties": false
}
},
"required": ["query"],
"additionalProperties": false
}
},
"required": ["parameters"],
"additionalProperties": false
}
},
"required": ["get"],
"additionalProperties": false
}
},
"required": ["/root/getQueryParam-v3/{id}"],
"additionalProperties": false,
"description": "This file was auto-generated by",
"definitions": {
"Record<string,never>": {
"type": "object",
"additionalProperties": {
"not": {}
}
},
"components": {
"type": "object",
"properties": {
"schemas": {
"type": "object",
"properties": {
"recordTest.89e6481d": {
"type": "object",
"properties": {
"a": {
"$ref": "#/definitions/components"
},
"b": {
"$ref": "#/definitions/components"
},
"c": {
"$ref": "#/definitions/components"
},
"d": {
"type": "string",
"description": "Format: date-time"
}
},
"required": ["a", "b", "c", "d"],
"additionalProperties": false
},
"Record<string,string>.992e92f3": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"Record<any,any>.992e92f3": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"Record<string,never>.992e92f3": {
"$ref": "#/definitions/Record%3Cstring%2Cnever%3E"
},
"Date.8c67fa4a": {
"type": "string",
"description": "Format: date-time"
}
},
"required": [
"recordTest.89e6481d",
"Record<string,string>.992e92f3",
"Record<any,any>.992e92f3",
"Record<string,never>.992e92f3",
"Date.8c67fa4a"
],
"additionalProperties": false
}
},
"required": ["schemas"],
"additionalProperties": false
}
}
}
many error ref: "$ref": "#/definitions/components"
code here:
demo.ts typescript file
out put console.log:
many error ref: "$ref": "#/definitions/components"