Skip to content

Commit fddbc20

Browse files
committed
readme
1 parent 6d3aa5c commit fddbc20

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

packages/schema-sdk/README.md

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# schema-sdk
22

33
<p align="center" width="100%">
4-
<a href="https://github.com/pyramation/schema-sdk/actions/workflows/run-tests.yaml">
5-
<img height="20" src="https://github.com/pyramation/schema-sdk/actions/workflows/run-tests.yaml/badge.svg" />
4+
<a href="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml">
5+
<img height="20" src="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml/badge.svg" />
66
</a>
7-
<a href="https://github.com/pyramation/schema-sdk/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
7+
<a href="https://github.com/cosmology-tech/schema-typescript/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
88
</p>
99

1010
Welcome to _schema-sdk_! This project provides robust tools for handling OpenAPI schemas and converting them to TypeScript clients with ease and efficiency.
1111

1212
## Features
1313

14+
- **📜 OpenAPI Specification (formerly Swagger)**: Seamlessly integrate with the OpenAPI Spec to generate TypeScript clients. This ensures robust API client generation with comprehensive type safety and support for various API definitions.
15+
1416
- **🔧 JSON Schema to TypeScript**: Convert JSON schemas into TypeScript interfaces automatically.
1517

1618
- **📦 Modular**: Designed to be reusable with minimal dependencies.
1719

18-
- **🔍 Supports `$ref` and `$defs`**: Fully supports JSON Schema references, allowing you to define complex schemas modularly.
19-
20-
- **🐕 Multiple Entities Handling**: Handles arrays of defined types, such as multiple dogs or cats, seamlessly in your schemas.
21-
2220
## Getting Started 🏁
2321

2422
To get started with _schema-sdk_, simply run:
@@ -29,15 +27,69 @@ npm install schema-sdk
2927

3028
## Usage
3129

32-
(see tests)
30+
Below are examples demonstrating how to use schema-sdk for generating TypeScript clients and handling OpenAPI specifications:
31+
32+
### Generating OpenAPI Client
33+
34+
```ts
35+
import schema from 'path-to-your/swagger.json';
36+
import { generateOpenApiClient, getDefaultSchemaTSOptions } from 'schema-sdk';
37+
import { writeFileSync } from 'fs';
38+
39+
const options = getDefaultSchemaTSOptions({
40+
exclude: [
41+
'*.v1beta1.*',
42+
'*.v2beta1.*',
43+
'io.k8s.api.events.v1.EventSeries',
44+
'io.k8s.api.events.v1.Event',
45+
'io.k8s.api.flowcontrol*'
46+
]
47+
});
48+
49+
const code = generateOpenApiClient({
50+
...options,
51+
paths: {
52+
exclude: [
53+
'*flowschema*',
54+
'*v1beta1*',
55+
'*v2beta1*'
56+
],
57+
excludeRequests: [
58+
'head',
59+
'options'
60+
],
61+
excludeTags: [
62+
'storage_v1beta1',
63+
'*v1beta1',
64+
'*v2beta1',
65+
'*v1beta1*',
66+
'*v2beta1*'
67+
]
68+
},
69+
includeTypeComments: true,
70+
includeMethodComments: true,
71+
mergedParams: false,
72+
namingStrategy: {
73+
useLastSegment: true,
74+
renameMap: {
75+
'io.k8s.api.discovery.v1.EndpointPort': 'DiscoveryEndpointPort',
76+
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ServiceReference': 'ApiExtServiceReference',
77+
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.WebhookClientConfig': 'ApiExtWebhookClientConfig',
78+
'io.k8s.api.admissionregistration.v1.ServiceReference': 'AdmissionServiceReference'
79+
}
80+
}
81+
}, schema);
82+
83+
writeFileSync(__dirname + '/output/swagger-client.ts', code);
84+
```
3385

3486
## Contributing 🤝
3587

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

3890
## Need Help?
3991

40-
`schema-sdk` 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-sdk/issues).
92+
`schema-sdk` 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/cosmology-tech/schema-typescript/issues).
4193

4294
## License 📜
4395

packages/schema-sdk/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { getDefaultSchemaTSOptions } from 'schema-typescript';
2+
13
export * from './openapi';
24
export * from './openapi.types';
3-
export * from './utils';
5+
export * from './utils';
6+
7+
export { getDefaultSchemaTSOptions };

packages/schema-typescript/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# schema-typescript
22

33
<p align="center" width="100%">
4-
<a href="https://github.com/pyramation/schema-typescript/actions/workflows/run-tests.yaml">
5-
<img height="20" src="https://github.com/pyramation/schema-typescript/actions/workflows/run-tests.yaml/badge.svg" />
4+
<a href="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml">
5+
<img height="20" src="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml/badge.svg" />
66
</a>
7-
<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>
7+
<a href="https://github.com/cosmology-tech/schema-typescript/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
88
</p>
99

1010
Welcome to _schema-typescript_! This project provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.
@@ -77,7 +77,7 @@ Contributions are what make the open-source community such an amazing place to l
7777

7878
## Need Help?
7979

80-
`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).
80+
`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/cosmology-tech/schema-typescript/issues).
8181

8282
## License 📜
8383

0 commit comments

Comments
 (0)