Skip to content

Commit

Permalink
new workspace πŸš€
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed May 5, 2024
1 parent d8876c2 commit 68c127a
Show file tree
Hide file tree
Showing 68 changed files with 5,531 additions and 246 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
yarn
yarn build
- name: Test
- name: Test Schema TypeScript
run: |
yarn test
cd ./packages/schema-typescript && yarn test
- name: Test OpenAPI Spec
run: |
cd ./packages/open-api && yarn test
24 changes: 24 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"lerna": "6",
"conventionalCommits": true,
"npmClient": "yarn",
"npmClientArgs": [
"--no-lockfile"
],
"packages": [
"packages/*"
],
"version": "independent",
"registry": "https://registry.npmjs.org",
"command": {
"create": {
"homepage": "https://github.com/pyramation/schema-typescript-workspace",
"license": "SEE LICENSE IN LICENSE",
"access": "restricted"
},
"publish": {
"allowBranch": "main",
"message": "chore(release): publish"
}
}
}
49 changes: 19 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
{
"name": "schema-typescript",
"version": "0.5.0",
"description": "Convert JSON Schema to TypeScript Definitions",
"name": "schema-typescript-workspace",
"version": "0.0.1",
"author": "Dan Lynch <pyramation@gmail.com>",
"homepage": "https://github.com/pyramation/schema-typescript#readme",
"license": "SEE LICENSE IN LICENSE",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/pyramation/schema-typescript"
"url": "https://github.com/pyramation/schema-typescript-workspace"
},
"bugs": {
"url": "https://github.com/pyramation/schema-typescript/issues"
"license": "SEE LICENSE IN LICENSE",
"publishConfig": {
"access": "restricted"
},
"workspaces": [
"packages/*"
],
"scripts": {
"copy": "copyfiles -f LICENSE README.md package.json dist",
"clean": "del dist/**",
"prepare": "npm run build",
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"test": "jest",
"test:watch": "jest --watch"
"clean": "lerna run clean",
"build": "lerna run build --stream",
"symlink": "symlink-workspace --logLevel error",
"postinstall": "yarn symlink"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"copyfiles": "^2.4.1",
Expand All @@ -38,17 +32,12 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"jest": "^29.6.2",
"lerna": "^6",
"prettier": "^3.0.2",
"strip-ansi": "^6",
"symlink-workspace": "^1.9.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
},
"keywords": [],
"dependencies": {
"@babel/core": "^7.24.4",
"@babel/generator": "^7.24.4",
"@babel/types": "^7.24.0",
"deepmerge": "^4.3.1",
"minimatch": "^9.0.4"
}
}
}
51 changes: 51 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# @schema-typescript/cli

<p align="center">
<img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"><br />
schema-typescript CLI
</p>

## install

```sh
npm install @schema-typescript/cli
```
## Table of contents

- [@schema-typescript/cli](#@schema-typescript/cli)
- [Install](#install)
- [Table of contents](#table-of-contents)
- [Developing](#developing)
- [Credits](#credits)

## Developing

When first cloning the repo:

```
yarn
yarn build
```

## Related

Checkout these related projects:

* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules.
* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes.
* [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application.
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command.
* [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.
* [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain.

## Credits

πŸ›  Built by Cosmology β€”Β if you like our tools, please consider delegating to [our validator βš›οΈ](https://cosmology.zone/validator)


## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED β€œAS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
18 changes: 18 additions & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
babelConfig: false,
tsconfig: "tsconfig.json",
},
],
},
transformIgnorePatterns: [`/node_modules/*`],
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["dist/*"]
};
31 changes: 31 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@schema-typescript/cli",
"version": "0.0.1",
"author": "Dan Lynch <pyramation@gmail.com>",
"description": "schema-typescript CLI",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/pyramation/schema-typescript",
"license": "SEE LICENSE IN LICENSE",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/pyramation/schema-typescript"
},
"bugs": {
"url": "https://github.com/pyramation/schema-typescript/issues"
},
"scripts": {
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
"clean": "del dist/**",
"prepare": "npm run build",
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"test": "jest",
"test:watch": "jest --watch"
},
"keywords": []
}
3 changes: 3 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {

};
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src/"
},
"include": ["src/**/*.ts"],
"exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*"]
}
84 changes: 84 additions & 0 deletions packages/open-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# schema-typescript

<p align="center" width="100%">
<a href="https://github.com/pyramation/schema-typescript/actions/workflows/run-tests.yaml">
<img height="20" src="https://github.com/pyramation/schema-typescript/actions/workflows/run-tests.yaml/badge.svg" />
</a>
<a href="https://github.com/pyramation/schema-typescript/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
</p>

Welcome to _schema-typescript_! This project provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.

## Features

- **πŸ”§ JSON Schema to TypeScript**: Convert JSON schemas into TypeScript interfaces automatically.

- **πŸ“¦ Modular**: Designed to be reusable with minimal dependencies.

- **πŸ” Supports `$ref` and `$defs`**: Fully supports JSON Schema references, allowing you to define complex schemas modularly.

- **πŸ• Multiple Entities Handling**: Handles arrays of defined types, such as multiple dogs or cats, seamlessly in your schemas.

## Getting Started 🏁

To get started with _schema-typescript_, simply run:

```bash
npm install schema-typescript
```

## Usage πŸ“˜

Here's a quick example to show you how to convert a JSON schema into TypeScript interfaces:

```javascript
import { generateTypeScript } from 'schema-typescript';

const schema = {
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"firstName": { "type": "string" },
"pets": {
"type": "array",
"items": { "$ref": "#/$defs/pet" }
}
},
"required": ["firstName", "pets"],
"$defs": {
"pet": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" }
},
"required": ["name", "type"]
}
}
};

console.log(generateTypeScript(schema));
// OUTPUT:
interface Pet {
name: string;
type: string;
}
interface Person {
firstName: string;
pets: Pet[];
}
```

## Contributing 🀝

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

## Need Help?

`schema-typescript` might not work perfectly for all JSON schemas yet. We value your feedback and contributions to make it better. If you encounter any issues or have suggestions for improvements, please [let us know](https://github.com/pyramation/schema-typescript/issues).

## License πŸ“œ

Distributed under the MIT License. See \`LICENSE\` for more information.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from 'fs';

import schema from '../__fixtures__/openapi/swagger.json';
import schema from '../../../__fixtures__/openapi/swagger.json';
import { getDefaultSchemaTSOptions } from '../src';
import { generateOpenApiClient } from '../src/openapi';

Expand Down Expand Up @@ -52,7 +52,7 @@ it('swagger', () => {
}
}, schema as any);
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger-client.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger-client.ts', code);
});

it('merged', () => {
Expand All @@ -71,10 +71,10 @@ it('merged', () => {
mergedParams: true
}, schema as any);
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger-client.merged.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger-client.merged.ts', code);
});

it('openapi', () => {
const data = Object.keys(schema.definitions)
writeFileSync(__dirname + '/../__fixtures__/output/swagger-definitions.json', JSON.stringify(data, null, 2));
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger-definitions.json', JSON.stringify(data, null, 2));
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from 'fs';

import schema from '../__fixtures__/openapi/swagger.json';
import schema from '../../../__fixtures__/openapi/swagger.json';
import { generateTypeScript } from '../src';

const myschema = {
Expand Down Expand Up @@ -111,7 +111,7 @@ it('useLastSegment false', () => {
}
});
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger.overrides.all.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger.overrides.all.ts', code);
});

it('useLastSegment true', () => {
Expand All @@ -123,5 +123,5 @@ it('useLastSegment true', () => {
}
});
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger.overrides.last.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger.overrides.last.ts', code);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from 'fs';

import schema from '../__fixtures__/openapi/swagger.json';
import schema from '../../../__fixtures__/openapi/swagger.json';
import { generateTypeScript } from '../src';

const myschema = {
Expand All @@ -13,7 +13,7 @@ it('swagger', () => {

});
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger.ts', code);
});

it('naming', () => {
Expand All @@ -35,5 +35,5 @@ it('naming', () => {
}
});
expect(code).toMatchSnapshot();
writeFileSync(__dirname + '/../__fixtures__/output/swagger.includes.ts', code);
writeFileSync(__dirname + '/../../../__fixtures__/output/swagger.includes.ts', code);
});
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 68c127a

Please sign in to comment.