Open8

JSON SchemaをTypeScriptの型にする

eatski(itski haga)eatski(itski haga)

JSON Schema<>TS について、型を自動生成するアプローチは前からあるけど、そもそもTSは静的な値から型を導出することが可能なので、それを駆使しJSON Schemaから型を導出できないかというチャレンジ

eatski(itski haga)eatski(itski haga)

Enumに対応
https://www.typescriptlang.org/play?#code/PQKhCgAIUhVAXAlgGwM5RMc8CeAHAU0gEEAnUgQxwBUB7WAO0VoYB5jICAPeAhgE1SQASgQr8WyHGUo5WFBjgB8SyAF4SAbQYBXALYAjAqQC64c6AjRIASQZ4d8SNXwEMWXIUgBlAMYALAj0KdUgAeQMAKwJfeD9A4MgAH0gAOX0jUnigkJTveFJEBgBzbMSUmSoyinNPInTDY2rQgG8oSA7SMQkGKUg6gC5IACJdRtJh8ABfWtcfAqLSgJzW9s7uyRx+1yHh1AWS4YAaNc4xgH5IIa7xTch9wpLNMxm6knIq5cSNNo71296W0GIwoHxwx1ONx6fUQvD0qCG1Wmsy8EWisWaP0hG0B20Iu1oURi8Ahf0gULuXQAjjpEF1+NccX0HotnicyRTcXhSLRCKQkAQESIYrRSPxWCySkdqkpkeBLBhIABhFgAN2MqGYDHcKKIAClvGFUtU6C5CKxvJweHxBD4vhRVBpTpbuLwBEIGplmpcxpkrs6rW7bflHksEiFLiHFibaGbBRbVAMA66bUJKjhve9ZDG4wmrpBk9b3eEiRj7ZBLmjiTnXHmhqcGAR1aRzNg5lGSjXCKgLYHU-NQzLQt5NMM+PphiY+8XRACpOnWEUAGbGSAAUVUlzX+clxV1Wc+4dNtZdRdt6aHGgNRq7BAto9hQVQk6Uz1bwGAkAAYjYABoAWTXIZGC1QArBkAOwZAHMGQBEHUAdQZAHQbQBAY0AQwZABkGQAqg0AEQY21RUs4ntY9zVPIMhCrMtw0dSBfj+TQAGlICKdcuF8ZAdH4O8AGsCBwWglx8UduV5YwBWfEwjnTOgQJYe9hmpWl6RfJQTHOIZr2NAjYxPASeT5ETJzokxZSmSAADIqNOOiGIYJiCgoWJWC4ni+JHYZBN0xBBUncSwUkphpJcuS6QIfhFJMVTDXUo9NKI7ShP5DzRIMozzF8Fh9kgHRUCacssQ6YY6mGAk8NJEZAoUoZRwYCg9AILz2lcnThISwrzLJUZqtqoZqLagrdl3SYySmdk-mGZAmwIZAWu6kbepGX1jAGv4htOVyCBJLrTjy2a9gOYoSra8c9BazRNrJEYJD2o5hl8CgSSugw6RC06pwLQbhrygIUH4LoGCm06OmBYZQVkfazsfeENrOqGRm2wl0Tu-6ztkggaSCkKKvamq6uhpG3KazzIZx6HMc61qifJ-LXBanbQ0W8nBsRhmcZmJnIBmYyKCEVKGH2fdYCy0hQjU29WDqXiMoFmVwG59LiloWh+H54wAEZ8yVwXcr+Kqat2Cg9YoUHCHgXYLsmGZpbSpw5YV9WACY1YF1YyW1ghdf10GxvVZAhgAZgABneyBPuQb6+AGE6cemnGXYGIGDcDt7Eaj6GY7j+PEZZv4XhSy3IAMcR1dV4DHc1joP0gF38zTj3xuQfNlb9v25Rlpx88VgX7eL1dS4rjrdn8WhilqwPPYm3Z-cNtbdl8RwzfAIA

eatski(itski haga)eatski(itski haga)

anyOf,constに対応

https://www.typescriptlang.org/play?#code/PQKhCgAIUhVAXAlgGwM5RMc8CeAHAU0gEEAnUgQxwBUB7WAO0VoYB5jICAPeAhgE1SQASgQr8WyHGUo5WFBjgB8SyAF4SAbQYBXALYAjAqQC64cKAjRIASQZ4d8SNXwEMkABbx4eVAC5gYAArVBYAWlQAYw8CPQoAOlpSAHNgfkoAM3hgACYABgBGAE4wvKLg0IYI6NiKMMikgnivPWQAYlIMyPjUAkikFniAFnic+IKMLFxCSABlGrj1SAB5AyC++HmYxYAfSAA5fSNSLdrIPdn4UkQGZNPdknIqe4pzyAAhWlpkMQYXt8OyGQ-z2xEUywyL3M0yIh0Mxn+GgA3lBIGjSGIJAwpJAYX5IAAiXTw0gEt4Em68ZLGAngAC+0NcHy+PwUiMgKLR6MxkhwuNc+IJBhZv1pDOwTMu11u7M5XIx4l5-MIgtQVxu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Ob1vd9n-H0d38-deEA3TeX1vDIv2i39f-65cY7+3gkHR++cuRL1oqyBgpdf6ogZATCgQgComxYGqSAAN+A6AOmca2hJC4EgLPvZuLsCCVj5gLd2D9fYdkQJEH2fc4hfVJBfG219I63xtp7YOnCk670JB-CeFdaH0PntvAhxcaQAMngSJhNJeEx0Noed2n80TgJfjvN+e8iyTx-oSY+lDIAezjr7ORpBpIhz0VfJm0tWYKKsVwkx9iHExwIYIlxQiPExzMRY5xXjNGP0bqnXRXibYFQbnYfgiBbyICwRQXOqjn5-wcckpJIS17qOfgEhuRCdGJJjgY0+3CGGyIoMwixrCXFhxsRHOxT9QkUkMZkjx2SU6WlgV4wBoSi5OPqd01+gT3GhK6Q0nx-DmlVLccE-JP98poOroSK8Xs8D7g6R41JeiNn-zvmYdO5g4GIOQfM18sALa1RFtrGSMJfpmwthOXaAAFTsWD+jnPqmjVg1y-qYOwedby4BTbJC+PwU5xgChyVBaQJYidimCgoPCigq9PAB1CN7fEGR4m9EnoQeAgoe5rgBfMyAQLaAgotjkCFZy8FolhSGBFSLgGBzRbiUgOgCCT2zgQZA+IADMeRJ7T2QLPBgfgO53wmTSuOfg9yIvSZAEZLcJWQFhTK2Vh9UlmHFIC4FTzSW-PBfiXVLynDUuVVK1uBBLVIpEXmSABQ8gOsnmYvxsTpUFByDyoYSK7QqstVauVYyVQEiWXoFZigkUIPkoSx0TgSX8CNb8ilhrnm-OhZZc1-k-WIGtdceh+J7VOrKcYPxga8wEkidE2JOh4neq5LSv2tAPC0GpB0hBnVgCQAAALwFQGEbghB+h9vIEkaN6CDDiEhQauAVK+ldWKXJVVDKUWgPxFcNlHLrJcrkvavIyZR1OHHWS4wSbp1EVNfWptLbJ5dW7b2-tGwh2dlsnaTl3LCR8qRTentfauADvgI+kddocWCkiI4NcQA

eatski(itski haga)eatski(itski haga)

$refに対応

https://www.typescriptlang.org/play?#code/PQKhCgAIUhVAXAlgGwM5RMc8CeAHAU0gEEAnUgQxwBUB7WAO0VoYB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