https://github.com/json-schema-tools/transpiler
  
  
    Transpile JSON Schema to Type aliases for many languages 
    https://github.com/json-schema-tools/transpiler
  
json-schema-generator jsonschema open-api open-rpc typings
        Last synced: 7 months ago 
        JSON representation
    
Transpile JSON Schema to Type aliases for many languages
- Host: GitHub
 - URL: https://github.com/json-schema-tools/transpiler
 - Owner: json-schema-tools
 - License: apache-2.0
 - Created: 2020-01-28T02:17:08.000Z (almost 6 years ago)
 - Default Branch: master
 - Last Pushed: 2024-05-28T06:46:17.000Z (over 1 year ago)
 - Last Synced: 2024-05-28T16:32:54.138Z (over 1 year ago)
 - Topics: json-schema-generator, jsonschema, open-api, open-rpc, typings
 - Language: TypeScript
 - Homepage: https://json-schema-tools.github.io/transpiler/
 - Size: 1.4 MB
 - Stars: 19
 - Watchers: 2
 - Forks: 7
 - Open Issues: 16
 - 
            Metadata Files:
            
- Readme: README.md
 - Changelog: CHANGELOG.md
 - Contributing: CONTRIBUTING.md
 - Funding: .github/FUNDING.yml
 - License: LICENSE.md
 
 
Awesome Lists containing this project
- jimsghstars - json-schema-tools/transpiler - Transpile JSON Schema to Type aliases for many languages (TypeScript)
 
README
          # JSON Schema Transpiler
  
    
    
    
    
    
  
Turn your JSON Schemas into types to be used in various languages.
[Try Me](https://json-schema.tools/)
- Generate types for:
  - Golang
  - Typescript
  - Rust
  - Python
- handles cycle detection
- automatically determines references
- includes documentation annotations for easy documentation generation with native language tools.
- minimal dependencies (wip)
- Creates 1 type alias per 1 schema
- Autogenerated deterministic titles where missing
- Autoreferencer (removes duplication)
- Code is synchronous - no IO keeps it lean and fast
- [Convert schema to types in browser too!](https://json-schema.tools)
## Getting Started
`npm install @json-schema-tools/transpiler`
```typescript
const JsonSchemaTranspiler = require("@json-schema-tools/transpiler").default;
const mySchema = {
  "title": "PlowAnimals",
  "description": "an array of animals that are good at pulling things",
  "type": "array",
  "items": {
    "oneOf": [
      { "title": "Horse" },
      { "title": "Donkey" },
      { "title": "Elephant" },
    ]
  }
};
const transpiler = new JsonSchemaTranspiler(mySchema);
console.log(transpiler.toTypescript());
console.log(transpiler.toRust());
console.log(transpiler.to("go")); // same thing, different form/interface
console.log(transpiler.to("python")); // works with shorthand of the language aswell (py or python)
```
## Testing
### Generate a test case
`npm run generateTest`
outputs:
```
> @json-schema-tools/transpiler@0.0.0-development generateTest /Users/zb/Code/json-schema-tools/transpiler
> tsc && node ./build/integration-tests/generator.js
? What is the name of the test schema? type-as-array
? Enter a url to a JSON Schema, or press enter to get an empty one? false
Detecting languages...
Found 4 languages: go, py, rs, ts
Writing files...
All done
```
Edit schema if necessary, and run `npm test`. Update expected results as needed.
### Contributing
How to contribute, build and release are outlined in [CONTRIBUTING.md](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification.