Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed May 25, 2024
1 parent 6d3aa5c commit fddbc20
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
70 changes: 61 additions & 9 deletions packages/schema-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# schema-sdk

<p align="center" width="100%">
<a href="https://github.com/pyramation/schema-sdk/actions/workflows/run-tests.yaml">
<img height="20" src="https://github.com/pyramation/schema-sdk/actions/workflows/run-tests.yaml/badge.svg" />
<a href="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml">
<img height="20" src="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml/badge.svg" />
</a>
<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>
<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>
</p>

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

## Features

- **📜 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.

- **🔧 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-sdk_, simply run:
Expand All @@ -29,15 +27,69 @@ npm install schema-sdk

## Usage

(see tests)
Below are examples demonstrating how to use schema-sdk for generating TypeScript clients and handling OpenAPI specifications:

### Generating OpenAPI Client

```ts
import schema from 'path-to-your/swagger.json';
import { generateOpenApiClient, getDefaultSchemaTSOptions } from 'schema-sdk';
import { writeFileSync } from 'fs';

const options = getDefaultSchemaTSOptions({
exclude: [
'*.v1beta1.*',
'*.v2beta1.*',
'io.k8s.api.events.v1.EventSeries',
'io.k8s.api.events.v1.Event',
'io.k8s.api.flowcontrol*'
]
});

const code = generateOpenApiClient({
...options,
paths: {
exclude: [
'*flowschema*',
'*v1beta1*',
'*v2beta1*'
],
excludeRequests: [
'head',
'options'
],
excludeTags: [
'storage_v1beta1',
'*v1beta1',
'*v2beta1',
'*v1beta1*',
'*v2beta1*'
]
},
includeTypeComments: true,
includeMethodComments: true,
mergedParams: false,
namingStrategy: {
useLastSegment: true,
renameMap: {
'io.k8s.api.discovery.v1.EndpointPort': 'DiscoveryEndpointPort',
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ServiceReference': 'ApiExtServiceReference',
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.WebhookClientConfig': 'ApiExtWebhookClientConfig',
'io.k8s.api.admissionregistration.v1.ServiceReference': 'AdmissionServiceReference'
}
}
}, schema);

writeFileSync(__dirname + '/output/swagger-client.ts', code);
```

## 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-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).
`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).

## License 📜

Expand Down
6 changes: 5 additions & 1 deletion packages/schema-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { getDefaultSchemaTSOptions } from 'schema-typescript';

export * from './openapi';
export * from './openapi.types';
export * from './utils';
export * from './utils';

export { getDefaultSchemaTSOptions };
8 changes: 4 additions & 4 deletions packages/schema-typescript/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 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 href="https://github.com/cosmology-tech/schema-typescript/actions/workflows/run-tests.yaml">
<img height="20" src="https://github.com/cosmology-tech/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>
<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>
</p>

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

## 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).
`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).

## License 📜

Expand Down

0 comments on commit fddbc20

Please sign in to comment.