├── test ├── invalid-data │ ├── script-empty │ │ ├── main.ts │ │ └── index.test.ts │ ├── duplicates │ │ ├── import1.ts │ │ ├── import2.ts │ │ └── main.ts │ ├── non-union-discriminator │ │ └── main.ts │ ├── missing-discriminator │ │ ├── main.ts │ │ └── index.test.ts │ └── duplicate-discriminator │ │ ├── main.ts │ │ └── index.test.ts ├── valid-data │ ├── never │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── symbol-union │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-aliases-tuple-empty │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── undefined-alias │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-rest-only │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-aliases-primitive │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── export-star-prune-unreachable │ │ ├── dep2.ts │ │ ├── dep.ts │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-aliases-tuple │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-any │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── undefined-union │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-max-items-optional │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-min-items-1 │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── function-parameters-declaration │ │ ├── main.ts │ │ ├── schema.json │ │ └── index.test.ts │ ├── symbol │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-primitive-with-id │ │ ├── main.ts │ │ ├── schema.json │ │ └── index.test.ts │ ├── type-aliases-tuple-only-rest │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-never │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-symbol │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-min-items-2 │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-min-max-items │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── enums-number │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── function-function-syntax │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── enums-string │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── function-parameters-variable-assignment │ │ ├── main.ts │ │ ├── schema.json │ │ └── index.test.ts │ ├── import-simple │ │ ├── module.ts │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-widened │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── array-min-max-items-optional │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-typeof-value │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── multiple-roots2 │ │ ├── Asset.ts │ │ └── schema │ │ │ ├── MyAsset.ts │ │ │ ├── AssetType.ts │ │ │ └── index.test.ts │ ├── type-aliases-tuple-rest │ │ ├── main.ts │ │ └── index.test.ts │ ├── keyof-typeof-enum │ │ ├── Size.ts │ │ ├── index.test.ts │ │ └── main.ts │ ├── literal-object-type │ │ ├── main.ts │ │ └── index.test.ts │ ├── string-template-expression-literals-import │ │ ├── types.ts │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-keyof-object-function │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-empty-exclude │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── annotation-empty │ │ ├── main.ts │ │ └── schema.json │ ├── any-unknown │ │ ├── main.ts │ │ └── index.test.ts │ ├── enums-initialized │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── literal-array-type │ │ ├── main.ts │ │ └── index.test.ts │ ├── literal-index-type │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-aliases-tuple-optional-items │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-intersection-union-primitive │ │ ├── main.ts │ │ ├── schema.json │ │ └── index.test.ts │ ├── type-keyof-tuple │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── export-star │ │ ├── literal.ts │ │ ├── main.ts │ │ ├── object.ts │ │ └── index.test.ts │ ├── type-mapped-native-single-literal │ │ ├── main.ts │ │ └── index.test.ts │ ├── interface-recursion │ │ ├── main.ts │ │ └── index.test.ts │ ├── simple-object │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-tuple-nested-rest-uniform │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-typeof-object-property │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── class-recursion │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-annotated-string │ │ ├── size.ts │ │ ├── index.test.ts │ │ └── main.ts │ ├── enums-compute │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── keyof-typeof-x │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── string-literals-null │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-indexed-access-tuple-1 │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-indexed-access-tuple-2 │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-uri │ │ ├── main.ts │ │ └── index.test.ts │ ├── class-new-expression │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── function-parameters-optional │ │ ├── main.ts │ │ └── index.test.ts │ ├── function-parameters-required │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-default │ │ ├── main.ts │ │ └── index.test.ts │ ├── re-export-with-asterisk │ │ ├── main.ts │ │ ├── lib.ts │ │ └── index.test.ts │ ├── shorthand-array │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-date │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-native │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-template-literal │ │ ├── main.ts │ │ └── index.test.ts │ ├── undefined-property │ │ ├── main.ts │ │ └── index.test.ts │ ├── annotation-readOnly │ │ ├── main.ts │ │ └── index.test.ts │ ├── annotation-writeOnly │ │ ├── main.ts │ │ └── index.test.ts │ ├── import-exposed │ │ ├── main.ts │ │ ├── module.ts │ │ └── index.test.ts │ ├── lowercase │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-literal │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-tuple-nested-rest │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-typeof-class-static-property │ │ ├── main.ts │ │ ├── schema.json │ │ └── index.test.ts │ ├── array-function-generics │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-arrays │ │ ├── main.ts │ │ └── index.test.ts │ ├── import-anonymous │ │ ├── main.ts │ │ ├── module.ts │ │ └── index.test.ts │ ├── interface-single │ │ ├── main.ts │ │ └── index.test.ts │ ├── nullable-null │ │ ├── main.ts │ │ └── index.test.ts │ ├── object-literal-expression │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── string-template-literals │ │ ├── main.ts │ │ └── index.test.ts │ ├── structure-extra-props-symbol │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-indexed-access-type-union │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-enum-null │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── interface-computed-property-name │ │ ├── module.ts │ │ ├── index.test.ts │ │ └── main.ts │ ├── interface-property-dash │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-regexp │ │ ├── main.ts │ │ └── index.test.ts │ ├── enums-member │ │ ├── main.ts │ │ └── index.test.ts │ ├── enums-mixed │ │ ├── main.ts │ │ └── index.test.ts │ ├── function-parameters-default-value │ │ ├── main.ts │ │ └── index.test.ts │ ├── promise-generics │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-indexed-access-tuple-union │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-keyof-object │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-satisfies │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-typeof-class │ │ ├── main.ts │ │ └── index.test.ts │ ├── enums-template-literal │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-void │ │ ├── main.ts │ │ └── index.test.ts │ ├── literal-object-type-with-computed-props │ │ ├── module.ts │ │ ├── index.test.ts │ │ └── main.ts │ ├── string-literals-inline │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-object │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-recursive-generics-anonymous │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-number │ │ ├── main.ts │ │ └── index.test.ts │ ├── array-literal-spread │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-simple │ │ ├── main.ts │ │ └── index.test.ts │ ├── interface-extra-props │ │ ├── main.ts │ │ └── index.test.ts │ ├── string-literals │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-recursive-anonymous │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-recursive-generics-export │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-extend │ │ ├── main.ts │ │ └── index.test.ts │ ├── class-extra-props │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-recursive-export │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-enum-number │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-infer │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-extend-circular │ │ ├── main.ts │ │ └── index.test.ts │ ├── object-function-expression │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-enum │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-prefixed-number │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-intersection-conflict │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-array │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── generic-recursive │ │ ├── main.ts │ │ └── index.test.ts │ ├── interface-array │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-infer-rest │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-intersection-union-enum │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-enum-optional │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-simple │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-default-conditional │ │ ├── main.ts │ │ └── index.test.ts │ ├── interface-extended-extra-props │ │ ├── main.ts │ │ └── index.test.ts │ ├── never-record │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── structure-recursion │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-omit │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-multiple │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-aliases-union │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-index │ │ ├── main.ts │ │ └── index.test.ts │ ├── interface-multi │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-infer-recursive │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-indexed-access-object-1 │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-optional │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-maps │ │ ├── index.test.ts │ │ └── main.ts │ ├── annotation-union-if-then-enum │ │ ├── main.ts │ │ └── index.test.ts │ ├── class-jsdoc │ │ └── index.test.ts │ ├── class-multi │ │ ├── index.test.ts │ │ └── main.ts │ ├── const-spread │ │ ├── index.test.ts │ │ └── main.ts │ ├── enums-union │ │ └── index.test.ts │ ├── ignore-export │ │ ├── index.test.ts │ │ └── main.ts │ ├── structure-extra-props │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-indexed-access-object-2 │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-typeof │ │ ├── index.test.ts │ │ ├── main.ts │ │ └── schema.json │ ├── type-union │ │ └── index.test.ts │ ├── class-single │ │ └── index.test.ts │ ├── generic-hell │ │ └── index.test.ts │ ├── unique-symbol │ │ ├── index.test.ts │ │ └── main.ts │ ├── annotation-ref │ │ └── index.test.ts │ ├── class-generics │ │ ├── index.test.ts │ │ └── main.ts │ ├── generic-nested │ │ └── index.test.ts │ ├── type-aliases-anonymous │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-primitives │ │ └── index.test.ts │ ├── function-generic │ │ └── index.test.ts │ ├── function-parameters-jsdoc │ │ ├── main.ts │ │ └── index.test.ts │ ├── promise-extensions │ │ └── index.test.ts │ ├── type-typeof-enum │ │ └── index.test.ts │ ├── type-typeof-keys │ │ ├── index.test.ts │ │ ├── main.ts │ │ └── schema.json │ ├── type-union-tagged │ │ └── index.test.ts │ ├── annotation-comment │ │ ├── index.test.ts │ │ └── main.ts │ ├── annotation-example │ │ └── index.test.ts │ ├── annotation-id │ │ ├── main.ts │ │ └── index.test.ts │ ├── annotation-nullable-definition │ │ ├── main.ts │ │ └── index.test.ts │ ├── binary-expression │ │ └── index.test.ts │ ├── class-inheritance │ │ ├── index.test.ts │ │ └── main.ts │ ├── generic-anonymous │ │ ├── index.test.ts │ │ └── main.ts │ ├── generic-indexed-access-constraint │ │ ├── main.ts │ │ └── index.test.ts │ ├── generic-multiargs │ │ ├── index.test.ts │ │ └── main.ts │ ├── structure-private │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-aliases-mixed │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-extends-never │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-intersection │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-mapped-index-as │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-typeof-function │ │ ├── index.test.ts │ │ └── main.ts │ ├── exported-enums-union │ │ └── index.test.ts │ ├── namespace-deep-1 │ │ └── index.test.ts │ ├── string-literals-hack │ │ └── index.test.ts │ ├── structure-anonymous │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-conditional-infer-nested │ │ ├── main.ts │ │ ├── index.test.ts │ │ └── schema.json │ ├── type-mapped-exclude │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-mapped-generic │ │ ├── index.test.ts │ │ └── main.ts │ ├── annotation-deprecated │ │ └── main.ts │ ├── import-internal │ │ ├── index.test.ts │ │ └── main.ts │ ├── multiple-roots1 │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-enum │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-indexed-circular │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-intersection-partial-conflict │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-intersection-recursive-interface │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-additional-props │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-named-tuple-member │ │ └── index.test.ts │ ├── type-conditional-jsdoc │ │ └── index.test.ts │ ├── type-conditional-simple │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-conditional-union │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-mapped-union-union │ │ ├── index.test.ts │ │ └── main.ts │ ├── namespace-deep-2 │ │ └── index.test.ts │ ├── namespace-deep-3 │ │ ├── index.test.ts │ │ ├── ns-root.ts │ │ └── ns-sub.ts │ ├── string-literals-intrinsic │ │ └── index.test.ts │ ├── type-conditional-exclude │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-indexed-access-keyof │ │ ├── index.test.ts │ │ └── main.ts │ ├── string-literal-property-names │ │ └── index.test.ts │ ├── type-conditional-narrowing │ │ └── index.test.ts │ ├── type-date-annotation │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-indexed-circular-access │ │ └── index.test.ts │ ├── type-intersection-with-arrays │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-mapped-double-exclude │ │ └── index.test.ts │ ├── type-mapped-exported-aliases │ │ └── index.test.ts │ ├── type-recursive-deep-exclude │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-aliases-local-namespace │ │ └── index.test.ts │ ├── type-aliases-union-namespace │ │ └── index.test.ts │ ├── type-conditional-inheritance │ │ └── index.test.ts │ ├── type-mapped-index-as-template │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-index-as-with-conditional │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-intersection │ │ └── index.test.ts │ ├── type-intersection-partial-conflict-ref │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-mapped-union-intersection │ │ └── index.test.ts │ ├── type-conditional-infer-tuple-xor │ │ └── index.test.ts │ ├── type-intersection-aliased-union │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-intersection-partial-conflict-union │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-tuple-nested-rest-to-union │ │ ├── index.test.ts │ │ └── main.ts │ ├── annotation-union-if-then │ │ ├── index.test.ts │ │ └── main.ts │ ├── discriminator │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-conditional-tuple-narrowing │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-intersection-partial-conflict-union-alias │ │ ├── main.ts │ │ └── index.test.ts │ ├── type-conditional-exclude-narrowing │ │ └── index.test.ts │ ├── type-intersection-additional-props │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-mapped-pick-union-alias │ │ └── index.test.ts │ ├── string-template-expression-literals │ │ └── index.test.ts │ ├── type-conditional-exclude-complex │ │ └── index.test.ts │ ├── type-conditional-infer-tail-recursion │ │ └── index.test.ts │ ├── annotation-description-override │ │ └── index.test.ts │ ├── type-intersection-union-recursive-interface │ │ ├── index.test.ts │ │ └── main.ts │ ├── type-intersection-union │ │ ├── index.test.ts │ │ └── main.ts │ └── object-required │ │ └── main.ts ├── minify │ └── schema.ts ├── sourceless-nodes │ ├── key │ │ ├── types1.ts │ │ ├── types2.ts │ │ └── source.ts │ └── source.ts └── config │ ├── no-ref-encode │ ├── main.ts │ ├── schema.json │ └── index.test.ts │ ├── tsconfig-support │ └── src │ │ ├── import1.ts │ │ └── main.ts │ ├── jsdoc-description-only │ ├── main.ts │ ├── schema.json │ └── index.test.ts │ ├── jsdoc-inheritance-exclude │ ├── main.ts │ └── schema.json │ ├── functions-hide │ ├── main.ts │ ├── index.test.ts │ └── schema.json │ ├── custom-formatter-configuration-circular │ └── main.ts │ ├── functions-comment │ ├── main.ts │ └── index.test.ts │ ├── mapped-intersection │ ├── main.ts │ └── index.test.ts │ ├── function-parameters-all │ ├── main.ts │ └── index.test.ts │ ├── multiple-types │ └── index.test.ts │ ├── mapped-index-any │ ├── index.test.ts │ └── main.ts │ ├── multiple-types-all │ └── index.test.ts │ ├── additional-properties │ └── index.test.ts │ ├── arrow-function-parameters │ └── index.test.ts │ ├── mapped-intersection-index │ ├── index.test.ts │ └── main.ts │ ├── jsdoc-hidden-types │ ├── main.ts │ └── index.test.ts │ ├── jsdoc-hidden │ └── index.test.ts │ ├── mapped-intersection-complex │ └── index.test.ts │ ├── jsdoc-complex-none │ └── index.test.ts │ ├── jsdoc-inheritance │ ├── index.test.ts │ └── main.ts │ ├── jsdoc-complex-basic │ └── index.test.ts │ ├── expose-all-topref-true │ └── index.test.ts │ ├── expose-all-topref-false │ └── index.test.ts │ ├── expose-none-topref-true │ └── index.test.ts │ ├── expose-export-topref-true │ └── index.test.ts │ └── expose-none-topref-false │ └── index.test.ts ├── .gitattributes ├── .prettierignore ├── src ├── Utils │ ├── StringMap.ts │ ├── uniqueArray.ts │ ├── isHidden.ts │ ├── symbolAtNode.ts │ ├── notNever.ts │ ├── castArray.ts │ ├── hasJsDocTag.ts │ └── uniqueTypeArray.ts ├── Schema │ ├── Schema.ts │ ├── Definition.ts │ └── RawType.ts ├── Type │ ├── PrimitiveType.ts │ ├── AnyType.ts │ ├── VoidType.ts │ ├── NeverType.ts │ ├── HiddenType.ts │ ├── NullType.ts │ ├── UndefinedType.ts │ ├── NumberType.ts │ ├── SymbolType.ts │ ├── BooleanType.ts │ ├── InferType.ts │ ├── BaseType.ts │ └── ArrayType.ts ├── MutableParser.ts ├── Interfaces │ ├── MutableParser.ts │ ├── MutableTypeFormatter.ts │ ├── SubNodeParser.ts │ ├── AnnotationsReader.ts │ ├── SubTypeFormatter.ts │ └── TypeFormatter.ts ├── MutableTypeFormatter.ts ├── SubNodeParser.ts ├── AnnotationsReader.ts ├── SubTypeFormatter.ts └── TypeFormatter.ts ├── factory └── index.ts ├── bin └── ts-json-schema-generator.js ├── tsconfig.eslint.json ├── .gitignore ├── .autorc.json ├── .github └── dependabot.yml └── .prettierrc.json /test/invalid-data/script-empty/main.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ts text eol=lf 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | test/valid-data/**/*.json 3 | -------------------------------------------------------------------------------- /test/invalid-data/duplicates/import1.ts: -------------------------------------------------------------------------------- 1 | export type A = number; 2 | -------------------------------------------------------------------------------- /test/invalid-data/duplicates/import2.ts: -------------------------------------------------------------------------------- 1 | export type A = string; 2 | -------------------------------------------------------------------------------- /test/valid-data/never/main.ts: -------------------------------------------------------------------------------- 1 | export type BasicNever = never; 2 | -------------------------------------------------------------------------------- /test/minify/schema.ts: -------------------------------------------------------------------------------- 1 | export type Schema = { 2 | a?: number; 3 | }; 4 | -------------------------------------------------------------------------------- /test/valid-data/symbol-union/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = string | symbol; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-empty/main.ts: -------------------------------------------------------------------------------- 1 | export type MyTuple = []; 2 | -------------------------------------------------------------------------------- /test/valid-data/undefined-alias/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = undefined; 2 | -------------------------------------------------------------------------------- /test/valid-data/array-rest-only/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [...string[]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive/main.ts: -------------------------------------------------------------------------------- 1 | export type MyString = string; 2 | -------------------------------------------------------------------------------- /test/valid-data/export-star-prune-unreachable/dep2.ts: -------------------------------------------------------------------------------- 1 | export type DepType2 = string; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple/main.ts: -------------------------------------------------------------------------------- 1 | export type MyTuple = [string, number]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-any/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Record; 2 | -------------------------------------------------------------------------------- /test/valid-data/undefined-union/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = undefined | string; 2 | -------------------------------------------------------------------------------- /src/Utils/StringMap.ts: -------------------------------------------------------------------------------- 1 | export interface StringMap { 2 | [key: string]: T; 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/array-max-items-optional/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [string?, string?]; 2 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-1/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [string, ...string[]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-declaration/main.ts: -------------------------------------------------------------------------------- 1 | export function myFunction() {} 2 | -------------------------------------------------------------------------------- /test/valid-data/symbol/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | foo: symbol; 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive-with-id/main.ts: -------------------------------------------------------------------------------- 1 | export type MyString = string; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-only-rest/main.ts: -------------------------------------------------------------------------------- 1 | export type MyTuple = [...string[]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-never/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = { [K in never]: never }; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-symbol/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Record; 2 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-2/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [string, string, ...string[]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [string, string, string]; 2 | -------------------------------------------------------------------------------- /test/valid-data/enums-number/main.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | X = 1, 3 | Y = 2, 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/function-function-syntax/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = function () {}; 2 | -------------------------------------------------------------------------------- /test/valid-data/enums-string/main.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | X = "x", 3 | Y = "y", 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-variable-assignment/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = () => {}; 2 | -------------------------------------------------------------------------------- /test/valid-data/import-simple/module.ts: -------------------------------------------------------------------------------- 1 | export interface MySubObject { 2 | value: number; 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-widened/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = { [K in string]?: boolean }; 2 | -------------------------------------------------------------------------------- /test/sourceless-nodes/key/types1.ts: -------------------------------------------------------------------------------- 1 | export type A = 1; 2 | export type B = 2; 3 | export type C = 3; 4 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items-optional/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [string, string, string?]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-value/main.ts: -------------------------------------------------------------------------------- 1 | const FOO = "foo"; 2 | 3 | export type MyType = typeof FOO; 4 | -------------------------------------------------------------------------------- /test/config/no-ref-encode/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = T; 2 | 3 | export type MyObject = MyType; 4 | -------------------------------------------------------------------------------- /test/config/tsconfig-support/src/import1.ts: -------------------------------------------------------------------------------- 1 | export interface MySubObject { 2 | subValue: string; 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots2/Asset.ts: -------------------------------------------------------------------------------- 1 | export interface Asset { 2 | readonly type: "One" | "Two"; 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-rest/main.ts: -------------------------------------------------------------------------------- 1 | export type MyTuple = [string, number, string?, ...number[]]; 2 | -------------------------------------------------------------------------------- /src/Schema/Schema.ts: -------------------------------------------------------------------------------- 1 | import type { JSONSchema7 } from "json-schema"; 2 | 3 | export type Schema = JSONSchema7; 4 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-enum/Size.ts: -------------------------------------------------------------------------------- 1 | export enum Size { 2 | Small, 3 | Medium, 4 | Large, 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/literal-object-type/main.ts: -------------------------------------------------------------------------------- 1 | const obj = { abc: "def" }; 2 | 3 | export type MyType = typeof obj; 4 | -------------------------------------------------------------------------------- /test/valid-data/string-template-expression-literals-import/types.ts: -------------------------------------------------------------------------------- 1 | export type MyType = "one" | "two" | "three"; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object-function/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = keyof { 2 | key: () => number; 3 | }; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-empty-exclude/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = { [K in Exclude<"key", "key">]: never }; 2 | -------------------------------------------------------------------------------- /src/Schema/Definition.ts: -------------------------------------------------------------------------------- 1 | import type { JSONSchema7 } from "json-schema"; 2 | 3 | export type Definition = JSONSchema7; 4 | -------------------------------------------------------------------------------- /test/config/jsdoc-description-only/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Some description here 3 | */ 4 | export interface MyObject {} 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-empty/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @customEmptyAnnotation 3 | */ 4 | export interface MyObject {} 5 | -------------------------------------------------------------------------------- /test/valid-data/any-unknown/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | value1: any; 3 | value2: unknown; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-initialized/main.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | X = 10, 3 | Y, 4 | Z, 5 | A = 1, 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/literal-array-type/main.ts: -------------------------------------------------------------------------------- 1 | const arr = ["abc", "def"] as const; 2 | export type MyType = typeof arr; 3 | -------------------------------------------------------------------------------- /test/valid-data/literal-index-type/main.ts: -------------------------------------------------------------------------------- 1 | const arr = ["abc", "def"]; 2 | export type MyType = (typeof arr)[number]; 3 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-optional-items/main.ts: -------------------------------------------------------------------------------- 1 | export type MyTuple = [string, number, string?, number?]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-primitive/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = (number | string) & (number | boolean); 2 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-tuple/main.ts: -------------------------------------------------------------------------------- 1 | type SomeTuple = [12, "baz"]; 2 | 3 | export type MyType = keyof SomeTuple; 4 | -------------------------------------------------------------------------------- /test/valid-data/export-star/literal.ts: -------------------------------------------------------------------------------- 1 | export type A = 1; 2 | 3 | export type B = "string"; 4 | 5 | type C = "internal"; 6 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots2/schema/MyAsset.ts: -------------------------------------------------------------------------------- 1 | import { Asset } from "../Asset"; 2 | 3 | export type MyAsset = Asset; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-native-single-literal/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Pick, "a">; 2 | -------------------------------------------------------------------------------- /test/valid-data/interface-recursion/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | propA: number; 3 | propB: MyObject; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/simple-object/main.ts: -------------------------------------------------------------------------------- 1 | export interface SimpleObject { 2 | required: string; 3 | optional?: number; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest-uniform/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [number, ...[number, number, ...[number, ...[]]]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-object-property/main.ts: -------------------------------------------------------------------------------- 1 | const Foo = { bar: "foo" }; 2 | 3 | export type MyType = typeof Foo.bar; 4 | -------------------------------------------------------------------------------- /src/Type/PrimitiveType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export abstract class PrimitiveType extends BaseType {} 4 | -------------------------------------------------------------------------------- /test/valid-data/class-recursion/main.ts: -------------------------------------------------------------------------------- 1 | export class MyObject { 2 | public propA: number; 3 | public propB: MyObject; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-annotated-string/size.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Size 3 | * @pattern ^S|M|L$ 4 | */ 5 | export type Size = string; 6 | -------------------------------------------------------------------------------- /test/valid-data/enums-compute/main.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | X = 1 << 1, 3 | Y = 1 << 2, 4 | Z = X | Y, 5 | A = 1, 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-x/main.ts: -------------------------------------------------------------------------------- 1 | const myprop = 0; 2 | export const mymap = { myprop }; 3 | export type MyType = keyof typeof mymap; 4 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-null/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | enum1: "a" | "b" | null; 3 | enum2: "a" | "b"; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-1/main.ts: -------------------------------------------------------------------------------- 1 | const arr: ["foo", "bar"] = ["foo", "bar"]; 2 | export type MyType = (typeof arr)[0]; 3 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-2/main.ts: -------------------------------------------------------------------------------- 1 | const arr: ["foo", "bar"] = ["foo", "bar"]; 2 | export type MyType = (typeof arr)[1]; 3 | -------------------------------------------------------------------------------- /test/valid-data/type-uri/main.ts: -------------------------------------------------------------------------------- 1 | type MyURL = URL; 2 | 3 | export interface MyObject { 4 | url: URL; 5 | urlAlias: MyURL; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/class-new-expression/main.ts: -------------------------------------------------------------------------------- 1 | class MyObject {} 2 | 3 | const obj = new MyObject(); 4 | 5 | export type MyType = typeof obj; 6 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-optional/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = (optionalString?: string) => { 2 | return "whatever"; 3 | }; 4 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-required/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = (requiredString: string) => { 2 | return "whatever"; 3 | }; 4 | -------------------------------------------------------------------------------- /test/valid-data/generic-default/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Generic; 2 | 3 | export interface Generic { 4 | foo: N; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/re-export-with-asterisk/main.ts: -------------------------------------------------------------------------------- 1 | export { MyObject } from "./lib"; 2 | import { MyEnum } from "./lib"; 3 | export { MyEnum }; 4 | -------------------------------------------------------------------------------- /test/valid-data/shorthand-array/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyType { 2 | numberArray: number[]; 3 | stringArray: readonly string[]; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/type-date/main.ts: -------------------------------------------------------------------------------- 1 | type MyDate = Date; 2 | 3 | export interface MyObject { 4 | date: Date; 5 | dateAlias: MyDate; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-native/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Partial, "b" | "c">>>; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-template-literal/main.ts: -------------------------------------------------------------------------------- 1 | type AorB = "A" | "B"; 2 | 3 | export type MyObject = Record<`letter-${AorB}`, string>; 4 | -------------------------------------------------------------------------------- /test/valid-data/undefined-property/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = { 2 | a: undefined; 3 | b: null; 4 | c: undefined | string; 5 | }; 6 | -------------------------------------------------------------------------------- /test/invalid-data/non-union-discriminator/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @discriminator name 3 | */ 4 | export interface MyType { 5 | name: string; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/annotation-readOnly/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | one?: string; 3 | /** @readOnly */ 4 | two?: number; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/annotation-writeOnly/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | one?: string; 3 | /** @writeOnly */ 4 | two?: number; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/import-exposed/main.ts: -------------------------------------------------------------------------------- 1 | import { MySubObject } from "./module"; 2 | 3 | export interface MyObject { 4 | field: MySubObject; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/import-simple/main.ts: -------------------------------------------------------------------------------- 1 | import { MySubObject } from "./module"; 2 | 3 | export interface MyObject { 4 | field: MySubObject; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/lowercase/main.ts: -------------------------------------------------------------------------------- 1 | /** The built-in color schemes, cased. */ 2 | type Foo = "Accent"; 3 | 4 | export type MyType = Lowercase; 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-literal/main.ts: -------------------------------------------------------------------------------- 1 | type SomeKeys = "a" | "b" | "c"; 2 | 3 | export type MyObject = { 4 | [K in SomeKeys]?: K; 5 | }; 6 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest/main.ts: -------------------------------------------------------------------------------- 1 | export type MyType = [{ a: number }, ...[{ b: string }, { c: number }, ...[{ d: boolean }, ...[]]]]; 2 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-class-static-property/main.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | static bar = "foo"; 3 | } 4 | 5 | export type MyType = typeof Foo.bar; 6 | -------------------------------------------------------------------------------- /factory/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./formatter.js"; 2 | export * from "./generator.js"; 3 | export * from "./parser.js"; 4 | export * from "./program.js"; 5 | -------------------------------------------------------------------------------- /test/invalid-data/duplicates/main.ts: -------------------------------------------------------------------------------- 1 | import { A as A1 } from "./import1"; 2 | import { A as A2 } from "./import2"; 3 | 4 | export type MyType = A1 | A2; 5 | -------------------------------------------------------------------------------- /test/valid-data/array-function-generics/main.ts: -------------------------------------------------------------------------------- 1 | export function arrayGenerics(a: T[], b: T[]): T[] { 2 | console.log(a, b); 3 | return b; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/export-star-prune-unreachable/dep.ts: -------------------------------------------------------------------------------- 1 | export interface SomeInterface { 2 | foo?: string; 3 | } 4 | 5 | export type DepType = string; 6 | -------------------------------------------------------------------------------- /test/valid-data/generic-arrays/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | numberArray: Array; 3 | stringArray: ReadonlyArray; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/import-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | import { MySubObject } from "./module"; 2 | 3 | export interface MyObject { 4 | field: MySubObject; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/interface-single/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | propA: number; 3 | propB: number; 4 | readonly propC: string; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/nullable-null/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | /** 3 | * @nullable 4 | */ 5 | optional?: MyObject | null; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/object-literal-expression/main.ts: -------------------------------------------------------------------------------- 1 | export const Foo = { 2 | x: 1, 3 | y: 1, 4 | }; 5 | 6 | export type MyType = keyof typeof Foo; 7 | -------------------------------------------------------------------------------- /test/valid-data/string-template-literals/main.ts: -------------------------------------------------------------------------------- 1 | type Result = "ok" | "fail" | `abort`; 2 | 3 | export interface MyObject { 4 | foo: Result; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/structure-extra-props-symbol/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | structure: { 3 | [name: string]: symbol; 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-type-union/main.ts: -------------------------------------------------------------------------------- 1 | export type Foo = { foo: number } | { foo: boolean }; 2 | 3 | export type MyType = Partial; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-null/main.ts: -------------------------------------------------------------------------------- 1 | enum Test { 2 | A = null, 3 | } 4 | 5 | export type MyObject = { 6 | [P in Test]?: string; 7 | }; 8 | -------------------------------------------------------------------------------- /test/config/tsconfig-support/src/main.ts: -------------------------------------------------------------------------------- 1 | import { MySubObject } from "@src/import1"; 2 | 3 | export interface MyObject { 4 | subObject: MySubObject; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/export-star/main.ts: -------------------------------------------------------------------------------- 1 | export * from "./literal"; 2 | export * from "./object"; 3 | 4 | export type External = 1; 5 | 6 | type Internal = 2; 7 | -------------------------------------------------------------------------------- /test/valid-data/interface-computed-property-name/module.ts: -------------------------------------------------------------------------------- 1 | export const key = "exportedKey"; 2 | 3 | export enum Keys { 4 | Key = "exportedEnumKey", 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/interface-property-dash/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | "with-dash": string; 3 | without: string; 4 | nodash: string; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/type-regexp/main.ts: -------------------------------------------------------------------------------- 1 | type MyRegExp = RegExp; 2 | 3 | export interface MyObject { 4 | regexp: RegExp; 5 | regexpAlias: MyRegExp; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/enums-member/main.ts: -------------------------------------------------------------------------------- 1 | export enum A { 2 | B, 3 | C, 4 | D, 5 | } 6 | 7 | export interface MyObject { 8 | code: A.B; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/enums-mixed/main.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | A, // = 0 3 | B = 1, 4 | C = true as any, 5 | D = "str" as any, 6 | E = null, 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-default-value/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = (paramWithDefault: string = "something") => { 2 | return "whatever"; 3 | }; 4 | -------------------------------------------------------------------------------- /test/valid-data/promise-generics/main.ts: -------------------------------------------------------------------------------- 1 | export type HasPromise = { a: Promise }; 2 | 3 | export type ConcreteHasPromise = HasPromise; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-union/main.ts: -------------------------------------------------------------------------------- 1 | type FormLayouts = ["horizontal", "inline", "vertical"]; 2 | export type FormLayout = FormLayouts[number]; 3 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | foo: 12; 3 | bar: "baz"; 4 | } 5 | 6 | export type MyType = keyof SomeInterface; 7 | -------------------------------------------------------------------------------- /test/valid-data/type-satisfies/main.ts: -------------------------------------------------------------------------------- 1 | const record = { x: "hello", y: "goodbye" } satisfies Record; 2 | export type MyType = keyof typeof record; 3 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-class/main.ts: -------------------------------------------------------------------------------- 1 | class MyClass { 2 | myValue: number; 3 | } 4 | 5 | export type MyObject = { 6 | classType: typeof MyClass; 7 | }; 8 | -------------------------------------------------------------------------------- /src/Utils/uniqueArray.ts: -------------------------------------------------------------------------------- 1 | export function uniqueArray(array: readonly T[]): T[] { 2 | return array.filter((value, index) => array.indexOf(value) === index); 3 | } 4 | -------------------------------------------------------------------------------- /test/valid-data/enums-template-literal/main.ts: -------------------------------------------------------------------------------- 1 | enum MyEnum { 2 | A = "a", 3 | B = "b", 4 | } 5 | 6 | export type MyObject = { 7 | prop?: `${MyEnum}`; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/generic-void/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | field: T; 3 | } 4 | 5 | export interface MyObject { 6 | value: MyGeneric; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/literal-object-type-with-computed-props/module.ts: -------------------------------------------------------------------------------- 1 | export const key = "exportedKey"; 2 | 3 | export enum Keys { 4 | Key = "exportedEnumKey", 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-inline/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | foo: "ok" | "fail" | "abort"; 3 | bar: "ok" | "fail" | "abort" | string; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-object/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | number: number; 3 | string: string; 4 | } 5 | 6 | export type MyAlias = MyObject; 7 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-generics-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | type Map = { [key: string]: T }; 2 | 3 | export type MyAlias = { 4 | a: Map; 5 | }; 6 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-number/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = Record; 2 | 3 | export type MyObjectKVSyntax = { 4 | [key: number]: string; 5 | }; 6 | -------------------------------------------------------------------------------- /test/valid-data/array-literal-spread/main.ts: -------------------------------------------------------------------------------- 1 | const BASE = ["foo", "bar"] as const; 2 | 3 | export const ALL = [...BASE, "baz"] as const; 4 | export type MyType = typeof ALL; 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-simple/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | field: T; 3 | } 4 | 5 | export interface MyObject { 6 | value: MyGeneric; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/interface-extra-props/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | required: string; 3 | optional?: number; 4 | [name: string]: string | number; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/string-literals/main.ts: -------------------------------------------------------------------------------- 1 | type result = "ok" | "fail" | "abort"; 2 | 3 | export interface MyObject { 4 | foo: result; 5 | bar: result | string; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/string-template-expression-literals-import/main.ts: -------------------------------------------------------------------------------- 1 | import { MyType } from "./types"; 2 | 3 | export interface MyObject { 4 | value: `_${MyType}`; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | interface MyObject { 2 | alias: MyAlias; 3 | self: MyObject; 4 | } 5 | 6 | export type MyAlias = MyObject; 7 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-generics-export/main.ts: -------------------------------------------------------------------------------- 1 | export type Map = { [key: string]: T }; 2 | 3 | export type MyAlias = { 4 | a: Map; 5 | }; 6 | -------------------------------------------------------------------------------- /test/valid-data/type-extend/main.ts: -------------------------------------------------------------------------------- 1 | export interface Type { 2 | value: "foo" | "bar"; 3 | } 4 | 5 | export interface MyObject extends Type { 6 | value: "foo"; 7 | } 8 | -------------------------------------------------------------------------------- /bin/ts-json-schema-generator.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // eslint-disable-next-line @typescript-eslint/no-require-imports 4 | require("../dist/ts-json-schema-generator.js"); 5 | -------------------------------------------------------------------------------- /test/config/jsdoc-inheritance-exclude/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Hello World. 3 | */ 4 | export type BaseType = number | string; 5 | 6 | export type MyType = Exclude; 7 | -------------------------------------------------------------------------------- /test/valid-data/class-extra-props/main.ts: -------------------------------------------------------------------------------- 1 | export class MyObject { 2 | public required: string; 3 | public optional?: number; 4 | [name: string]: string | number; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots2/schema/AssetType.ts: -------------------------------------------------------------------------------- 1 | import { Asset } from "../Asset"; 2 | 3 | const asset: Asset = { type: "One" }; 4 | export type AssetType = typeof asset.type; 5 | -------------------------------------------------------------------------------- /test/valid-data/re-export-with-asterisk/lib.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | Foo = "foo", 3 | Bar = "bar", 4 | } 5 | 6 | export interface MyObject { 7 | id: string; 8 | } 9 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-export/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | alias: MyAlias; 3 | self: MyObject; 4 | } 5 | 6 | export type MyAlias = MyObject; 7 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-number/main.ts: -------------------------------------------------------------------------------- 1 | enum Test { 2 | A, 3 | B, 4 | C, 5 | } 6 | 7 | export type MyObject = { 8 | [P in Test]: string; 9 | }; 10 | -------------------------------------------------------------------------------- /test/valid-data/import-anonymous/module.ts: -------------------------------------------------------------------------------- 1 | interface AnonymousSubType { 2 | subvalue: number; 3 | } 4 | 5 | export interface MySubObject { 6 | value: AnonymousSubType; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/import-exposed/module.ts: -------------------------------------------------------------------------------- 1 | export interface ExposedSubType { 2 | subvalue: number; 3 | } 4 | 5 | export interface MySubObject { 6 | value: ExposedSubType; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer/main.ts: -------------------------------------------------------------------------------- 1 | type InferObject = T extends { a: infer A } ? A : never; 2 | 3 | export type MyType = InferObject<{ a: string }>; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-extend-circular/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | foo: MyObject; 3 | } 4 | 5 | export interface MyType extends MyObject { 6 | bar: string; 7 | } 8 | -------------------------------------------------------------------------------- /src/MutableParser.ts: -------------------------------------------------------------------------------- 1 | import type { SubNodeParser } from "./SubNodeParser.js"; 2 | 3 | export interface MutableParser { 4 | addNodeParser(parser: SubNodeParser): MutableParser; 5 | } 6 | -------------------------------------------------------------------------------- /src/Type/AnyType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class AnyType extends BaseType { 4 | public getId(): string { 5 | return "any"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/Type/VoidType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class VoidType extends BaseType { 4 | public getId(): string { 5 | return "void"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/sourceless-nodes/source.ts: -------------------------------------------------------------------------------- 1 | // Async function to test promise unwrapping. 2 | export async function withInferredReturnType() { 3 | return { a: 1, b: `constant` as const }; 4 | } 5 | -------------------------------------------------------------------------------- /test/valid-data/export-star/object.ts: -------------------------------------------------------------------------------- 1 | export interface D { 2 | a: 1; 3 | } 4 | 5 | export class E { 6 | b: 2; 7 | } 8 | 9 | interface F { 10 | internal: true; 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/object-function-expression/main.ts: -------------------------------------------------------------------------------- 1 | const bar = () => ({ bar: 1 }); 2 | 3 | export const Foo = { 4 | x: bar(), 5 | }; 6 | 7 | export type MyType = keyof typeof Foo; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum/main.ts: -------------------------------------------------------------------------------- 1 | enum Test { 2 | A = "a", 3 | B = "b", 4 | C = "c", 5 | } 6 | 7 | export type MyObject = { 8 | [P in Test]: string; 9 | }; 10 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["src/**/*.ts", "factory/**/*.ts", "test/**/*.test.ts", "test/utils.ts", "bin/ts-json-schema-generator.js"] 4 | } 5 | -------------------------------------------------------------------------------- /src/Schema/RawType.ts: -------------------------------------------------------------------------------- 1 | import type { JSONSchema7Type, JSONSchema7TypeName } from "json-schema"; 2 | 3 | export type RawType = JSONSchema7Type; 4 | export type RawTypeName = JSONSchema7TypeName; 5 | -------------------------------------------------------------------------------- /src/Type/NeverType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class NeverType extends BaseType { 4 | public getId(): string { 5 | return "never"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/generic-prefixed-number/main.ts: -------------------------------------------------------------------------------- 1 | export type Range = number; 2 | 3 | export interface MyObject { 4 | angle: Range<-180, 180>; 5 | } 6 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-conflict/main.ts: -------------------------------------------------------------------------------- 1 | interface A { 2 | flag: boolean; 3 | } 4 | 5 | interface B { 6 | flag: true; 7 | } 8 | 9 | export type MyObject = A & B; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-array/main.ts: -------------------------------------------------------------------------------- 1 | type Test = string[]; 2 | 3 | type WithNumbers = { 4 | [P in keyof T]: T[P] | number; 5 | }; 6 | 7 | export type MyObject = WithNumbers; 8 | -------------------------------------------------------------------------------- /src/Interfaces/MutableParser.ts: -------------------------------------------------------------------------------- 1 | import type { SubNodeParser } from "./SubNodeParser.js"; 2 | 3 | export interface MutableParser { 4 | addNodeParser(parser: SubNodeParser): MutableParser; 5 | } 6 | -------------------------------------------------------------------------------- /src/Type/HiddenType.ts: -------------------------------------------------------------------------------- 1 | import { NeverType } from "./NeverType.js"; 2 | 3 | export class HiddenType extends NeverType { 4 | public getId(): string { 5 | return "hidden"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/config/functions-hide/main.ts: -------------------------------------------------------------------------------- 1 | type MyConstructor = new () => any; 2 | 3 | export type MyType = { 4 | foo?: (b: string) => number; 5 | bar?: number; 6 | baz?: MyConstructor; 7 | }; 8 | -------------------------------------------------------------------------------- /test/valid-data/generic-recursive/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | field: MyGeneric; 3 | } 4 | 5 | export interface MyObject { 6 | value: MyGeneric; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/interface-array/main.ts: -------------------------------------------------------------------------------- 1 | export type Tag = TagPrimitive | TagArray; 2 | export type TagPrimitive = string | number | boolean | null; 3 | export interface TagArray extends Array {} 4 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-rest/main.ts: -------------------------------------------------------------------------------- 1 | type GetRest = T extends [any, ...infer T] ? T : never; 2 | 3 | export type MyType = GetRest<[string, string, number, boolean]>; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-enum/main.ts: -------------------------------------------------------------------------------- 1 | type type1 = "foo" | "bar"; 2 | type type2 = type1 | "moo"; 3 | 4 | export type MyObject = { 5 | field1: type1; 6 | field2: type2; 7 | }; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-optional/main.ts: -------------------------------------------------------------------------------- 1 | enum Test { 2 | A = "a", 3 | B = "b", 4 | C = "c", 5 | } 6 | 7 | export type MyObject = { 8 | [P in Test]?: string; 9 | }; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-simple/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | foo: 12; 3 | bar: "baz"; 4 | } 5 | 6 | export type MyObject = { 7 | [K in keyof SomeInterface]?: boolean; 8 | }; 9 | -------------------------------------------------------------------------------- /src/Type/NullType.ts: -------------------------------------------------------------------------------- 1 | import { PrimitiveType } from "./PrimitiveType.js"; 2 | 3 | export class NullType extends PrimitiveType { 4 | public getId(): string { 5 | return "null"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/Type/UndefinedType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class UndefinedType extends BaseType { 4 | public getId(): string { 5 | return "undefined"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/config/custom-formatter-configuration-circular/main.ts: -------------------------------------------------------------------------------- 1 | export interface InnerInterface { 2 | exportValue: string; 3 | } 4 | 5 | export interface MyObject { 6 | inner: InnerInterface; 7 | } 8 | -------------------------------------------------------------------------------- /test/config/functions-comment/main.ts: -------------------------------------------------------------------------------- 1 | type MyConstructor = new () => any; 2 | 3 | export type MyType = { 4 | foo?: (b: string) => number; 5 | bar?: number; 6 | baz?: MyConstructor; 7 | }; 8 | -------------------------------------------------------------------------------- /test/valid-data/generic-default-conditional/main.ts: -------------------------------------------------------------------------------- 1 | export type MyObject = ConditionalGeneric; 2 | 3 | export type ConditionalGeneric = { 4 | foo: T; 5 | }; 6 | -------------------------------------------------------------------------------- /test/valid-data/interface-extended-extra-props/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject extends StringMap { 2 | param: string; 3 | } 4 | 5 | export interface StringMap { 6 | [key: string]: any; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/never-record/main.ts: -------------------------------------------------------------------------------- 1 | // This form is recommended by the typescript-eslint rule "ban-types" to mean 2 | // "an object with no properties" 3 | export type Mapped = Record; 4 | -------------------------------------------------------------------------------- /test/valid-data/never/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - never", assertValidSchema("never", "BasicNever")); 5 | -------------------------------------------------------------------------------- /test/valid-data/structure-recursion/main.ts: -------------------------------------------------------------------------------- 1 | export interface MySubObject { 2 | propA: number; 3 | propB: MySubObject; 4 | } 5 | 6 | export interface MyObject { 7 | sub: MySubObject; 8 | } 9 | -------------------------------------------------------------------------------- /test/valid-data/symbol/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - symbol", assertValidSchema("symbol", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-omit/main.ts: -------------------------------------------------------------------------------- 1 | interface Test { 2 | a: string; 3 | b: number; 4 | c: boolean; 5 | d: string[]; 6 | } 7 | 8 | export type MyObject = Omit; 9 | -------------------------------------------------------------------------------- /src/Type/NumberType.ts: -------------------------------------------------------------------------------- 1 | import { PrimitiveType } from "./PrimitiveType.js"; 2 | 3 | export class NumberType extends PrimitiveType { 4 | public getId(): string { 5 | return "number"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/Type/SymbolType.ts: -------------------------------------------------------------------------------- 1 | import { PrimitiveType } from "./PrimitiveType.js"; 2 | 3 | export class SymbolType extends PrimitiveType { 4 | public getId(): string { 5 | return "symbol"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/generic-multiple/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | field: T; 3 | } 4 | 5 | export interface MyObject { 6 | value1: MyGeneric; 7 | value2: MyGeneric; 8 | } 9 | -------------------------------------------------------------------------------- /test/valid-data/lowercase/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - lowercase", assertValidSchema("lowercase", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-union/main.ts: -------------------------------------------------------------------------------- 1 | type BasicArray = (string | number)[]; 2 | 3 | export interface MyObject { 4 | array: BasicArray; 5 | } 6 | 7 | export type MyUnion = (string | MyObject)[]; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | foo: 123; 3 | bar: "baz"; 4 | } 5 | 6 | export type MyObject = { 7 | [K in keyof SomeInterface]?: SomeInterface[K]; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/type-uri/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-uri", assertValidSchema("type-uri", "MyObject")); 5 | -------------------------------------------------------------------------------- /src/Type/BooleanType.ts: -------------------------------------------------------------------------------- 1 | import { PrimitiveType } from "./PrimitiveType.js"; 2 | 3 | export class BooleanType extends PrimitiveType { 4 | public getId(): string { 5 | return "boolean"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/enums-mixed/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-mixed", assertValidSchema("enums-mixed", "Enum")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-multi/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | subA: MySubObject; 3 | subB: MySubObject; 4 | } 5 | export interface MySubObject { 6 | propA: number; 7 | propB: number; 8 | } 9 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-recursive/main.ts: -------------------------------------------------------------------------------- 1 | type Recursive = T extends Array ? Recursive : T; 2 | 3 | export type MyType = Recursive<[[[string], [number, { a: string }]], [[boolean]]]>; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-date/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-date", assertValidSchema("type-date", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-object-1/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeObject { 2 | abc: "foo"; 3 | def?: "bar"; 4 | } 5 | 6 | const obj: SomeObject = { abc: "foo" }; 7 | export type MyType = typeof obj.abc; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-optional/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | foo?: 123; 3 | bar: "baz"; 4 | } 5 | 6 | export type MyObject = { 7 | [K in keyof SomeInterface]: SomeInterface[K]; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/type-maps/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-maps", assertValidSchema("type-maps", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/invalid-data/missing-discriminator/main.ts: -------------------------------------------------------------------------------- 1 | export interface A { 2 | type: string; 3 | } 4 | 5 | export interface B {} 6 | 7 | /** 8 | * @discriminator type 9 | */ 10 | export type MyType = A | B; 11 | -------------------------------------------------------------------------------- /test/valid-data/annotation-union-if-then-enum/main.ts: -------------------------------------------------------------------------------- 1 | type A = { kind: "a" | "A"; a: string }; 2 | type B = { kind: "b" | "B"; b: string }; 3 | 4 | /** 5 | * @discriminator kind 6 | */ 7 | export type AB = A | B; 8 | -------------------------------------------------------------------------------- /test/valid-data/any-unknown/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - any-unknown", assertValidSchema("any-unknown", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-jsdoc/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-jsdoc", assertValidSchema("class-jsdoc", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-multi/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-multi", assertValidSchema("class-multi", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/const-spread/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - const-spread", assertValidSchema("const-spread", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-compute/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-compute", assertValidSchema("enums-compute", "Enum")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-number/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-number", assertValidSchema("enums-number", "Enum")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-string/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-string", assertValidSchema("enums-string", "Enum")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-union", assertValidSchema("enums-union", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/ignore-export/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - ignore-export", assertValidSchema("ignore-export", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/ignore-export/main.ts: -------------------------------------------------------------------------------- 1 | // This constant should be ignored 2 | const foo = [].map(() => {}); 3 | 4 | export class A { 5 | a: string; 6 | } 7 | 8 | export class B { 9 | b: string; 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/never-record/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - never-record", assertValidSchema("never-record", "Mapped")); 5 | -------------------------------------------------------------------------------- /test/valid-data/structure-extra-props/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | structure: { 3 | required: string; 4 | optional?: number; 5 | [name: string]: string | number; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/symbol-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - symbol-union", assertValidSchema("symbol-union", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-extend/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-extend", assertValidSchema("type-extend", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-object-2/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeObject { 2 | abc: "foo"; 3 | def?: "bar"; 4 | } 5 | 6 | const obj: SomeObject = { abc: "foo" }; 7 | export type MyType = (typeof obj)["def"]; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-regexp/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-regexp", assertValidSchema("type-regexp", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof", assertValidSchema("type-typeof", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-union", assertValidSchema("type-union", "TypeUnion")); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.ts 2 | coverage/ 3 | dist/ 4 | cjs/ 5 | node_modules/ 6 | !auto.config.ts 7 | /.idea/ 8 | 9 | # local config for auto 10 | .env 11 | 12 | # Other package managers 13 | pnpm-lock.yaml 14 | yarn.lock 15 | -------------------------------------------------------------------------------- /src/MutableTypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { SubTypeFormatter } from "./SubTypeFormatter.js"; 2 | 3 | export interface MutableTypeFormatter { 4 | addTypeFormatter(formatter: SubTypeFormatter): MutableTypeFormatter; 5 | } 6 | -------------------------------------------------------------------------------- /src/SubNodeParser.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import type { NodeParser } from "./NodeParser.js"; 3 | 4 | export interface SubNodeParser extends NodeParser { 5 | supportsNode(node: ts.Node): boolean; 6 | } 7 | -------------------------------------------------------------------------------- /src/Utils/isHidden.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import { hasJsDocTag } from "./hasJsDocTag.js"; 3 | 4 | export function isNodeHidden(node: ts.Node): boolean { 5 | return hasJsDocTag(node, "hidden"); 6 | } 7 | -------------------------------------------------------------------------------- /src/Utils/symbolAtNode.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | 3 | export function symbolAtNode(node: ts.Node): ts.Symbol | undefined { 4 | //@ts-expect-error - internal typescript API 5 | return node.symbol; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/class-single/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-single", assertValidSchema("class-single", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-member/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-member", assertValidSchema("enums-member", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-hell/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-hell", assertValidSchema("generic-hell", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-void/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-void", assertValidSchema("generic-void", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/import-simple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - import-simple", assertValidSchema("import-simple", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-x/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - keyof-typeof-x", assertValidSchema("keyof-typeof-x", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/nullable-null/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - nullable-null", assertValidSchema("nullable-null", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-satisfies/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-satisfies", assertValidSchema("type-satisfies", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof/main.ts: -------------------------------------------------------------------------------- 1 | export namespace Types { 2 | export const STRING: string = "s"; 3 | export const NUMBER: number = 1; 4 | } 5 | 6 | export type MyType = typeof Types.STRING | typeof Types.NUMBER; 7 | -------------------------------------------------------------------------------- /test/valid-data/unique-symbol/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - unique-symbol", assertValidSchema("unique-symbol", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-ref/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-ref", assertValidSchema("annotation-ref", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/array-rest-only/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-rest-only", assertValidSchema("array-rest-only", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-generics/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-generics", assertValidSchema("class-generics", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-recursion/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-recursion", assertValidSchema("class-recursion", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-arrays/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-arrays", assertValidSchema("generic-arrays", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-default/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-default", assertValidSchema("generic-default", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-nested/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-nested", assertValidSchema("generic-nested", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/import-exposed/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - import-exposed", assertValidSchema("import-exposed", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-array/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-array", assertValidSchema("interface-array", "TagArray")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-multi/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-multi", assertValidSchema("interface-multi", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/promise-generics/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - promise-generics", assertValidSchema("promise-generics", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/shorthand-array/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - shorthand-array", assertValidSchema("shorthand-array", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/simple-object/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - simple-object", assertValidSchema("simple-object", "SimpleObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literals/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literals", assertValidSchema("string-literals", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | export type MyExportString = string; 2 | type MyPrivateString = string; 3 | 4 | export interface MyObject { 5 | export: MyExportString; 6 | private: MyPrivateString; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-any/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-any", assertValidSchema("type-mapped-any", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-primitives/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-primitives", assertValidSchema("type-primitives", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/undefined-alias/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - undefined-alias", assertValidSchema("undefined-alias", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/undefined-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - undefined-union", assertValidSchema("undefined-union", "MyType")); 5 | -------------------------------------------------------------------------------- /src/Interfaces/MutableTypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { SubTypeFormatter } from "./SubTypeFormatter.js"; 2 | 3 | export interface MutableTypeFormatter { 4 | addTypeFormatter(formatter: SubTypeFormatter): MutableTypeFormatter; 5 | } 6 | -------------------------------------------------------------------------------- /src/Interfaces/SubNodeParser.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import type { NodeParser } from "../NodeParser.js"; 3 | 4 | export interface SubNodeParser extends NodeParser { 5 | supportsNode(node: ts.Node): boolean; 6 | } 7 | -------------------------------------------------------------------------------- /src/Utils/notNever.ts: -------------------------------------------------------------------------------- 1 | import type { BaseType } from "../Type/BaseType.js"; 2 | import { NeverType } from "../Type/NeverType.js"; 3 | 4 | export function notNever(x: BaseType): boolean { 5 | return !(x instanceof NeverType); 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-1/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-min-items-1", assertValidSchema("array-min-items-1", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-2/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-min-items-2", assertValidSchema("array-min-items-2", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-multi/main.ts: -------------------------------------------------------------------------------- 1 | export class MyObject { 2 | public subA: MySubObject; 3 | public subB: MySubObject; 4 | } 5 | export class MySubObject { 6 | public propA: number; 7 | public propB: number; 8 | } 9 | -------------------------------------------------------------------------------- /test/valid-data/enums-initialized/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-initialized", assertValidSchema("enums-initialized", "Enum")); 5 | -------------------------------------------------------------------------------- /test/valid-data/function-generic/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - function-generic", assertValidSchema("function-generic", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-jsdoc/main.ts: -------------------------------------------------------------------------------- 1 | export const myFunction = ( 2 | /** 3 | * @description Inline parameter description 4 | */ 5 | requiredString: string, 6 | ) => { 7 | return "whatever"; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/generic-multiple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-multiple", assertValidSchema("generic-multiple", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/import-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - import-anonymous", assertValidSchema("import-anonymous", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-single/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-single", assertValidSchema("interface-single", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/promise-extensions/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - promise-extensions", assertValidSchema("promise-extensions", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-keyof-object", assertValidSchema("type-keyof-object", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-tuple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-keyof-tuple", assertValidSchema("type-keyof-tuple", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-enum", assertValidSchema("type-mapped-enum", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-number/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-number", assertValidSchema("type-mapped-number", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-enum", assertValidSchema("type-typeof-enum", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-keys/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-keys", assertValidSchema("type-typeof-keys", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-value/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-value", assertValidSchema("type-typeof-value", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-union-tagged/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-union-tagged", assertValidSchema("type-union-tagged", "Shape")); 5 | -------------------------------------------------------------------------------- /src/AnnotationsReader.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import type { Annotations } from "./Type/AnnotatedType.js"; 3 | 4 | export interface AnnotationsReader { 5 | getAnnotations(node: ts.Node): Annotations | undefined; 6 | } 7 | -------------------------------------------------------------------------------- /src/Utils/castArray.ts: -------------------------------------------------------------------------------- 1 | export function castArray(input: undefined | T | T[]): undefined | T[] { 2 | if (input === undefined) { 3 | return undefined; 4 | } 5 | 6 | return Array.isArray(input) ? input : [input]; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/annotation-comment/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-comment", assertValidSchema("annotation-comment", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-example/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-example", assertValidSchema("annotation-example", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-id/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @id #MyObject 3 | */ 4 | export interface MyObject { 5 | nested: MyNestedObject; 6 | } 7 | 8 | /** 9 | * @id #MyNestedObject 10 | */ 11 | export interface MyNestedObject {} 12 | -------------------------------------------------------------------------------- /test/valid-data/annotation-nullable-definition/main.ts: -------------------------------------------------------------------------------- 1 | export class Definition { 2 | name: string; 3 | } 4 | 5 | export class MyObject { 6 | /** 7 | * @nullable 8 | */ 9 | optional?: Definition[]; 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-min-max-items", assertValidSchema("array-min-max-items", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/binary-expression/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - binary-expression", assertValidSchema("binary-expression", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-extra-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-extra-props", assertValidSchema("class-extra-props", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-inheritance/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-inheritance", assertValidSchema("class-inheritance", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-anonymous", assertValidSchema("generic-anonymous", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-indexed-access-constraint/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | a?: T["a"]; 3 | b: T["b"]; 4 | } 5 | 6 | export interface MyObject extends MyGeneric<{ b: number }> {} 7 | -------------------------------------------------------------------------------- /test/valid-data/generic-multiargs/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-multiargs", assertValidSchema("generic-multiargs", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-recursive/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-recursive", assertValidSchema("generic-recursive", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - keyof-typeof-enum", assertValidSchema("keyof-typeof-enum", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/literal-array-type/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - literal-array-type", assertValidSchema("literal-array-type", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/literal-index-type/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - literal-index-type", assertValidSchema("literal-index-type", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/literal-object-type/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - literal-object-type", assertValidSchema("literal-object-type", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/never/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/BasicNever", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "BasicNever": { 6 | "not": {} 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/structure-private/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - structure-private", assertValidSchema("structure-private", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-mixed/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-mixed", assertValidSchema("type-aliases-mixed", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-tuple", assertValidSchema("type-aliases-tuple", "MyTuple")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-union", assertValidSchema("type-aliases-union", "MyUnion")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-extends-never/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-extends-never", assertValidSchema("type-extends-never", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection", assertValidSchema("type-intersection", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-array/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-array", assertValidSchema("type-mapped-array", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as/main.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | foo: 12; 3 | bar: "baz"; 4 | } 5 | 6 | export type MyObject = { 7 | [K in keyof SomeInterface as Capitalize]: `${K}.${SomeInterface[K]}`; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-index", assertValidSchema("type-mapped-index", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-native/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-native", assertValidSchema("type-mapped-native", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-never/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-never", assertValidSchema("type-mapped-never", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-simple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-simple", assertValidSchema("type-mapped-simple", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-symbol/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-symbol", assertValidSchema("type-mapped-symbol", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-class/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-class", assertValidSchema("type-typeof-class", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-function/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-function", assertValidSchema("type-typeof-function", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/undefined-property/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - undefined-property", assertValidSchema("undefined-property", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/array-literal-spread/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-literal-spread", assertValidSchema("array-literal-spread", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-new-expression/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - class-new-expression", assertValidSchema("class-new-expression", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/export-star/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - export-star", assertValidSchema("export-star", "*", undefined, { mainTsOnly: true })); 5 | -------------------------------------------------------------------------------- /test/valid-data/exported-enums-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - exported-enums-union", assertValidSchema("exported-enums-union", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | interface MyGeneric { 2 | a: A; 3 | b: B; 4 | } 5 | 6 | export interface MyObject { 7 | value1: MyGeneric; 8 | value2: MyGeneric; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/interface-recursion/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-recursion", assertValidSchema("interface-recursion", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/namespace-deep-1/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - namespace-deep-1", assertValidSchema("namespace-deep-1", "RootNamespace.Def")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-hack/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literals-hack", assertValidSchema("string-literals-hack", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-null/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literals-null", assertValidSchema("string-literals-null", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/structure-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - structure-anonymous", assertValidSchema("structure-anonymous", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/structure-recursion/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - structure-recursion", assertValidSchema("structure-recursion", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-object/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-object", assertValidSchema("type-aliases-object", "MyAlias")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-nested/main.ts: -------------------------------------------------------------------------------- 1 | type Nested>> = T extends Array ? (A extends Array ? B : never) : never; 2 | 3 | export type MyType = Nested<[[string, number], [boolean]]>; 4 | -------------------------------------------------------------------------------- /test/valid-data/type-extend-circular/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-extend-circular", assertValidSchema("type-extend-circular", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-exclude/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-exclude", assertValidSchema("type-mapped-exclude", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-generic/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-generic", assertValidSchema("type-mapped-generic", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-index-as", assertValidSchema("type-mapped-index-as", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-literal/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-literal", assertValidSchema("type-mapped-literal", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-optional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-optional", assertValidSchema("type-mapped-optional", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-widened/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-widened", assertValidSchema("type-mapped-widened", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/undefined-alias/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "not": {} 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/annotation-deprecated/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @deprecated 3 | * @deprecationMessage Use `NewMyObject` instead. 4 | */ 5 | export interface MyObject { 6 | one?: string; 7 | /** @deprecated */ 8 | two?: number; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/annotation-id/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-id", assertValidSchema("annotation-id", "MyObject", { schemaId: "Test" })); 5 | -------------------------------------------------------------------------------- /test/valid-data/array-function-generics/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-function-generics", assertValidSchema("array-function-generics", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/class-generics/main.ts: -------------------------------------------------------------------------------- 1 | export class Base { 2 | public a: T; 3 | } 4 | 5 | export class MyObject extends Base { 6 | public b: string; 7 | public c: Base; 8 | public d: Base; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/generic-multiargs/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyGeneric { 2 | a: A; 3 | b: B; 4 | } 5 | 6 | export interface MyObject { 7 | value1: MyGeneric; 8 | value2: MyGeneric; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/import-internal/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - import-internal", assertValidSchema("import-internal", "MyObject", { jsDoc: "basic" })); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-extra-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-extra-props", assertValidSchema("interface-extra-props", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots1/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject1 { 2 | propA: MyObject2; 3 | } 4 | 5 | export interface MyObject2 { 6 | propB: string; 7 | } 8 | 9 | export interface MyObject3 { 10 | propC: boolean; 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/structure-extra-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - structure-extra-props", assertValidSchema("structure-extra-props", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-enum", assertValidSchema("type-conditional-enum", "IParameter")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-infer", assertValidSchema("type-conditional-infer", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-omit/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-omit", assertValidSchema("type-conditional-omit", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-circular/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-circular", assertValidSchema("type-indexed-circular", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict/main.ts: -------------------------------------------------------------------------------- 1 | export interface Base { 2 | a: "hello" | "world"; 3 | } 4 | 5 | export interface Base2 { 6 | a: "hello" | "typescript"; 7 | } 8 | 9 | export type MyType = Base & Base2; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-recursive-interface/main.ts: -------------------------------------------------------------------------------- 1 | export interface Container { 2 | children: Container[]; 3 | } 4 | 5 | export type Dummy = { 6 | x: number; 7 | }; 8 | 9 | export type Intersection = Container & Dummy; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-additional-props/main.ts: -------------------------------------------------------------------------------- 1 | export interface Test { 2 | [name: string]: string; 3 | } 4 | 5 | export type WithNumbers = { 6 | [P in keyof T]: T[P] | number; 7 | }; 8 | export type MyObject = WithNumbers; 9 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-null/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-enum-null", assertValidSchema("type-mapped-enum-null", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-named-tuple-member/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-named-tuple-member", assertValidSchema("type-named-tuple-member", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-tuple-nested-rest", assertValidSchema("type-tuple-nested-rest", "MyType")); 5 | -------------------------------------------------------------------------------- /src/Interfaces/AnnotationsReader.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import type { Annotations } from "../Type/AnnotatedType.js"; 3 | 4 | export interface AnnotationsReader { 5 | getAnnotations(node: ts.Node): Annotations | undefined; 6 | } 7 | -------------------------------------------------------------------------------- /test/config/mapped-intersection/main.ts: -------------------------------------------------------------------------------- 1 | interface Base { 2 | foo: string; 3 | bar: null; 4 | } 5 | 6 | type Keep = { [P in Exclude]: B[P] }; 7 | 8 | export type MyObject = Keep & { bar: number }; 9 | -------------------------------------------------------------------------------- /test/invalid-data/script-empty/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertInvalidSchema } from "../../utils"; 3 | 4 | it("invalid-data - script-empty", assertInvalidSchema("script-empty", "MyType", `No root type "MyType" found`)); 5 | -------------------------------------------------------------------------------- /test/valid-data/array-max-items-optional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-max-items-optional", assertValidSchema("array-max-items-optional", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/enums-template-literal/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - enums-template-literal", assertValidSchema("enums-template-literal", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-prefixed-number/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-prefixed-number", assertValidSchema("generic-prefixed-number", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-property-dash/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-property-dash", assertValidSchema("interface-property-dash", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-inline/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literals-inline", assertValidSchema("string-literals-inline", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-anonymous", assertValidSchema("type-aliases-anonymous", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-primitive", assertValidSchema("type-aliases-primitive", "MyString")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-rest/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-tuple-rest", assertValidSchema("type-aliases-tuple-rest", "MyTuple")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "type": "string" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-jsdoc/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-jsdoc", assertValidSchema("type-conditional-jsdoc", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-simple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-simple", assertValidSchema("type-conditional-simple", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-union", assertValidSchema("type-conditional-union", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-number/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-enum-number", assertValidSchema("type-mapped-enum-number", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-union-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-union-union", assertValidSchema("type-mapped-union-union", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-union-union/main.ts: -------------------------------------------------------------------------------- 1 | type MyType1 = "s1"; 2 | type MyType2 = MyType1 | "s2" | "s3"; 3 | type MyType3 = MyType2 | "s4" | "s5"; 4 | type MyType10 = MyType3 | MyType2 | "s6"; 5 | 6 | export type MyType = Record; 7 | -------------------------------------------------------------------------------- /.autorc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["npm", "conventional-commits", "first-time-contributor", "released"], 3 | "baseBranch": "stable", 4 | "prereleaseBranches": ["next"], 5 | "author": "GitHub Actions Bot " 6 | } 7 | -------------------------------------------------------------------------------- /src/SubTypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { BaseType } from "./Type/BaseType.js"; 2 | import type { TypeFormatter } from "./TypeFormatter.js"; 3 | 4 | export interface SubTypeFormatter extends TypeFormatter { 5 | supportsType(type: BaseType): boolean; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/function-function-syntax/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - function-function-syntax", assertValidSchema("function-function-syntax", "myFunction")); 5 | -------------------------------------------------------------------------------- /test/valid-data/namespace-deep-2/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - namespace-deep-2", assertValidSchema("namespace-deep-2", "RootNamespace.SubNamespace.HelperA")); 5 | -------------------------------------------------------------------------------- /test/valid-data/namespace-deep-3/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - namespace-deep-3", assertValidSchema("namespace-deep-3", "RootNamespace.SubNamespace.HelperB")); 5 | -------------------------------------------------------------------------------- /test/valid-data/object-literal-expression/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - object-literal-expression", assertValidSchema("object-literal-expression", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literals-intrinsic/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literals-intrinsic", assertValidSchema("string-literals-intrinsic", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-template-literals/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-template-literals", assertValidSchema("string-template-literals", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyString", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyString": { 6 | "type": "string" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-empty/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-tuple-empty", assertValidSchema("type-aliases-tuple-empty", "MyTuple")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-exclude/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-exclude", assertValidSchema("type-conditional-exclude", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-keyof/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-keyof", assertValidSchema("type-indexed-access-keyof", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-empty-exclude/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-empty-exclude", assertValidSchema("type-mapped-empty-exclude", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-optional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-enum-optional", assertValidSchema("type-mapped-enum-optional", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-readOnly/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-readOnly", assertValidSchema("annotation-readOnly", "MyObject", { jsDoc: "basic" })); 5 | -------------------------------------------------------------------------------- /test/valid-data/annotation-writeOnly/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-writeOnly", assertValidSchema("annotation-writeOnly", "MyObject", { jsDoc: "basic" })); 5 | -------------------------------------------------------------------------------- /test/valid-data/object-function-expression/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - object-function-expression", assertValidSchema("object-function-expression", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/string-literal-property-names/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - string-literal-property-names", assertValidSchema("string-literal-property-names", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-rest/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-infer-rest", assertValidSchema("type-conditional-infer-rest", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-narrowing/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-narrowing", assertValidSchema("type-conditional-narrowing", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-date-annotation/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-date-annotation", assertValidSchema("type-date-annotation", "MyObject", { jsDoc: "basic" })); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-1/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-tuple-1", assertValidSchema("type-indexed-access-tuple-1", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-2/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-tuple-2", assertValidSchema("type-indexed-access-tuple-2", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-circular-access/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-circular-access", assertValidSchema("type-indexed-circular-access", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-conflict/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection-conflict", assertValidSchema("type-intersection-conflict", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-with-arrays/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection-with-arrays", assertValidSchema("type-intersection-with-arrays", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object-function/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-keyof-object-function", assertValidSchema("type-keyof-object-function", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-annotated-string/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-annotated-string", assertValidSchema("type-mapped-annotated-string", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-double-exclude/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-double-exclude", assertValidSchema("type-mapped-double-exclude", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-exported-aliases/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-exported-aliases", assertValidSchema("type-mapped-exported-aliases", "*")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-recursive-deep-exclude/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-recursive-deep-exclude", assertValidSchema("type-recursive-deep-exclude", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-object-property/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-typeof-object-property", assertValidSchema("type-typeof-object-property", "MyType")); 5 | -------------------------------------------------------------------------------- /src/Interfaces/SubTypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { BaseType } from "../Type/BaseType.js"; 2 | import type { TypeFormatter } from "./TypeFormatter.js"; 3 | 4 | export interface SubTypeFormatter extends TypeFormatter { 5 | supportsType(type: BaseType): boolean; 6 | } 7 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items-optional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - array-min-max-items-optional", assertValidSchema("array-min-max-items-optional", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-default-conditional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-default-conditional", assertValidSchema("generic-default-conditional", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/structure-anonymous/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | field: { 3 | subfieldA: number; 4 | subfieldB: string | number; 5 | subfieldC: { 6 | subsubfieldA: number[]; 7 | }; 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/structure-extra-props-symbol/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - structure-extra-props-symbol", assertValidSchema("structure-extra-props-symbol", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-local-namespace/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-local-namespace", assertValidSchema("type-aliases-local-namespace", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-only-rest/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-tuple-only-rest", assertValidSchema("type-aliases-tuple-only-rest", "MyTuple")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-union-namespace/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-union-namespace", assertValidSchema("type-aliases-union-namespace", "MyModel")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-nested/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-infer-nested", assertValidSchema("type-conditional-infer-nested", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-inheritance/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-inheritance", assertValidSchema("type-conditional-inheritance", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-simple/main.ts: -------------------------------------------------------------------------------- 1 | type TypeName = T extends string ? "string" : T extends number ? "number" : "unknown"; 2 | 3 | export type MyObject = { 4 | a: TypeName; 5 | b: TypeName; 6 | c: TypeName; 7 | }; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-object-1/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-object-1", assertValidSchema("type-indexed-access-object-1", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-object-2/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-object-2", assertValidSchema("type-indexed-access-object-2", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection-union-enum", assertValidSchema("type-intersection-union-enum", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-primitive/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "type": "number" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-additional-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-additional-props", assertValidSchema("type-mapped-additional-props", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as-template/main.ts: -------------------------------------------------------------------------------- 1 | interface Message { 2 | id: number; 3 | name: string; 4 | title: string; 5 | } 6 | 7 | export type MyObject = { 8 | [K in keyof Message as `message${Capitalize}`]: Message[K]; 9 | }; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as-with-conditional/main.ts: -------------------------------------------------------------------------------- 1 | interface Message { 2 | id: number; 3 | name: string; 4 | title: string; 5 | } 6 | 7 | export type MyObject = { 8 | [K in keyof Message as Exclude]: Message[K]; 9 | }; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-template-literal/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-template-literal", assertValidSchema("type-mapped-template-literal", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/config/function-parameters-all/main.ts: -------------------------------------------------------------------------------- 1 | export type String = string; 2 | 3 | export const myFunction = ( 4 | /** 5 | * @description Inline parameter description 6 | */ 7 | requiredString: String, 8 | ) => { 9 | return "whatever"; 10 | }; 11 | -------------------------------------------------------------------------------- /test/valid-data/annotation-nullable-definition/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - annotation-nullable-definition", assertValidSchema("annotation-nullable-definition", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-optional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - function-parameters-optional", assertValidSchema("function-parameters-optional", "myFunction")); 5 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-required/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - function-parameters-required", assertValidSchema("function-parameters-required", "myFunction")); 5 | -------------------------------------------------------------------------------- /test/valid-data/generic-indexed-access-constraint/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("generic-indexed-access-constraint", assertValidSchema("generic-indexed-access-constraint", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/interface-extended-extra-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - interface-extended-extra-props", assertValidSchema("interface-extended-extra-props", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/lowercase/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "accent", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/namespace-deep-3/ns-root.ts: -------------------------------------------------------------------------------- 1 | namespace RootNamespace { 2 | export interface Def { 3 | nest: Def; 4 | prev: RootNamespace.Def; 5 | 6 | propA: SubNamespace.HelperA; 7 | propB: SubNamespace.HelperB; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-export/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-recursive-export", assertValidSchema("type-aliases-recursive-export", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-intersection/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-intersection", assertValidSchema("type-conditional-intersection", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-type-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-indexed-access-type-union", assertValidSchema("type-indexed-access-type-union", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-ref/main.ts: -------------------------------------------------------------------------------- 1 | export interface X { 2 | foo: number; 3 | } 4 | 5 | export interface A { 6 | a: X | number; 7 | } 8 | 9 | export interface B { 10 | a: X; 11 | } 12 | 13 | export type MyType = A & B; 14 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as-template/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-index-as-template", assertValidSchema("type-mapped-index-as-template", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-union-intersection/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-mapped-union-intersection", assertValidSchema("type-mapped-union-intersection", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest-uniform/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-tuple-nested-rest-uniform", assertValidSchema("type-tuple-nested-rest-uniform", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-keys/main.ts: -------------------------------------------------------------------------------- 1 | const IDX = { 2 | foo: 1, 3 | bar: 1, 4 | }; 5 | 6 | export const keys = Object.keys as (o: T) => Extract[]; 7 | export const Foo = keys(IDX); 8 | 9 | export type MyType = (typeof Foo)[number]; 10 | -------------------------------------------------------------------------------- /test/invalid-data/duplicate-discriminator/main.ts: -------------------------------------------------------------------------------- 1 | export type A = { 2 | type: "A"; 3 | a: string; 4 | }; 5 | 6 | export type B = { 7 | type: "A"; 8 | b: string; 9 | }; 10 | 11 | /** 12 | * @discriminator type 13 | */ 14 | export type MyType = A | B; 15 | -------------------------------------------------------------------------------- /test/valid-data/class-inheritance/main.ts: -------------------------------------------------------------------------------- 1 | export class Base { 2 | declare public a: number; 3 | declare public b: string | string; 4 | } 5 | 6 | export class MyObject extends Base { 7 | declare public c: boolean; 8 | declare public b: string; 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/const-spread/main.ts: -------------------------------------------------------------------------------- 1 | export const a = { 2 | a: "A", 3 | } as const; 4 | 5 | export const b = { 6 | ...a, 7 | b: "B", 8 | } as const; 9 | 10 | export type A = typeof a; 11 | export type B = typeof b; 12 | 13 | export type MyType = [A, B]; 14 | -------------------------------------------------------------------------------- /test/valid-data/function-function-syntax/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/myFunction", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "myFunction": { 6 | "$comment": "() =>undefined" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/import-internal/main.ts: -------------------------------------------------------------------------------- 1 | import { ExposedSubType, InternalAlias, InternalSubType } from "./module"; 2 | 3 | export interface MyObject { 4 | internalSubType: InternalSubType; 5 | internalAlias: InternalAlias; 6 | exposedSubType: ExposedSubType; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-x/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "myprop", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-mixed/main.ts: -------------------------------------------------------------------------------- 1 | export type MyString = string; 2 | 3 | export interface MySubObject { 4 | propA: number; 5 | propB: number; 6 | } 7 | 8 | export interface MyObject { 9 | primitive: MyString; 10 | object: MySubObject; 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-aliases-recursive-anonymous", assertValidSchema("type-aliases-recursive-anonymous", "MyAlias")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-recursive/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-infer-recursive", assertValidSchema("type-conditional-infer-recursive", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-tuple-xor/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-conditional-infer-tuple-xor", assertValidSchema("type-conditional-infer-tuple-xor", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-extends-never/main.ts: -------------------------------------------------------------------------------- 1 | type State = [TValues] extends [never] 2 | ? { 3 | noValuesHere: true; 4 | } 5 | : { 6 | values: TValues; 7 | }; 8 | 9 | export type MyType = State<"a" | "b"> | State; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-aliased-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection-aliased-union", assertValidSchema("type-intersection-aliased-union", "MyObject")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-union/main.ts: -------------------------------------------------------------------------------- 1 | type Foo = { 2 | foo: "a" | "b"; 3 | }; 4 | 5 | export type A = Foo & { 6 | foo: "a"; 7 | }; 8 | 9 | export type B = Foo & { 10 | foo: "b"; 11 | }; 12 | 13 | export type MyType = A | B; 14 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest-to-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-tuple-nested-rest-to-union", assertValidSchema("type-tuple-nested-rest-to-union", "MyType")); 5 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-function/main.ts: -------------------------------------------------------------------------------- 1 | function checkServerIdentity(hostname: string): Error | undefined { 2 | return undefined; 3 | } 4 | export interface Test { 5 | checkServerIdentity?: typeof checkServerIdentity | undefined; 6 | otherProp: string; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-value/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "foo", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Type/InferType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class InferType extends BaseType { 4 | constructor(private id: string) { 5 | super(); 6 | } 7 | 8 | public getId(): string { 9 | return this.id; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/TypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { Definition } from "./Schema/Definition.js"; 2 | import type { BaseType } from "./Type/BaseType.js"; 3 | 4 | export interface TypeFormatter { 5 | getDefinition(type: BaseType): Definition; 6 | getChildren(type: BaseType): BaseType[]; 7 | } 8 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-declaration/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/myFunction", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "myFunction": { 6 | "$comment": "() =>undefined" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/object-function-expression/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "x", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/structure-private/main.ts: -------------------------------------------------------------------------------- 1 | interface MyPrivate { 2 | subfieldA: number; 3 | subfieldB: string | number; 4 | subfieldC: { 5 | subsubfieldA: number[]; 6 | }; 7 | } 8 | 9 | export interface MyObject { 10 | field: MyPrivate; 11 | } 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: weekly 7 | day: sunday 8 | - package-ecosystem: github-actions 9 | directory: "/" 10 | schedule: 11 | interval: daily 12 | -------------------------------------------------------------------------------- /test/valid-data/keyof-typeof-enum/main.ts: -------------------------------------------------------------------------------- 1 | import { Size } from "./Size"; 2 | 3 | enum Orientation { 4 | Horizontal, 5 | Vertical, 6 | } 7 | 8 | export type MyObject = { 9 | sizeName?: keyof typeof Size; 10 | orientationName?: keyof typeof Orientation; 11 | }; 12 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-object-1/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "foo", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-1/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "foo", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-2/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "bar", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object-function/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "key", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest-to-union/main.ts: -------------------------------------------------------------------------------- 1 | type NestedTuple = [{ a: number }, ...[{ b: string }, { c: number }, ...[{ d: boolean }, ...[]]]]; 2 | 3 | type ToUnion = T extends Array ? A : never; 4 | 5 | export type MyType = ToUnion; 6 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-object-property/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "foo", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/class-new-expression/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "additionalProperties": false, 7 | "type": "object" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-variable-assignment/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/myFunction", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "myFunction": { 6 | "$comment": "() =>undefined" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive-with-id/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "testId", 3 | "$ref": "#/definitions/MyString", 4 | "$schema": "http://json-schema.org/draft-07/schema#", 5 | "definitions": { 6 | "MyString": { 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-class-static-property/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "const": "foo", 7 | "type": "string" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "type": [ 7 | "string", 8 | "number" 9 | ] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Interfaces/TypeFormatter.ts: -------------------------------------------------------------------------------- 1 | import type { Definition } from "../Schema/Definition.js"; 2 | import type { BaseType } from "../Type/BaseType.js"; 3 | 4 | export interface TypeFormatter { 5 | getDefinition(type: BaseType): Definition; 6 | getChildren(type: BaseType): BaseType[]; 7 | } 8 | -------------------------------------------------------------------------------- /src/Type/BaseType.ts: -------------------------------------------------------------------------------- 1 | export abstract class BaseType { 2 | public abstract getId(): string; 3 | 4 | /** 5 | * Get the definition name of the type. Override for non-basic types. 6 | */ 7 | public getName(): string { 8 | return this.getId(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/config/jsdoc-inheritance-exclude/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "description": "Hello World.", 7 | "type": "number" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/config/multiple-types/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - multiple-types", 6 | assertConfigSchema("multiple-types", { 7 | type: ["MyObject1", "MyObject2"], 8 | }), 9 | ); 10 | -------------------------------------------------------------------------------- /test/valid-data/annotation-union-if-then/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - annotation-union-if-then", 6 | assertValidSchema("annotation-union-if-then", "Animal", { jsDoc: "basic" }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/discriminator/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - discriminator", 6 | assertValidSchema("discriminator", "Animal", { jsDoc: "basic", discriminatorType: "open-api" }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots2/schema/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - multiple-roots2/schema", 6 | assertValidSchema("multiple-roots2/schema", undefined, undefined, undefined), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-circular/main.ts: -------------------------------------------------------------------------------- 1 | export interface GeoJsonObject { 2 | type: GeometryCollection["type"]; 3 | } 4 | 5 | export interface GeometryCollection extends GeoJsonObject { 6 | type: "GeometryCollection"; 7 | } 8 | 9 | export type MyType = GeometryCollection; 10 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-enum-null/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": false, 7 | "type": "object" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-never/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": false, 7 | "type": "object" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/unique-symbol/main.ts: -------------------------------------------------------------------------------- 1 | // An explicitly typed unique symbol 2 | const Foo: unique symbol = Symbol("foo"); 3 | // A unique symbol using type inference 4 | const Bar = Symbol("bar"); 5 | 6 | export interface MyObject { 7 | foo: typeof Foo; 8 | bar: typeof Bar; 9 | } 10 | -------------------------------------------------------------------------------- /test/config/function-parameters-all/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - function-parameters-all", 6 | assertConfigSchema("function-parameters-all", { 7 | type: "*", 8 | }), 9 | ); 10 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-declaration/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - function-parameters-declaration", 6 | assertValidSchema("function-parameters-declaration", "myFunction"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-jsdoc/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - function-parameters-jsdoc", 6 | assertValidSchema("function-parameters-jsdoc", "myFunction", { jsDoc: "basic" }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/interface-computed-property-name/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - interface-computed-property-name", 6 | assertValidSchema("interface-computed-property-name", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/re-export-with-asterisk/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - re-export-with-asterisk", 6 | assertValidSchema("re-export-with-asterisk", "*", undefined, { mainTsOnly: true }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-tuple-narrowing/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-conditional-tuple-narrowing", 6 | assertValidSchema("type-conditional-tuple-narrowing", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-indexed-access-tuple-union", 6 | assertValidSchema("type-indexed-access-tuple-union", "FormLayout"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-union-alias/main.ts: -------------------------------------------------------------------------------- 1 | type X = "a" | "b"; 2 | 3 | type Foo = { 4 | foo: X; 5 | }; 6 | 7 | export type A = Foo & { 8 | foo: "a"; 9 | }; 10 | 11 | export type B = Foo & { 12 | foo: "b"; 13 | }; 14 | 15 | export type MyType = A | B; 16 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-primitive/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-union-primitive", 6 | assertValidSchema("type-intersection-union-primitive", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-with-arrays/main.ts: -------------------------------------------------------------------------------- 1 | export type NonEmptyNumberArrayVariationOne = [number, ...number[]] & number[]; 2 | 3 | type NonEmptyGenericArrayVariationOne = [T, ...T[]] & T[]; 4 | 5 | export type NonEmptyNumberArrayVariationTwo = NonEmptyGenericArrayVariationOne; 6 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-empty-exclude/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": false, 7 | "type": "object" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-class-static-property/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-typeof-class-static-property", 6 | assertValidSchema("type-typeof-class-static-property", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/annotation-union-if-then-enum/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - annotation-union-if-then-enum", 6 | assertValidSchema("annotation-union-if-then-enum", "AB", { jsDoc: "basic" }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/enums-number/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/Enum", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "Enum": { 6 | "enum": [ 7 | 1, 8 | 2 9 | ], 10 | "type": "number" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-default-value/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - function-parameters-default-value", 6 | assertValidSchema("function-parameters-default-value", "myFunction"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/namespace-deep-3/ns-sub.ts: -------------------------------------------------------------------------------- 1 | namespace RootNamespace.SubNamespace { 2 | export interface HelperA { 3 | propA: number; 4 | propB: HelperB; 5 | } 6 | export interface HelperB { 7 | propA: SubNamespace.HelperA; 8 | propB: Def; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-empty/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyTuple", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyTuple": { 6 | "maxItems": 0, 7 | "minItems": 0, 8 | "type": "array" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-optional-items/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-aliases-tuple-optional-items", 6 | assertValidSchema("type-aliases-tuple-optional-items", "MyTuple"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-enum/main.ts: -------------------------------------------------------------------------------- 1 | enum ParameterType { 2 | Enum = "enum", 3 | Number = "number", 4 | String = "string", 5 | Date = "date", 6 | } 7 | 8 | export interface IParameter { 9 | type: Exclude; 10 | } 11 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-exclude-narrowing/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-conditional-exclude-narrowing", 6 | assertValidSchema("type-conditional-exclude-narrowing", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-additional-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-additional-props", 6 | assertValidSchema("type-intersection-additional-props", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-partial-conflict", 6 | assertValidSchema("type-intersection-partial-conflict", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-native-single-literal/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-mapped-native-single-literal", 6 | assertValidSchema("type-mapped-native-single-literal", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-pick-union-alias/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-mapped-pick-union-alias", 6 | assertValidSchema("type-mapped-pick-union-alias", "PickAliasedLiteralUnion"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/config/functions-hide/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - functions-hide", 6 | assertConfigSchema("functions-hide", { 7 | type: "MyType", 8 | functions: "hide", 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/valid-data/enums-string/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/Enum", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "Enum": { 6 | "enum": [ 7 | "x", 8 | "y" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/string-template-expression-literals/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - string-template-expression-literals", 6 | assertValidSchema("string-template-expression-literals", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-exclude-complex/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-conditional-exclude-complex", 6 | assertValidSchema("type-conditional-exclude-complex", "BaseAxisNoSignals"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-keyof/main.ts: -------------------------------------------------------------------------------- 1 | interface Types1 { 2 | String: string; 3 | } 4 | 5 | interface Types2 { 6 | String: string; 7 | Number: number; 8 | } 9 | 10 | export interface MyType { 11 | types1: Types1[keyof Types1]; 12 | types2: Types2[keyof Types2]; 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-tuple/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | 0, 8 | 1 9 | ], 10 | "type": "number" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/never-record/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/Mapped", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "Mapped": { 6 | "additionalProperties": { 7 | "not": {} 8 | }, 9 | "type": "object" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-tail-recursion/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-conditional-infer-tail-recursion", 6 | assertValidSchema("type-conditional-infer-tail-recursion", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-ref/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-partial-conflict-ref", 6 | assertValidSchema("type-intersection-partial-conflict-ref", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-index-as-with-conditional/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-mapped-index-as-with-conditional", 6 | assertValidSchema("type-mapped-index-as-with-conditional", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-satisfies/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | "x", 8 | "y" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/config/functions-comment/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - functions-comment", 6 | assertConfigSchema("functions-comment", { 7 | type: "MyType", 8 | functions: "comment", 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/config/mapped-index-any/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - mapped-index-any", 6 | assertConfigSchema("mapped-index-any", { 7 | type: "*", 8 | additionalProperties: true, 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/sourceless-nodes/key/types2.ts: -------------------------------------------------------------------------------- 1 | import { A, B, C } from "./types1"; 2 | 3 | // Uses global scope to test for types without direct import 4 | declare global { 5 | // eslint-disable-next-line @typescript-eslint/no-namespace 6 | namespace Test { 7 | type GlobalType = A | B[] | C; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/export-star-prune-unreachable/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - export-star-prune-unreachable", 6 | assertValidSchema("export-star-prune-unreachable", "*", undefined, { mainTsOnly: true }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/literal-index-type/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | "abc", 8 | "def" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/literal-object-type-with-computed-props/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - literal-object-type-with-computed-props", 6 | assertValidSchema("literal-object-type-with-computed-props", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-generics-export/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-aliases-recursive-generics-export", 6 | assertValidSchema("type-aliases-recursive-generics-export", "MyAlias"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-recursive-interface/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-recursive-interface", 6 | assertValidSchema("type-intersection-recursive-interface", "Intersection"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-keyof-object/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | "foo", 8 | "bar" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/type-typeof-keys/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | "foo", 8 | "bar" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/invalid-data/missing-discriminator/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertInvalidSchema } from "../../utils"; 3 | 4 | it( 5 | "invalid-data - missing-discriminator", 6 | assertInvalidSchema("missing-discriminator", "MyType", 'Cannot find discriminator keyword "type" in type B.'), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/function-parameters-variable-assignment/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - function-parameters-variable-assignment", 6 | assertValidSchema("function-parameters-variable-assignment", "myFunction"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/object-literal-expression/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "enum": [ 7 | "x", 8 | "y" 9 | ], 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-recursive-generics-anonymous/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-aliases-recursive-generics-anonymous", 6 | assertValidSchema("type-aliases-recursive-generics-anonymous", "MyAlias"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-partial-conflict-union", 6 | assertValidSchema("type-intersection-partial-conflict-union", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /src/Utils/hasJsDocTag.ts: -------------------------------------------------------------------------------- 1 | import type ts from "typescript"; 2 | import { symbolAtNode } from "./symbolAtNode.js"; 3 | 4 | export function hasJsDocTag(node: ts.Node, tagName: string): boolean { 5 | const symbol = symbolAtNode(node); 6 | return symbol ? symbol.getJsDocTags()?.some((tag) => tag.name === tagName) : false; 7 | } 8 | -------------------------------------------------------------------------------- /test/invalid-data/duplicate-discriminator/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertInvalidSchema } from "../../utils"; 3 | 4 | it( 5 | "invalid-data - duplicate-discriminator", 6 | assertInvalidSchema("duplicate-discriminator", "MyType", 'Duplicate discriminator values: A in type "(A|B)".'), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/annotation-comment/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @comment Top level comment 3 | */ 4 | export interface MyObject { 5 | /** 6 | * @comment Property comment 7 | */ 8 | nested: MyNestedObject; 9 | } 10 | 11 | /** 12 | * @comment Nested object comment 13 | */ 14 | export interface MyNestedObject {} 15 | -------------------------------------------------------------------------------- /test/valid-data/discriminator/main.ts: -------------------------------------------------------------------------------- 1 | export type Fish = { 2 | animal_type: "fish"; 3 | found_in: "ocean" | "river"; 4 | }; 5 | 6 | export type Bird = { 7 | animal_type: "bird"; 8 | can_fly: boolean; 9 | }; 10 | 11 | /** 12 | * @discriminator animal_type 13 | */ 14 | export type Animal = Bird | Fish; 15 | -------------------------------------------------------------------------------- /test/valid-data/generic-simple/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - generic-simple", assertValidSchema("generic-simple", "MyObject")); 5 | 6 | test("valid-data - generic-simple", assertValidSchema("generic-simple", "*", { expose: "all" })); 7 | -------------------------------------------------------------------------------- /test/valid-data/string-template-expression-literals-import/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - string-template-expression-literals-import", 6 | assertValidSchema("string-template-expression-literals-import", "MyObject"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/symbol-union/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "anyOf": [ 7 | { 8 | "type": "string" 9 | }, 10 | {} 11 | ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-any/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": { 7 | "type": "string" 8 | }, 9 | "type": "object" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 4, 4 | "overrides": [ 5 | { 6 | "files": "*.json", 7 | "options": { 8 | "tabWidth": 2 9 | } 10 | }, 11 | { 12 | "files": "*.yml", 13 | "options": { 14 | "tabWidth": 2 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /test/config/mapped-intersection/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - mapped-intersection", 6 | assertConfigSchema("mapped-intersection", { 7 | type: "MyObject", 8 | additionalProperties: true, 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/config/multiple-types-all/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - multiple-types-all", 6 | assertConfigSchema("multiple-types-all", { 7 | type: ["MyObject1", "MyObject2", "Object1Prop", "Object2Prop"], 8 | }), 9 | ); 10 | -------------------------------------------------------------------------------- /test/config/no-ref-encode/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "$ref": "#/definitions/MyType" 7 | }, 8 | "MyType": { 9 | "type": "number" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/valid-data/annotation-empty/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": false, 7 | "customEmptyAnnotation": true, 8 | "type": "object" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/array-rest-only/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "minItems": 0, 10 | "type": "array" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/enums-compute/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/Enum", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "Enum": { 6 | "enum": [ 7 | 2, 8 | 4, 9 | 6, 10 | 1 11 | ], 12 | "type": "number" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-primitive-with-id/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-aliases-primitive-with-id", 6 | assertValidSchema("type-aliases-primitive-with-id", "MyString", { jsDoc: "none", schemaId: "testId" }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-infer-nested/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "type": [ 7 | "string", 8 | "number", 9 | "boolean" 10 | ] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-symbol/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": { 7 | "type": "string" 8 | }, 9 | "type": "object" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-widened/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": { 7 | "type": "boolean" 8 | }, 9 | "type": "object" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/valid-data/type-maps/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyType {} 2 | 3 | export interface MyMap1 { 4 | [id: string]: MyType; 5 | } 6 | 7 | export interface MyMap2 { 8 | [id: string]: string | number; 9 | } 10 | 11 | export interface MyObject { 12 | map1: MyMap1; 13 | map2: MyMap2; 14 | map3: object; 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/type-recursive-deep-exclude/main.ts: -------------------------------------------------------------------------------- 1 | type DeepExclude = T extends U 2 | ? never 3 | : T extends object 4 | ? { 5 | [K in keyof T]: DeepExclude; 6 | } 7 | : T; 8 | export type MyType = DeepExclude; 9 | -------------------------------------------------------------------------------- /test/config/additional-properties/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - additional-properties", 6 | assertConfigSchema("additional-properties", { 7 | type: "MyObject", 8 | additionalProperties: true, 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/config/arrow-function-parameters/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - arrow-function-parameters", 6 | assertConfigSchema("arrow-function-parameters", { 7 | type: "myFunction", 8 | expose: "all", 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/valid-data/annotation-description-override/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - annotation-description-override", 6 | assertValidSchema("annotation-description-override", "MyObject", { extraTags: ["markdownDescription"] }), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/annotation-union-if-then/main.ts: -------------------------------------------------------------------------------- 1 | export type Fish = { 2 | animal_type: "fish"; 3 | found_in: "ocean" | "river"; 4 | }; 5 | 6 | export type Bird = { 7 | animal_type: "bird"; 8 | can_fly: boolean; 9 | }; 10 | 11 | /** 12 | * @discriminator animal_type 13 | */ 14 | export type Animal = Bird | Fish; 15 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-1/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "minItems": 1, 10 | "type": "array" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/array-min-items-2/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "minItems": 2, 10 | "type": "array" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/multiple-roots1/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - multiple-roots1", assertValidSchema("multiple-roots1", undefined, undefined, undefined)); 5 | 6 | test("valid-data - multiple-roots1", assertValidSchema("multiple-roots1", "*")); 7 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-additional-props/main.ts: -------------------------------------------------------------------------------- 1 | export interface A { 2 | bar: number; 3 | } 4 | 5 | export interface B { 6 | [index: string]: number | string; 7 | } 8 | 9 | export interface C { 10 | [index: string]: A | number; 11 | } 12 | 13 | export interface MyObject { 14 | value: A & B & C; 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-partial-conflict-union-alias/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-partial-conflict-union-alias", 6 | assertValidSchema("type-intersection-partial-conflict-union-alias", "MyType"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-recursive-interface/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test( 5 | "valid-data - type-intersection-union-recursive-interface", 6 | assertValidSchema("type-intersection-union-recursive-interface", "Intersection"), 7 | ); 8 | -------------------------------------------------------------------------------- /test/config/jsdoc-description-only/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "additionalProperties": false, 7 | "description": "Some description here", 8 | "type": "object" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/valid-data/enums-initialized/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/Enum", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "Enum": { 6 | "enum": [ 7 | 10, 8 | 11, 9 | 12, 10 | 1 11 | ], 12 | "type": "number" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-generic/main.ts: -------------------------------------------------------------------------------- 1 | type PropFoo = 123; 2 | type PropBar = "bar"; 3 | 4 | export interface SomeInterface { 5 | foo: PropFoo; 6 | bar: PropBar; 7 | } 8 | export type NullableAndPartial = { 9 | [K in keyof T]?: T[K] | null; 10 | }; 11 | 12 | export type MyObject = NullableAndPartial; 13 | -------------------------------------------------------------------------------- /test/config/mapped-intersection-index/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - mapped-intersection-index", 6 | assertConfigSchema("mapped-intersection-index", { 7 | type: "MyObject", 8 | additionalProperties: true, 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/valid-data/type-aliases-tuple-only-rest/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyTuple", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyTuple": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "minItems": 0, 10 | "type": "array" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union-recursive-interface/main.ts: -------------------------------------------------------------------------------- 1 | export interface Container { 2 | child: Union; 3 | } 4 | 5 | export interface Dummy { 6 | x: number; 7 | } 8 | 9 | export interface Silly { 10 | y: number; 11 | } 12 | 13 | export type Union = Container | Silly; 14 | 15 | export type Intersection = Union & Dummy; 16 | -------------------------------------------------------------------------------- /test/config/jsdoc-hidden-types/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @hidden 3 | */ 4 | export type Hidden = number; 5 | 6 | export type Hidden2 = Hidden; 7 | 8 | export type Visible = number; 9 | 10 | export type MyType = { 11 | /** 12 | * @hidden 13 | */ 14 | hidden: Visible; 15 | hidden2?: Hidden; 16 | visible: Visible | Hidden2; 17 | }; 18 | -------------------------------------------------------------------------------- /test/config/jsdoc-hidden/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-hidden", 6 | assertConfigSchema("jsdoc-hidden", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "extended", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/mapped-intersection-complex/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - mapped-intersection-complex", 6 | assertConfigSchema("mapped-intersection-complex", { 7 | type: "MyObject", 8 | additionalProperties: true, 9 | }), 10 | ); 11 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-exclude/main.ts: -------------------------------------------------------------------------------- 1 | export type Primitives = string | number | boolean; 2 | 3 | export type MyObject = { 4 | primitives: Primitives; 5 | noNumber: Exclude; 6 | noNumberAndBoolean: Exclude; 7 | noStringAndNumber: Exclude, string>; 8 | }; 9 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-exclude/main.ts: -------------------------------------------------------------------------------- 1 | type Test = { 2 | /** 3 | * Foo 4 | */ 5 | foo?: string | number; 6 | /** 7 | * Bar 8 | */ 9 | bar: string | number; 10 | }; 11 | 12 | type WithoutNumbers = { 13 | [P in keyof T]: Exclude; 14 | }; 15 | 16 | export type MyObject = WithoutNumbers; 17 | -------------------------------------------------------------------------------- /test/config/mapped-index-any/main.ts: -------------------------------------------------------------------------------- 1 | interface BaseA { 2 | foo: string; 3 | [key: string]: any; 4 | } 5 | 6 | type Keep = { [K in keyof B]: B[K] }; 7 | 8 | export type MyObjectA = Keep; 9 | 10 | interface BaseB { 11 | foo: string; 12 | [key: string]: unknown; 13 | } 14 | 15 | export type MyObjectB = { [K in keyof BaseB]: any }; 16 | -------------------------------------------------------------------------------- /test/config/mapped-intersection-index/main.ts: -------------------------------------------------------------------------------- 1 | interface Base { 2 | foo: string; 3 | bar: null; 4 | [key: string]: any; 5 | } 6 | 7 | type Keep = { [P in Exclude]: B[P] }; 8 | 9 | type Override>> = Keep & O; 10 | 11 | export type MyObject = Override; 12 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "maxItems": 3, 10 | "minItems": 3, 11 | "type": "array" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-aliased-union/main.ts: -------------------------------------------------------------------------------- 1 | export interface A1 { 2 | a1: number; 3 | } 4 | 5 | export interface A2 { 6 | a2: number; 7 | } 8 | 9 | export type A = A1 | A2; 10 | 11 | export interface B { 12 | b: number; 13 | } 14 | 15 | export interface C { 16 | c: number; 17 | } 18 | 19 | export type MyObject = (A | B) & C; 20 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union/index.test.ts: -------------------------------------------------------------------------------- 1 | import { assertValidSchema } from "../../utils"; 2 | import { test } from "node:test"; 3 | 4 | test("valid-data - type-intersection-union", assertValidSchema("type-intersection-union", "MyObject")); 5 | 6 | test("valid-data - type-intersection-union", assertValidSchema("type-intersection-union", "MyObject")); 7 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection/main.ts: -------------------------------------------------------------------------------- 1 | export interface Type1 { 2 | value1: string; 3 | } 4 | export interface Type2 { 5 | value2: number; 6 | } 7 | 8 | export interface Type3 { 9 | value3: number; 10 | } 11 | 12 | export interface MyObject { 13 | value: Type1 & 14 | Type2 & { 15 | foo: Type3; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /src/Utils/uniqueTypeArray.ts: -------------------------------------------------------------------------------- 1 | import type { BaseType } from "../Type/BaseType.js"; 2 | 3 | export function uniqueTypeArray(types: T[]): T[] { 4 | const uniqueTypes = new Map(); 5 | for (const type of types) { 6 | uniqueTypes.set(type.getId(), type); 7 | } 8 | return Array.from(uniqueTypes.values()); 9 | } 10 | -------------------------------------------------------------------------------- /test/valid-data/array-max-items-optional/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "maxItems": 2, 10 | "minItems": 0, 11 | "type": "array" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/literal-object-type-with-computed-props/main.ts: -------------------------------------------------------------------------------- 1 | import { key as importedKey, Keys } from "./module"; 2 | const key = "localKey"; 3 | 4 | enum LocalKeys { 5 | Key = "localEnumKey", 6 | } 7 | 8 | export type MyType = { 9 | [key]: string; 10 | [LocalKeys.Key]: string; 11 | [importedKey]: string; 12 | [Keys.Key]: string; 13 | }; 14 | -------------------------------------------------------------------------------- /test/valid-data/type-date-annotation/main.ts: -------------------------------------------------------------------------------- 1 | export interface MyObject { 2 | /** 3 | * @examples ["2020-01-01T00:00:00.000Z"] 4 | */ 5 | defaultFormat: Date; 6 | /** 7 | * @format time 8 | * @examples ["12:00:00"] 9 | */ 10 | time: Date; 11 | /** 12 | * @format date 13 | */ 14 | dateOnly: Date; 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/undefined-union/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "anyOf": [ 7 | { 8 | "not": {} 9 | }, 10 | { 11 | "type": "string" 12 | } 13 | ] 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/config/jsdoc-complex-none/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-complex-none", 6 | assertConfigSchema("jsdoc-complex-none", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/jsdoc-inheritance/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-inheritance", 6 | assertConfigSchema("jsdoc-inheritance", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "extended", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/valid-data/array-min-max-items-optional/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "string" 8 | }, 9 | "maxItems": 3, 10 | "minItems": 2, 11 | "type": "array" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/interface-computed-property-name/main.ts: -------------------------------------------------------------------------------- 1 | import { key as importedKey, Keys } from "./module"; 2 | const key = "localKey"; 3 | 4 | enum LocalKeys { 5 | Key = "localEnumKey", 6 | } 7 | 8 | export interface MyObject { 9 | [key]?: string; 10 | [LocalKeys.Key]?: string; 11 | [importedKey]?: string; 12 | [Keys.Key]?: string; 13 | } 14 | -------------------------------------------------------------------------------- /test/valid-data/object-required/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @required ["id", "keys", "definitions"] 3 | */ 4 | export interface MyObject { 5 | id?: string; 6 | keys: string[]; 7 | /** 8 | * every element in `keys` must also be a key in `definitions` 9 | * @required { $data: "1/keys" } 10 | */ 11 | definitions: Record; 12 | } 13 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-array/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyObject", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyObject": { 6 | "items": { 7 | "type": [ 8 | "string", 9 | "number" 10 | ] 11 | }, 12 | "type": "array" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/valid-data/type-tuple-nested-rest-uniform/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "items": { 7 | "type": "number" 8 | }, 9 | "maxItems": 4, 10 | "minItems": 4, 11 | "type": "array" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/config/jsdoc-complex-basic/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-complex-basic", 6 | assertConfigSchema("jsdoc-complex-basic", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "basic", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/jsdoc-hidden-types/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-hidden-types", 6 | assertConfigSchema("jsdoc-hidden-types", { 7 | type: "MyType", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "extended", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/valid-data/type-indexed-access-tuple-union/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/FormLayout", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "FormLayout": { 6 | "enum": [ 7 | "horizontal", 8 | "inline", 9 | "vertical" 10 | ], 11 | "type": "string" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/config/expose-all-topref-true/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - expose-all-topref-true", 6 | assertConfigSchema("expose-all-topref-true", { 7 | type: "MyObject", 8 | expose: "all", 9 | topRef: true, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/valid-data/export-star-prune-unreachable/main.ts: -------------------------------------------------------------------------------- 1 | import type { SomeInterface } from "./dep"; 2 | export { DepType } from "./dep"; 3 | export * from "./dep2"; 4 | 5 | export type MyType = string; 6 | 7 | export interface MyObject extends SomeInterface { 8 | bar?: number; 9 | baz?: Internal; 10 | } 11 | 12 | interface Internal { 13 | nested?: boolean; 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-tuple-narrowing/main.ts: -------------------------------------------------------------------------------- 1 | type SecondElementType = T extends { length: 3 } ? T[1] : unknown; 2 | 3 | export type MyObject = { 4 | string: SecondElementType<[number, string, boolean]>; 5 | booleanOrNumber: SecondElementType<[string, boolean, string] | [number, number, boolean]>; 6 | unknown?: SecondElementType; 7 | }; 8 | -------------------------------------------------------------------------------- /test/valid-data/type-conditional-union/main.ts: -------------------------------------------------------------------------------- 1 | interface A { 2 | a: string; 3 | } 4 | 5 | interface B { 6 | b: string; 7 | } 8 | 9 | interface C { 10 | c: string; 11 | } 12 | 13 | type Map = T extends A | B ? "a or b" : "unknown"; 14 | 15 | export type MyObject = { 16 | a: Map; 17 | b: Map; 18 | c: Map; 19 | d: Map; 20 | }; 21 | -------------------------------------------------------------------------------- /test/valid-data/type-mapped-annotated-string/main.ts: -------------------------------------------------------------------------------- 1 | import { Size } from "./size"; 2 | 3 | /** 4 | * Currency 5 | * @pattern ^[A-Z]{3,3}$ 6 | */ 7 | type CurrencyISO = string; 8 | 9 | /** 10 | * Exchange rate 11 | */ 12 | export type ExchangeRate = Record; 13 | 14 | /** 15 | * Size chart 16 | */ 17 | export type SizeChart = Record; 18 | -------------------------------------------------------------------------------- /test/config/expose-all-topref-false/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - expose-all-topref-false", 6 | assertConfigSchema("expose-all-topref-false", { 7 | type: "MyObject", 8 | expose: "all", 9 | topRef: false, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/expose-none-topref-true/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - expose-none-topref-true", 6 | assertConfigSchema("expose-none-topref-true", { 7 | type: "MyObject", 8 | expose: "none", 9 | topRef: true, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/functions-hide/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/MyType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "MyType": { 6 | "additionalProperties": false, 7 | "properties": { 8 | "bar": { 9 | "type": "number" 10 | } 11 | }, 12 | "type": "object" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/config/jsdoc-description-only/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - jsdoc-description-only", 6 | assertConfigSchema("jsdoc-description-only", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "extended", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/jsdoc-inheritance/main.ts: -------------------------------------------------------------------------------- 1 | export interface Base { 2 | /** 3 | * Base comment. 4 | */ 5 | foo: number; 6 | 7 | /** 8 | * Base comment. 9 | */ 10 | bar: number; 11 | } 12 | 13 | export interface MyObject extends Base { 14 | /** 15 | * Interface comment. 16 | */ 17 | foo: number; 18 | 19 | bar: number; 20 | } 21 | -------------------------------------------------------------------------------- /test/config/no-ref-encode/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - no-ref-encode", 6 | assertConfigSchema("no-ref-encode", { 7 | type: "MyObject", 8 | expose: "all", 9 | encodeRefs: false, 10 | topRef: true, 11 | jsDoc: "none", 12 | }), 13 | ); 14 | -------------------------------------------------------------------------------- /test/sourceless-nodes/key/source.ts: -------------------------------------------------------------------------------- 1 | import { Value } from "./const"; 2 | import { B } from "./types1"; 3 | 4 | export async function withSemiInferredReturnType() { 5 | return { 6 | a: { 7 | b: Value.c.d, 8 | c: Value.c.e, 9 | }, 10 | d: Value.c.i[0]!.j, 11 | e: Value.c.f, 12 | f: Value.b as B[], 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /test/valid-data/type-intersection-union/main.ts: -------------------------------------------------------------------------------- 1 | export interface A { 2 | a: number; 3 | } 4 | 5 | export interface B { 6 | b: number; 7 | } 8 | 9 | export interface C { 10 | c: number; 11 | } 12 | 13 | export interface D { 14 | d: number; 15 | } 16 | 17 | export interface E { 18 | e: number; 19 | } 20 | 21 | export type MyObject = (B | C) & A & (D | E); 22 | -------------------------------------------------------------------------------- /src/Type/ArrayType.ts: -------------------------------------------------------------------------------- 1 | import { BaseType } from "./BaseType.js"; 2 | 3 | export class ArrayType extends BaseType { 4 | public constructor(private item: BaseType) { 5 | super(); 6 | } 7 | 8 | public getId(): string { 9 | return `${this.item.getId()}[]`; 10 | } 11 | 12 | public getItem(): BaseType { 13 | return this.item; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/config/expose-export-topref-true/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - expose-export-topref-true", 6 | assertConfigSchema("expose-export-topref-true", { 7 | type: "MyObject", 8 | expose: "export", 9 | topRef: true, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | -------------------------------------------------------------------------------- /test/config/expose-none-topref-false/index.test.ts: -------------------------------------------------------------------------------- 1 | import { it } from "node:test"; 2 | import { assertConfigSchema } from "../../utils"; 3 | 4 | it( 5 | "config - expose-none-topref-false", 6 | assertConfigSchema("expose-none-topref-false", { 7 | type: "MyObject", 8 | expose: "none", 9 | topRef: false, 10 | jsDoc: "none", 11 | }), 12 | ); 13 | --------------------------------------------------------------------------------