diff --git a/.changeset/five-bikes-double.md b/.changeset/five-bikes-double.md index 6e13be6..0fb559a 100644 --- a/.changeset/five-bikes-double.md +++ b/.changeset/five-bikes-double.md @@ -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 diff --git a/README.md b/README.md index 922f1b4..baddc42 100644 --- a/README.md +++ b/README.md @@ -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 @@ -51,7 +52,7 @@ type MyModel = FromSchema; | ---------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | | **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.
`"import"`: generate and import `$ref` schemas.
`"keep"`: keep `$ref` value. | `"inline"` | +| **refHandling** | `"inline" \| "import" \| "keep"` | `"inline"`: inline `$ref` schemas.
`"import"`: generate and import `$ref` schemas.
`"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` | @@ -60,7 +61,7 @@ type MyModel = FromSchema; 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. diff --git a/test/idExport.test.ts b/test/idExport.test.ts index 844dcce..17be872 100644 --- a/test/idExport.test.ts +++ b/test/idExport.test.ts @@ -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( diff --git a/test/metaData.test.ts b/test/metaData.test.ts index b64e80d..4ae1976 100644 --- a/test/metaData.test.ts +++ b/test/metaData.test.ts @@ -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'); diff --git a/test/outputPath.test.ts b/test/outputPath.test.ts index c21f23c..318baa1 100644 --- a/test/outputPath.test.ts +++ b/test/outputPath.test.ts @@ -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);