{"id":13799889,"url":"https://github.com/vojtechhabarta/typescript-generator","last_synced_at":"2025-05-14T20:03:13.241Z","repository":{"id":22779818,"uuid":"26125896","full_name":"vojtechhabarta/typescript-generator","owner":"vojtechhabarta","description":"Generates TypeScript from Java - JSON declarations, REST service client","archived":false,"fork":false,"pushed_at":"2024-06-26T12:17:49.000Z","size":14456,"stargazers_count":1176,"open_issues_count":123,"forks_count":243,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-04-11T06:18:50.572Z","etag":null,"topics":["gradle-plugin","jackson","java","jax-rs","json","maven-plugin","typescript","typescript-generator"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vojtechhabarta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-03T15:49:48.000Z","updated_at":"2025-04-10T09:43:19.000Z","dependencies_parsed_at":"2024-01-13T10:42:13.205Z","dependency_job_id":"e8dadf66-b51b-4e65-815a-b391bce45a2e","html_url":"https://github.com/vojtechhabarta/typescript-generator","commit_stats":null,"previous_names":[],"tags_count":129,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechhabarta%2Ftypescript-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechhabarta%2Ftypescript-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechhabarta%2Ftypescript-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojtechhabarta%2Ftypescript-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vojtechhabarta","download_url":"https://codeload.github.com/vojtechhabarta/typescript-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351633,"owners_count":21089317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle-plugin","jackson","java","jax-rs","json","maven-plugin","typescript","typescript-generator"],"created_at":"2024-08-04T00:01:06.980Z","updated_at":"2025-04-11T06:18:54.515Z","avatar_url":"https://github.com/vojtechhabarta.png","language":"Java","readme":"[![Maven Central](https://img.shields.io/maven-central/v/cz.habarta.typescript-generator/typescript-generator-core.svg)](https://repo1.maven.org/maven2/cz/habarta/typescript-generator/typescript-generator-core/)\n[![Appveyor](https://img.shields.io/appveyor/ci/vojtechhabarta/typescript-generator/main.svg)](https://ci.appveyor.com/project/vojtechhabarta/typescript-generator)\n[![Stars](https://img.shields.io/github/stars/vojtechhabarta/typescript-generator.svg?style=social)](https://github.com/vojtechhabarta/typescript-generator)\n\nQuick links:\n[Configuration parameters](https://www.habarta.cz/typescript-generator/maven/typescript-generator-maven-plugin/generate-mojo.html)\n|\n[Breaking changes](https://github.com/vojtechhabarta/typescript-generator/wiki/Breaking-Changes)\n|\n[Release notes](https://github.com/vojtechhabarta/typescript-generator/releases)\n|\n[Playground _(beta)_](https://jechlin.github.io/ts-gen-aws/)\n\ntypescript-generator\n====================\ntypescript-generator is a tool for generating TypeScript definition files (.d.ts) from Java JSON classes.\nIf you have REST service written in Java (or another JVM language) using object to JSON mapping you can use typescript-generator to generate TypeScript interfaces from Java classes.\n\nFor example for this Java class:\n\n``` java\npublic class Person {\n    public String name;\n    public int age;\n    public boolean hasChildren;\n    public List\u003cString\u003e tags;\n    public Map\u003cString, String\u003e emails;\n}\n```\n\ntypescript-generator outputs this TypeScript interface:\n``` typescript\ninterface Person {\n    name: string;\n    age: number;\n    hasChildren: boolean;\n    tags: string[];\n    emails: { [index: string]: string };\n}\n```\n\nSupported types include:\n- all Java primitive types with their corresponding wrappers (for example `int` and `Integer`, `boolean` and `Boolean`, etc.)\n- `String`\n- `Date`\n- enum\n- array\n- `List` and `Map` (including derived interfaces and implementation classes)\n- customized type mapping\n\nFor more details see [Type Mapping Wiki page](../../wiki/Type-Mapping).\n\n\u003e Note: typescript-generator works with compiled classes using Java reflection. It doesn't use source files (except for Javadoc feature).\nIn Maven plugin this means either classes compiled from source files in the same module or classes added using `\u003cdependency\u003e` element.\n\nMaven\n-----\n\nIn Maven build you can use `typescript-generator-maven-plugin` like this:\n``` xml\n\u003cplugin\u003e\n    \u003cgroupId\u003ecz.habarta.typescript-generator\u003c/groupId\u003e\n    \u003cartifactId\u003etypescript-generator-maven-plugin\u003c/artifactId\u003e\n    \u003cversion\u003ex.y.z\u003c/version\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cid\u003egenerate\u003c/id\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003egenerate\u003c/goal\u003e\n            \u003c/goals\u003e\n            \u003cphase\u003eprocess-classes\u003c/phase\u003e\n        \u003c/execution\u003e\n    \u003c/executions\u003e\n    \u003cconfiguration\u003e\n        \u003cjsonLibrary\u003ejackson2\u003c/jsonLibrary\u003e\n        \u003cclasses\u003e\n            \u003cclass\u003ecz.habarta.typescript.generator.Person\u003c/class\u003e\n        \u003c/classes\u003e\n        \u003coutputKind\u003emodule\u003c/outputKind\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\nMore complete sample can be found [here](sample-maven).\nDetailed description how to configure typescript-generator-maven-plugin is on generated [site](http://vojtechhabarta.github.io/typescript-generator/maven/typescript-generator-maven-plugin/generate-mojo.html).\n\n\nGradle\n------\n\nIn Gradle build you can use `cz.habarta.typescript-generator` plugin like this:\n```groovy\nplugins {\n    id 'cz.habarta.typescript-generator' version 'x.y.z'\n}\n\ngenerateTypeScript {\n    jsonLibrary = 'jackson2'\n    classes = [\n        'cz.habarta.typescript.generator.sample.Person'\n    ]\n    outputKind = 'module'\n}\n```\n\nFor the Kotlin Gradle DSL you can alternatively use the `cz.habarta.typescript-generator` plugin like this:\n\n#### build.gradle.kts\n```kotlin\nimport cz.habarta.typescript.generator.JsonLibrary\nimport cz.habarta.typescript.generator.TypeScriptFileType\nimport cz.habarta.typescript.generator.TypeScriptOutputKind\n\nplugins {\n    id(\"cz.habarta.typescript-generator\") version \"x.y.z\"\n}\n\ntasks {\n    generateTypeScript {\n        jsonLibrary = JsonLibrary.jackson2\n        outputKind = TypeScriptOutputKind.module\n        outputFileType = TypeScriptFileType.implementationFile\n        ...\n    }\n}\n```\n\nYou can run typescript-generator on demand using `gradle generateTypeScript` command\nor you can invoke it as part of another task by adding dependency from that task to `generateTypeScript` task in Gradle build file.\n\nMore complete sample can be found [here](sample-gradle).\nGradle plugin has the same features as Maven plugin, for detailed description see Maven generated [site](http://vojtechhabarta.github.io/typescript-generator/maven/typescript-generator-maven-plugin/generate-mojo.html). \n\n\nDirect invocation\n-----------------\nIf you do not use Maven or Gradle you can invoke typescript-generator directly using `TypeScriptGenerator.generateTypeScript()` method.\n\n\nInput classes\n-------------\nInput classes can be specified using several parameters:\n- **`classes`** - list of fully qualified class names, includes all listed classes and their dependencies, `$` character is used for nested classes like `com.example.ClassName$NestedClassName`\n- **`classPatterns`** - list of glob patterns like `com.example.*Json`, includes all classes matched by the pattern, supported are `*` and `**` wildcards\n- **`classesFromJaxrsApplication`** - fully qualified name of JAX-RS application class, all classes used by application resources will be included, recommended if you have JAX-RS application class\n- **`classesFromAutomaticJaxrsApplication`** - value `true` will include classes from automatically discovered REST resources, recommended if you have JAX-RS application without `Application` subclass\n- **`excludeClasses`** - list of fully qualified class names, excluded classes will be mapped to TypeScript `any` type, if excluded class is a resource then this resource will not be scanned for used classes\n\n\u003e Note: it is possible to use multiple parameters at the same time.\n\nFor more details see [Class Names Glob Patterns](../../wiki/Class-Names-Glob-Patterns) and [JAX RS Application](../../wiki/JAX-RS-Application) Wiki pages.\n\n\nOutput parameters\n-----------------\nOutput is configured using several parameters:\n- `outputKind` (required parameter) - determines if and how module will be generated\n    - values are: `global`, `module`, `ambientModule`\n- `outputFileType` - specifies TypeScript file type\n    - values are: `declarationFile` (.d.ts) or `implementationFile` (.ts)\n- `outputFile` - specifies path and name of output file\n\nFor more details see [Modules and Namespaces](http://vojtechhabarta.github.io/typescript-generator/doc/ModulesAndNamespaces.html) page.\n\n\nREST frameworks\n---------------\nTypescript-generator can generate not only TypeScript declarations for JSON Java classes but it can also generate client classes for REST services. Supported REST frameworks are JAX-RS and Spring. Client for JAX-RS service can be generated using `generateJaxrsApplicationClient` parameter, client for Spring service can be generated using `generateSpringApplicationClient`. Since Spring support is in separate module it is needed to add this module to typescript-generator dependencies. Here is example for Maven:\n``` xml\n\u003cplugin\u003e\n    \u003cgroupId\u003ecz.habarta.typescript-generator\u003c/groupId\u003e\n    \u003cartifactId\u003etypescript-generator-maven-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e${typescript-generator.version}\u003c/version\u003e\n    \u003cconfiguration\u003e\n        \u003cgenerateSpringApplicationClient\u003etrue\u003c/generateSpringApplicationClient\u003e\n        ...\n    \u003c/configuration\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecz.habarta.typescript-generator\u003c/groupId\u003e\n            \u003cartifactId\u003etypescript-generator-spring\u003c/artifactId\u003e\n            \u003cversion\u003e${typescript-generator.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/plugin\u003e\n```\n\n\nDownload\n--------\nReleases are available from Maven Central Repository.\n[Search](http://search.maven.org/#search%7Cga%7C1%7Ccz.habarta.typescript-generator) for dependency information for your build tool\nor download [typescript-generator-core](https://repo1.maven.org/maven2/cz/habarta/typescript-generator/typescript-generator-core) directly.\n\n\nWiki\n----\nFor more detailed description of some topics see [Wiki pages](../../wiki).\n\n\nArchitecture\n------------\n\n`TypeScriptGenerator` has 3 main parts (`ModelParser`, `ModelCompiler` and `Emitter`) which work together to produce TypeScript declarations for specified Java classes.\n\n```\n           (Model)            (TsModel)\nModelParser  ==\u003e  ModelCompiler  ==\u003e  Emitter\n         |         |\n         V         V\n        TypeProcessor\n```\n\n- `ModelParser` reads Java JSON classes and their properties using Java reflections and creates `Model`.\n  It uses `TypeProcessor`s for finding used classes.\n  For example if property type is `List\u003cPerson\u003e` it discovers that `Person` class should be also parsed.\n  `ModelParser`s are specific for each JSON library (for example `Jackson2Parser`).\n- `ModelCompiler` transforms Java model to TypeScript model (`Model` class to `TsModel` class).\n  It uses `TypeProcessor`s for mapping Java types to TypeScript types (for example for `int` returns `number`).\n- `Emitter` takes `TsModel` and produces TypeScript declaration file.\n\n\nLinks\n-----\n\n- http://www.rainerhahnekamp.com/type-safe-endpoints-with-typescript-and-java - blog post about using typescript-generator not only with Spring MVC\n- http://www.jsweet.org/10-reasons-to-use-jsweet - blog post about JSweet transpiler mentions typescript-generator\n- https://github.com/raphaeljolivet/java2typescript - tool similar to typescript-generator\n\n\nContributing\n------------\n\n- current major version supports Java 8 and later (version 1 supported Java 7 and 8)\n- keep pull requests small and focused ([10 tips for better Pull Requests](http://blog.ploeh.dk/2015/01/15/10-tips-for-better-pull-requests/))\n- do not add dependencies unless previously discussed in issue\n\n### Code formatting\n\n- use 4 spaces for indentation in Java files\n- sort java imports alphabetically (including static imports), do not use wildcard (star) imports\n- please do not reformat whole files in IDE (prevent accidental changes to unrelated lines)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojtechhabarta%2Ftypescript-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvojtechhabarta%2Ftypescript-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojtechhabarta%2Ftypescript-generator/lists"}