generated from toomuchdesign/npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial implementation * chore: run CI on Node.js v18 and v20 * refactor: remove empty schema def check * Update package.json * Update README.md * chore: remove unused @types/node dependency * chore: update changeset * chore: setup changeset release action
- Loading branch information
1 parent
309dd0b
commit 6454f47
Showing
31 changed files
with
3,374 additions
and
3,936 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openapi-ts-json-schema': patch | ||
--- | ||
|
||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.github/workflows/auto-merge.yml → .github/workflows/dependebot-auto-merge.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: auto-merge | ||
name: dependabot-auto-merge | ||
|
||
on: | ||
pull_request: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
|
||
- run: npm ci | ||
|
||
- name: Create Release Pull Request | ||
uses: changesets/action@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20 | ||
18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
# Project name | ||
# openapi-ts-json-schema | ||
|
||
## Setup after fork | ||
Generate JSON schemas TypeScript files (`.ts`) from OpenAPI definitions which can be natively used to infer types from (with [`json-schema-to-ts`](https://github.com/ThomasAribart/json-schema-to-ts) or [`fastify-type-provider-json-schema-to-ts`](https://github.com/fastify/fastify-type-provider-json-schema-to-ts)). | ||
|
||
- Fill `package.json` file with relevant fields | ||
- Enable [Changesets bot](https://github.com/changesets/bot) | ||
Given an OpenAPI definition file, `openapi-ts-json-schema` will: | ||
|
||
## Contributing | ||
- Dereference the definitions with [`@apidevtools/json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser) (resolving `$ref`'s) | ||
- Convert to JSON schema with [`@openapi-contrib/openapi-schema-to-json-schema`](https://github.com/openapi-contrib/openapi-schema-to-json-schema) | ||
- Generate a TypeScript JSON schema file for each definition (`.ts` files with `as const` assertion) | ||
- Store schemas in a folder structure reflecting the original OpenAPI definition structure | ||
|
||
Any contribution should be provided with a `changesets` update: | ||
## Installation | ||
|
||
``` | ||
npx changeset | ||
npm i openapi-ts-json-schema -D | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { openapiToTsJsonSchema } from 'openapi-ts-json-schema'; | ||
|
||
const { outputFolder } = await openapiToTsJsonSchema({ | ||
openApiSchema: path.resolve(fixtures, 'path/to/my/specs.yaml'), | ||
definitionPathsToGenerateFrom: ['paths', 'components.schemas'], | ||
}); | ||
``` | ||
|
||
### Notes | ||
|
||
Generated JSON schemas folders get currently saved in a `schemas-autogenerated` folder next to the provided OpenAPI definition file. | ||
|
||
Generated JSON schemas folders name gets escaped in order to be valid file system names. | ||
|
||
## Options | ||
|
||
| Property | Type | Description | Default | | ||
| --------------------------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | ||
| **openApiSchema** _(required)_ | `string` | Path to the OpenApi file (supports yaml and json) | - | | ||
| **definitionPathsToGenerateFrom** | `string[]` | OpenApi definition object paths to generate the JSON schemas from. Only matching paths will be generated. (Supports dot notation: `["components.schemas"]`) | `[]` | | ||
| **schemaPatcher** | `(params: { schema: JSONSchema }) => void` | Dynamically patch generated JSON schemas. The provided function will be invoked against every single JSON schema node. | - | | ||
| **silent** | `boolean` | Don't console.log user messages | `false` | | ||
|
||
## Todo | ||
|
||
- Consider exposing an option to set the output folder path |
Empty file.
Oops, something went wrong.