Repository: samchungy/zod-openapi
Pull request #347 (2024-10-28 01:28:06)

Bump @redocly/cli from 1.25.7 to 1.25.9
Bumps [@redocly/cli](https://github.com/Redocly/redocly-cli) from 1.25.7 to 1.25.9.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/Redocly/redocly-cli/releases"><code>@​redocly/cli</code>'s releases</a>.</em></p>
<blockquote>
<h2><code>@​redocly/cli</code><a href="https://github.com/1"><code>@​1</code></a>.25.9</h2>
<h3>Patch Changes</h3>
<ul>
<li>Updated <code>@​redocly/openapi-core</code> to v1.25.9.</li>
</ul>
<h2><code>@​redocly/cli</code><a href="https://github.com/1"><code>@​1</code></a>.25.8</h2>
<h3>Patch Changes</h3>
<ul>
<li>Added the <code>REDOCLY_SUPPRESS_UPDATE_NOTICE</code> environment variable so that users can skip version updates.</li>
<li>Fixed bundling with the <code>--dereferenced</code> option. Previously, references to external files were not substituted with references to components, causing them to become invalid.</li>
<li>Fixed an issue where using <code>externalValue</code> as a property name was causing the API description validation process to fail.</li>
<li>Updated <code>@​redocly/openapi-core</code> to v1.25.8.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/Redocly/redocly-cli/blob/main/docs/changelog.md"><code>@​redocly/cli</code>'s changelog</a>.</em></p>
<blockquote>
<h2>1.25.9 (2024-10-25)</h2>
<h3>Patch Changes</h3>
<ul>
<li>Updated <code>@​redocly/openapi-core</code> to v1.25.9.</li>
</ul>
<h2>1.25.8 (2024-10-21)</h2>
<h3>Patch Changes</h3>
<ul>
<li>Added the <code>REDOCLY_SUPPRESS_UPDATE_NOTICE</code> environment variable so that users can skip version updates.</li>
<li>Fixed bundling with the <code>--dereferenced</code> option. Previously, references to external files were not substituted with references to components, causing them to become invalid.</li>
<li>Fixed an issue where using <code>externalValue</code> as a property name was causing the API description validation process to fail.</li>
<li>Updated <code>@​redocly/openapi-core</code> to v1.25.8.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/Redocly/redocly-cli/commit/219e15b8089f3040a6a951826881cf75153ca9ff"><code>219e15b</code></a> chore: 🔖 release new versions (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1784">#1784</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/69fb49ee16cf26f1989b0abbf90568a9dd0cb80c"><code>69fb49e</code></a> chore: update Redocly config to v0.15.0 (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1782">#1782</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/d361240e537af31faecb329319ae3b7ae6f98644"><code>d361240</code></a> chore: update benchmarks, coverage threshold; improve types and names (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1781">#1781</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/36161d76112779a5ce37289c9f063a35abb91a4e"><code>36161d7</code></a> chore: update outdated links (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1780">#1780</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/7c429f338e1eaaca456863a42afa758b220b94e6"><code>7c429f3</code></a> chore: 🔖 release new versions (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1777">#1777</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/3b7221e11509299b6eed280f2e620dbf885014a8"><code>3b7221e</code></a> fix: do not try resolving exteranlValues used as property names (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1778">#1778</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/6f870fd1a61f3b883e80d15982e9aba55b80a1b5"><code>6f870fd</code></a> feat(cli): add flag to disable update notifications (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1740">#1740</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/5a493e729d186a63d36782498c4c53b8802fffa1"><code>5a493e7</code></a> fix: wrong discriminator mapping when bundling with derefernce (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1666">#1666</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/6522bc0761d0efc28380d24a4bd38877c48147dc"><code>6522bc0</code></a> docs(all): changes admonition types to 'info' (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1774">#1774</a>)</li>
<li><a href="https://github.com/Redocly/redocly-cli/commit/c6b74be85282ee309494245af00e412b467d9e05"><code>c6b74be</code></a> docs: replace absolute links for a more portable docs set (<a href="https://redirect.github.com/Redocly/redocly-cli/issues/1772">#1772</a>)</li>
<li>See full diff in <a href="https://github.com/Redocly/redocly-cli/compare/@redocly/cli@1.25.7...@redocly/cli@1.25.9">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@redocly/cli&package-manager=npm_and_yarn&previous-version=1.25.7&new-version=1.25.9)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/README.md b/README.md
index b6ad16d..6089aef 100644
--- a/README.md
+++ b/README.md
@@ -276,6 +276,7 @@ const { schema, components } = createSchema(job, {
   schemaType: 'input'; // This controls whether this should be rendered as a request (`input`) or response (`output`). Defaults to `output`
   openapi: '3.0.0'; // OpenAPI version to use, defaults to `'3.1.0'`
   components: { jobId: z.string() } // Additional components to use and create while rendering the schema
+  componentRefPath: '#/definitions/' // Defaults to #/components/schemas/
 })
 ```
 
diff --git a/package.json b/package.json
index f85bedf..f08e453 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,7 @@
   "devDependencies": {
     "@arethetypeswrong/cli": "0.16.4",
     "@crackle/cli": "0.15.5",
-    "@redocly/cli": "1.25.7",
+    "@redocly/cli": "1.25.9",
     "@types/node": "^20.3.0",
     "eslint-plugin-zod-openapi": "^1.0.0-beta.0",
     "openapi3-ts": "4.4.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 082c9bd..49c3d58 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -15,8 +15,8 @@ importers:
         specifier: 0.15.5
         version: 0.15.5(@types/node@20.12.13)(terser@5.31.1)(typescript@5.6.2)(webpack@5.92.0(@swc/core@1.6.1)(esbuild@0.24.0))
       '@redocly/cli':
-        specifier: 1.25.7
-        version: 1.25.7(encoding@0.1.13)(enzyme@3.11.0)
+        specifier: 1.25.9
+        version: 1.25.9(encoding@0.1.13)(enzyme@3.11.0)
       '@types/node':
         specifier: ^20.3.0
         version: 20.12.13
@@ -1181,16 +1181,16 @@ packages:
   '@redocly/ajv@8.11.2':
     resolution: {integrity: sha512-io1JpnwtIcvojV7QKDUSIuMN/ikdOUd1ReEnUnMKGfDVridQZ31J0MmIuqwuRjWDZfmvr+Q0MqCcfHM2gTivOg==}
 
-  '@redocly/cli@1.25.7':
-    resolution: {integrity: sha512-JXsx1IEr4l7qjBQ7ry1Xzj6vpg8xjdKBzcuf0J8DP9Jaupc9g5tS5uVFaLupal1h64m1kJpscX7a8TPzKdoeRA==}
+  '@redocly/cli@1.25.9':
+    resolution: {integrity: sha512-dIQdZGFA1ZqXgE+az0P/5LrhD9evE+AfEen2uTR/EY2e/HdwC2m0aFMaLAMUSdwFYmOmHd8JishUh67TGlBesQ==}
     engines: {node: '>=14.19.0', npm: '>=7.0.0'}
     hasBin: true
 
-  '@redocly/config@0.12.1':
-    resolution: {integrity: sha512-RW3rSirfsPdr0uvATijRDU3f55SuZV3m7/ppdTDvGw4IB0cmeZRkFmqTrchxMqWP50Gfg1tpHnjdxUCNo0E2qg==}
+  '@redocly/config@0.15.0':
+    resolution: {integrity: sha512-QmzuqbhzrbiktRGw+FV7iim+TsfQRU8crJb2s7ls8gP+BMkE1RHZnmJ1lAA/QwzyXbEmKZeGFTdM6PWuRwNlRA==}
 
-  '@redocly/openapi-core@1.25.7':
-    resolution: {integrity: sha512-qidGKk4Bq0Ud0O8gRuXnDSLwVopwrf5+roNvpkvdQPVIHFSYJ5dscJkThdsn7OW8bNqahumQPWWczEh9l93FZw==}
+  '@redocly/openapi-core@1.25.9':
+    resolution: {integrity: sha512-tod9bhIxBJQOeGQ3Ot5Zk707Wcg5YgEcEG766cGxwHqjRUNF5kwZnleBO7CpaLusOMWnQefj7RfFWLZS+IqnhA==}
     engines: {node: '>=14.19.0', npm: '>=7.0.0'}
 
   '@remix-run/router@1.16.1':
@@ -6736,9 +6736,9 @@ snapshots:
       require-from-string: 2.0.2
       uri-js-replace: 1.0.1
 
-  '@redocly/cli@1.25.7(encoding@0.1.13)(enzyme@3.11.0)':
+  '@redocly/cli@1.25.9(encoding@0.1.13)(enzyme@3.11.0)':
     dependencies:
-      '@redocly/openapi-core': 1.25.7(encoding@0.1.13)
+      '@redocly/openapi-core': 1.25.9(encoding@0.1.13)
       abort-controller: 3.0.0
       chokidar: 3.6.0
       colorette: 1.4.0
@@ -6765,12 +6765,12 @@ snapshots:
       - supports-color
       - utf-8-validate
 
-  '@redocly/config@0.12.1': {}
+  '@redocly/config@0.15.0': {}
 
-  '@redocly/openapi-core@1.25.7(encoding@0.1.13)':
+  '@redocly/openapi-core@1.25.9(encoding@0.1.13)':
     dependencies:
       '@redocly/ajv': 8.11.2
-      '@redocly/config': 0.12.1
+      '@redocly/config': 0.15.0
       colorette: 1.4.0
       https-proxy-agent: 7.0.4
       js-levenshtein: 1.1.6
@@ -10771,7 +10771,7 @@ snapshots:
   redoc@2.2.0(core-js@3.37.1)(encoding@0.1.13)(enzyme@3.11.0)(mobx@6.12.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.11(react-dom@18.3.1(react@18.3.1))(react@18.3.1)):
     dependencies:
       '@cfaester/enzyme-adapter-react-18': 0.8.0(enzyme@3.11.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
-      '@redocly/openapi-core': 1.25.7(encoding@0.1.13)
+      '@redocly/openapi-core': 1.25.9(encoding@0.1.13)
       classnames: 2.5.1
       core-js: 3.37.1
       decko: 1.2.0
diff --git a/src/create/components.ts b/src/create/components.ts
index f42542c..91306bc 100644
--- a/src/create/components.ts
+++ b/src/create/components.ts
@@ -385,8 +385,10 @@ const getCallbacks = (
   });
 };
 
-export const createComponentSchemaRef = (schemaRef: string) =>
-  `#/components/schemas/${schemaRef}`;
+export const createComponentSchemaRef = (
+  schemaRef: string,
+  componentPath?: string,
+) => `${componentPath ?? '#/components/schemas/'}${schemaRef}`;
 
 export const createComponentResponseRef = (responseRef: string) =>
   `#/components/responses/${responseRef}`;
diff --git a/src/create/schema/index.ts b/src/create/schema/index.ts
index 8e021a1..e9abb7f 100644
--- a/src/create/schema/index.ts
+++ b/src/create/schema/index.ts
@@ -8,11 +8,11 @@ import {
   type SchemaComponent,
   createComponentSchemaRef,
 } from '../components';
-import type { CreateDocumentOptions } from '../document';
 
 import { enhanceWithMetadata } from './metadata';
 import { createSchemaSwitch } from './parsers';
 import { verifyEffects } from './parsers/transform';
+import type { CreateSchemaOptions } from './single';
 
 export type LazyMap = Map<ZodType, true>;
 
@@ -21,7 +21,7 @@ export interface SchemaState {
   type: CreationType;
   path: string[];
   visited: Set<ZodType>;
-  documentOptions?: CreateDocumentOptions;
+  documentOptions?: CreateSchemaOptions;
 }
 
 const isDescriptionEqual = (schema: Schema, zodSchema: ZodType): boolean =>
@@ -95,7 +95,12 @@ export const createNewRef = <
 
   return {
     type: 'ref',
-    schema: { $ref: createComponentSchemaRef(ref) },
+    schema: {
+      $ref: createComponentSchemaRef(
+        ref,
+        state.documentOptions?.componentRefPath,
+      ),
+    },
     effects: newSchema.effects
       ? [
           {
@@ -121,7 +126,12 @@ export const createExistingRef = <
   if (component && component.type === 'complete') {
     return {
       type: 'ref',
-      schema: { $ref: createComponentSchemaRef(component.ref) },
+      schema: {
+        $ref: createComponentSchemaRef(
+          component.ref,
+          state.documentOptions?.componentRefPath,
+        ),
+      },
       effects: component.effects
         ? [
             {
@@ -138,7 +148,12 @@ export const createExistingRef = <
   if (component && component.type === 'in-progress') {
     return {
       type: 'ref',
-      schema: { $ref: createComponentSchemaRef(component.ref) },
+      schema: {
+        $ref: createComponentSchemaRef(
+          component.ref,
+          state.documentOptions?.componentRefPath,
+        ),
+      },
       effects: [
         {
           type: 'component',
diff --git a/src/create/schema/parsers/object.ts b/src/create/schema/parsers/object.ts
index 523caec..30ad5d8 100644
--- a/src/create/schema/parsers/object.ts
+++ b/src/create/schema/parsers/object.ts
@@ -107,7 +107,14 @@ export const createExtendedSchema = <
   return {
     type: 'schema',
     schema: {
-      allOf: [{ $ref: createComponentSchemaRef(completeComponent.ref) }],
+      allOf: [
+        {
+          $ref: createComponentSchemaRef(
+            completeComponent.ref,
+            state.documentOptions?.componentRefPath,
+          ),
+        },
+      ],
       ...extendedSchema.schema,
     },
     effects: flattenEffects([
diff --git a/src/create/schema/single.ts b/src/create/schema/single.ts
index 193b136..6cde6e3 100644
--- a/src/create/schema/single.ts
+++ b/src/create/schema/single.ts
@@ -34,6 +34,10 @@ export interface CreateSchemaOptions extends CreateDocumentOptions {
    * Additional components to use and create while rendering the schema
    */
   components?: Record<string, ZodType>;
+  /**
+   * The $ref path to use for the component. Defaults to `#/components/schemas/`
+   */
+  componentRefPath?: string;
 }
 
 export const createSchema = (


Test patch:
diff --git a/src/create/schema/single.test.ts b/src/create/schema/single.test.ts
index bae5893..c344bca 100644
--- a/src/create/schema/single.test.ts
+++ b/src/create/schema/single.test.ts
@@ -58,4 +58,25 @@ describe('createSchema', () => {
       },
     });
   });
+
+  it('should support componentRefPath', () => {
+    const schema = createSchema(
+      z.string().openapi({ description: 'foo', ref: 'String' }),
+      {
+        componentRefPath: '#/definitions/',
+      },
+    );
+
+    expect(schema).toEqual<SchemaResult>({
+      schema: {
+        $ref: '#/definitions/String',
+      },
+      components: {
+        String: {
+          type: 'string',
+          description: 'foo',
+        },
+      },
+    });
+  });
 });