Skip to content

Commit

Permalink
chore: minor cleanups (#75)
Browse files Browse the repository at this point in the history
* test: silent tests output

* chore: fix changeset casing

* docs: update options table

* docs: update readme

* docs: another readme update
  • Loading branch information
toomuchdesign authored Sep 14, 2023
1 parent 85ca0e8 commit 5d3f2fd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .changeset/five-bikes-double.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'openapi-ts-json-schema': minor
---

expose schema id's as `$id` named export
Expose schema id's as `$id` named export
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Generate JSON schema TypeScript files (`.ts`) from OpenAPI definitions which can

Given an OpenAPI definition file, `openapi-ts-json-schema` will:

- Resolve external/remote `$ref`s and dereference them with [`@apidevtools/json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser) (resolving `$ref`'s)
- Resolve external/remote `$ref`s and dereference them with [`@apidevtools/json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser)
- Optionally inline, import or keep local `$ref`s
- Convert to JSON schema with [`@openapi-contrib/openapi-schema-to-json-schema`](https://github.com/openapi-contrib/openapi-schema-to-json-schema) and [`openapi-jsonschema-parameters`](https://www.npmjs.com/package/openapi-jsonschema-parameters)
- Generate one 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
Expand Down Expand Up @@ -51,7 +52,7 @@ type MyModel = FromSchema<typeof myModelSchema>;
| ---------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| **openApiSchema** _(required)_ | `string` | Path to the OpenApi file (supports yaml and json). | - |
| **definitionPathsToGenerateFrom** _(required)_ | `string[]` | OpenApi definition object paths to generate the JSON schemas from. Only matching paths will be generated. (Supports dot notation: `["components.schemas"]`). | - |
| **refHandling** | `"inline" \| "import"` | `"inline"`: inline `$ref` schemas. <br/>`"import"`: generate and import `$ref` schemas.<br/>`"keep"`: keep `$ref` value. | `"inline"` |
| **refHandling** | `"inline" \| "import" \| "keep"` | `"inline"`: inline `$ref` schemas. <br/>`"import"`: generate and import `$ref` schemas.<br/>`"keep"`: keep `$ref` value. | `"inline"` |
| **schemaPatcher** | `(params: { schema: JSONSchema }) => void` | Dynamically patch generated JSON schemas. The provided function will be invoked against every single JSON schema node. | - |
| **outputPath** | `string` | Path where the generated schemas will be saved. Defaults to `/schemas-autogenerated` in same directory as provided `openApiSchema`. | - |
| **silent** | `boolean` | Don't `console.log` user messages. | `false` |
Expand All @@ -60,7 +61,7 @@ type MyModel = FromSchema<typeof myModelSchema>;

Generated JSON schema path names get escaped in order to be valid file system names.

Circular `$ref`s can be technically resolved with `experimentalImportRefs` option. But TS will stop the type recursion and type the schema as `any`. See [relevant tests](https://github.com/toomuchdesign/openapi-ts-json-schema/blob/master/test/circularReference.test.ts).
Circular `$ref`s can be technically resolved with "import" `refHandling` option. But TS will stop the type recursion and type the schema as `any`. See [relevant tests](https://github.com/toomuchdesign/openapi-ts-json-schema/blob/master/test/circularReference.test.ts).

Take a look at the [Developer's notes](./docs/developer-notes.md) for a few more in-depth explanations.

Expand Down
2 changes: 1 addition & 1 deletion test/idExport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('$id export', async () => {
const { outputPath } = await openapiToTsJsonSchema({
openApiSchema: path.resolve(fixtures, 'complex/specs.yaml'),
definitionPathsToGenerateFrom: ['components.months'],
silent: false,
silent: true,
});

const januarySchema = await importFresh(
Expand Down
2 changes: 1 addition & 1 deletion test/metaData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Returned "metaData"', async () => {
openApiSchema: path.resolve(fixtures, 'mini-referenced/specs.yaml'),
definitionPathsToGenerateFrom: ['components.months'],
refHandling: 'import',
silent: false,
silent: true,
});

const answerMeta = metaData.schemas.get('#/components/schemas/Answer');
Expand Down
2 changes: 1 addition & 1 deletion test/outputPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('"outputPath" option', async () => {
openApiSchema: path.resolve(fixtures, 'mini-referenced/specs.yaml'),
definitionPathsToGenerateFrom: ['components.schemas'],
outputPath: customOutputPath,
silent: false,
silent: true,
});

expect(outputPath).toBe(customOutputPath);
Expand Down

0 comments on commit 5d3f2fd

Please sign in to comment.