@scalar/openapi-to-markdown 1.7.10 → 1.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @scalar/openapi-to-markdown
2
2
 
3
+ ## 1.7.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11149](https://github.com/scalar/scalar/pull/11149): Resolve references in Node Markdown exports against the OpenAPI 3.2 document's `$self` URI when present.
8
+
9
+ For object and inline JSON/YAML input, resolve relative `$self` values against the configured `basePath`, or the current directory when omitted. File access still requires an explicit `basePath`.
10
+
11
+ Preserve literal `$ref` keys in examples when bundling descriptions, including descriptions without `$self`.
12
+ - [#11148](https://github.com/scalar/scalar/pull/11148): Resolve URI security requirements in Node Markdown exports for OpenAPI 3.2 descriptions.
13
+
14
+ Follow annotated security scheme references when resolving URI requirements.
15
+
16
+ Preserve security scheme reference descriptions in OpenAPI 3.1 and 3.2 Markdown exports.
17
+
18
+ ## 1.7.11
19
+
20
+ No changes in this release.
21
+
3
22
  ## 1.7.10
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -70,6 +70,11 @@ const operationMarkdownByPointer = await createMarkdownFromOpenApi(content, {
70
70
 
71
71
  ### Document loading permissions
72
72
 
73
+ When an OpenAPI 3.2 description declares `$self`, Node Markdown exports use that URI to resolve relative
74
+ references in the description. A relative `$self` is resolved against the location the description was
75
+ loaded from. For object and inline JSON/YAML input, relative `$self` values use `basePath`, or the current
76
+ directory when `basePath` is omitted. The loading options below apply to the resulting URLs and paths.
77
+
73
78
  URL inputs and external references block private, loopback, and link-local addresses by default.
74
79
  Protected requests also reject redirects. File access is disabled unless you provide an approved
75
80
  `basePath`; paths and symlinks outside that directory are rejected.
@@ -1 +1 @@
1
- {"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAQjF,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,8DAA8D,CAAA;AAkMrE,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAEjF,8EAA8E;AAC9E,eAAO,MAAM,YAAY,GACvB,OAAO,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EACzD,UAAS,mBAAwB,KAChC,OAAO,CAAC,eAAe,CAqEzB,CAAA"}
1
+ {"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAUjF,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,8DAA8D,CAAA;AAkMrE,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAMjF,8EAA8E;AAC9E,eAAO,MAAM,YAAY,GACvB,OAAO,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EACzD,UAAS,mBAAwB,KAChC,OAAO,CAAC,eAAe,CAgGzB,CAAA"}
@@ -1,3 +1,5 @@
1
+ import { isAbsolute, resolve, sep } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
1
3
  import { parseJsonPointerSegments } from '@scalar/helpers/json/parse-json-pointer-segments';
2
4
  import { isObject } from '@scalar/helpers/object/is-object';
3
5
  import { bundle } from '@scalar/json-magic/bundle';
@@ -7,6 +9,8 @@ import { getValueByPath } from '@scalar/json-magic/helpers/get-value-by-path';
7
9
  import { getRaw } from '@scalar/json-magic/magic-proxy';
8
10
  import { upgrade } from '@scalar/openapi-upgrader';
9
11
  import { deepClone } from '@scalar/workspace-store/helpers/deep-clone';
12
+ import { resolveSecurityRequirements } from '@scalar/workspace-store/helpers/resolve-security-requirements';
13
+ import { resolveOpenApiDocument } from '@scalar/workspace-store/plugins/bundler';
10
14
  import { coerceValue } from '@scalar/workspace-store/schemas/typebox-coerce';
11
15
  import { OpenAPIDocumentSchema, SchemaObjectSchema, } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
12
16
  import { getChildKind, referenceTargetSchemas } from './object-kinds.js';
@@ -151,6 +155,8 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
151
155
  visit(document, getId(document) ?? '', 'document', 'document');
152
156
  return hasExternalReferences;
153
157
  };
158
+ // A relative $self is a URI reference even when the document was retrieved from a local path.
159
+ const resolveNodeOpenApiDocument = (document, retrievalUri) => resolveOpenApiDocument(document, isAbsolute(retrievalUri) ? pathToFileURL(retrievalUri).href : retrievalUri);
154
160
  /** Coerce one plain document and keep references linked to shared targets. */
155
161
  export const loadDocument = async (input, options = {}) => {
156
162
  const { createDocumentLoader } = await import('@scalar/json-magic/bundle/plugins/node');
@@ -162,26 +168,51 @@ export const loadDocument = async (input, options = {}) => {
162
168
  if (!isObject(raw)) {
163
169
  throw new Error('Failed to load OpenAPI document');
164
170
  }
171
+ // Check identity before upgrading so older descriptions cannot acquire $self semantics.
172
+ // In-memory input has no retrieval URI. Keep the fallback directory's trailing separator
173
+ // so relative identities resolve inside it rather than alongside it.
174
+ const retrievalUri = origin ?? `${resolve(options.basePath ?? '.')}${sep}`;
175
+ const entryIdentity = resolveNodeOpenApiDocument(raw, retrievalUri);
165
176
  // Upgrade before indexing so reference resolution sees one consistent dialect.
166
177
  const declaredOpenapiVersion = typeof raw.openapi === 'string' ? raw.openapi : '2.0';
178
+ const isThreeTwo = /^3\.2\.\d+$/.test(declaredOpenapiVersion);
167
179
  const { document: upgraded } = upgrade(raw, '3.2', { onIncompatible: 'collect' });
168
180
  const upgradedSchemas = getSchemas(upgraded);
169
- const hasExternalReferences = attachRefValues(upgraded, upgradedSchemas, { detectOnly: true });
170
181
  let document = upgraded;
171
182
  let schemas = upgradedSchemas;
172
- // Resolve external targets only when the initial local-reference pass finds them.
173
- if (hasExternalReferences) {
183
+ // The local fast path only indexes schema IDs. Let the bundler handle document identities.
184
+ if (entryIdentity || attachRefValues(upgraded, upgradedSchemas, { detectOnly: true })) {
174
185
  const errors = [];
175
186
  document = await bundle(upgraded, {
176
187
  plugins: loader.plugins,
188
+ // Example payloads can contain literal $ref keys.
189
+ traversal: 'document',
177
190
  origin,
178
191
  treeShake: false,
179
- hooks: { onResolveError: (node) => errors.push(`Failed to resolve ${node.$ref}`) },
192
+ urlMap: isThreeTwo,
193
+ hooks: {
194
+ resolveDocument: (resource, retrievalUri) => resource === upgraded ? entryIdentity : resolveNodeOpenApiDocument(resource, retrievalUri),
195
+ onResolveError: (node) => errors.push(`Failed to resolve ${node.$ref}`),
196
+ },
180
197
  });
181
198
  if (errors.length) {
182
199
  throw new Error(errors.join('\n'));
183
200
  }
184
201
  schemas = getSchemas(document);
202
+ // References from nested schema resources can be rewritten to absolute pointers into the entry document.
203
+ if (entryIdentity) {
204
+ schemas.set(entryIdentity.baseUri, '');
205
+ }
206
+ }
207
+ // URI requirements are not $ref fields, so they need the same alias pass as the workspace store.
208
+ // Check the authored version because upgrading older descriptions must not enable URI semantics.
209
+ if (isThreeTwo) {
210
+ await resolveSecurityRequirements(document, { origin: retrievalUri, loaders: loader.plugins });
211
+ schemas = getSchemas(document);
212
+ // The URI pass can add resources, so retain the entry identity in the refreshed index.
213
+ if (entryIdentity) {
214
+ schemas.set(entryIdentity.baseUri, '');
215
+ }
185
216
  }
186
217
  // Cast the document before linking references. TypeBox clones every value that already
187
218
  // matches a union or array schema, and its clone follows all own properties, including
@@ -1 +1 @@
1
- {"version":3,"file":"render-document.d.ts","sourceRoot":"","sources":["../src/render-document.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EAGhB,MAAM,8DAA8D,CAAA;AAYrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAqD7D,2FAA2F;AAC3F,eAAO,MAAM,sBAAsB,QAAO,CAAC,CACzC,QAAQ,EAAE,eAAe,EACzB,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAyRnB,CAAA"}
1
+ {"version":3,"file":"render-document.d.ts","sourceRoot":"","sources":["../src/render-document.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EAGhB,MAAM,8DAA8D,CAAA;AAYrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAqD7D,2FAA2F;AAC3F,eAAO,MAAM,sBAAsB,QAAO,CAAC,CACzC,QAAQ,EAAE,eAAe,EACzB,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAiSnB,CAAA"}
@@ -178,7 +178,7 @@ export const createDocumentRenderer = () => {
178
178
  if (documentContext?.authentication) {
179
179
  nodes.push(anchor(documentContext.authentication));
180
180
  }
181
- nodes.push(...(await renderSecurity(document.security, document.components?.securitySchemes, description, 2)));
181
+ nodes.push(...(await renderSecurity(document.security, document.components?.securitySchemes, description, 2, openapiVersion)));
182
182
  if (document.tags?.length) {
183
183
  nodes.push(heading(2, text('Tags')));
184
184
  for (const { tag, title } of getTagSections(document.tags, openapiVersion)) {
@@ -1 +1 @@
1
- {"version":3,"file":"render-operation.d.ts","sourceRoot":"","sources":["../src/render-operation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAEf,cAAc,EAGf,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAsC,WAAW,EAAE,MAAM,OAAO,CAAA;AAE5E,OAAO,EAAU,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGrD,oEAAoE;AACpE,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,iBAAiB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AA;IAC9B,OAAO,EAAE,cAAc,CAAA;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,qEAAqE;AACrE,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAA;IACjD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC,CAAA;AA8CD,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,MACkC,CAAA;AAEzF,iFAAiF;AACjF,eAAO,MAAM,eAAe,GAC1B,UAAU,eAAe,EACzB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,UAAU,cAAc,EACxB,WAAW,eAAe,EAC1B,SAAS,OAAO,EAChB,4DAAgE,aAAa,KAC5E,OAAO,CAAC,WAAW,EAAE,CAyMvB,CAAA"}
@@ -116,7 +116,7 @@ export const renderOperation = async (document, path, method, pathItem, operatio
116
116
  nodes.push(paragraph(strong(text('Authentication:')), text(' '), link(`#${documentContext.authentication}`, 'Global authentication')));
117
117
  }
118
118
  else {
119
- nodes.push(...(await renderSecurity(operation.security ?? document.security, document.components?.securitySchemes, description, h(1))));
119
+ nodes.push(...(await renderSecurity(operation.security ?? document.security, document.components?.securitySchemes, description, h(1), openapiVersion)));
120
120
  }
121
121
  const parameters = new Map();
122
122
  for (const reference of [...(pathItem.parameters ?? []), ...(operation.parameters ?? [])]) {
@@ -6,5 +6,5 @@ import type { DescriptionParser } from './parse-description.js';
6
6
  * Without declared requirements there is nothing to say: only an explicit empty list means that
7
7
  * no authentication is required.
8
8
  */
9
- export declare const renderSecurity: (requirements: OpenApiDocument["security"], schemes: NonNullable<OpenApiDocument["components"]>["securitySchemes"], description: DescriptionParser, level?: Heading["depth"]) => Promise<RootContent[]>;
9
+ export declare const renderSecurity: (requirements: OpenApiDocument["security"], schemes: NonNullable<OpenApiDocument["components"]>["securitySchemes"], description: DescriptionParser, level?: Heading["depth"], openapiVersion?: string) => Promise<RootContent[]>;
10
10
  //# sourceMappingURL=render-security.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-security.d.ts","sourceRoot":"","sources":["../src/render-security.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AACnG,OAAO,KAAK,EAAE,OAAO,EAA6B,WAAW,EAAE,MAAM,OAAO,CAAA;AAG5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAwD5D;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,cAAc,eAAe,CAAC,UAAU,CAAC,EACzC,SAAS,WAAW,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,EACtE,aAAa,iBAAiB,EAC9B,QAAO,OAAO,CAAC,OAAO,CAAK,KAC1B,OAAO,CAAC,WAAW,EAAE,CAgCvB,CAAA"}
1
+ {"version":3,"file":"render-security.d.ts","sourceRoot":"","sources":["../src/render-security.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AACnG,OAAO,KAAK,EAAE,OAAO,EAA6B,WAAW,EAAE,MAAM,OAAO,CAAA;AAG5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AA0D5D;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,cAAc,eAAe,CAAC,UAAU,CAAC,EACzC,SAAS,WAAW,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,EACtE,aAAa,iBAAiB,EAC9B,QAAO,OAAO,CAAC,OAAO,CAAK,EAC3B,uBAAwB,KACvB,OAAO,CAAC,WAAW,EAAE,CAkCvB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref';
1
+ import { getResolvedSecurityScheme } from '@scalar/workspace-store/helpers/get-resolved-security-scheme';
2
2
  import { heading, inlineCode, item, list, paragraph, strong, text } from './markdown-nodes.js';
3
3
  const flowNames = {
4
4
  implicit: 'implicit',
@@ -53,7 +53,7 @@ const summarizeScheme = (scheme) => {
53
53
  * Without declared requirements there is nothing to say: only an explicit empty list means that
54
54
  * no authentication is required.
55
55
  */
56
- export const renderSecurity = async (requirements, schemes, description, level = 4) => {
56
+ export const renderSecurity = async (requirements, schemes, description, level = 4, openapiVersion = '3.2.0') => {
57
57
  if (!requirements) {
58
58
  return [];
59
59
  }
@@ -72,7 +72,9 @@ export const renderSecurity = async (requirements, schemes, description, level =
72
72
  }
73
73
  const entriesNodes = [];
74
74
  for (const [name, scopes] of entries) {
75
- const scheme = getResolvedRef(schemes?.[name]);
75
+ const scheme = getResolvedSecurityScheme(schemes?.[name], {
76
+ overrideDescription: /^3\.[12]\./.test(openapiVersion),
77
+ });
76
78
  const line = [strong(text(name))];
77
79
  if (scheme) {
78
80
  line.push(text(': '), ...summarizeScheme(scheme));
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "llm",
17
17
  "swagger"
18
18
  ],
19
- "version": "1.7.10",
19
+ "version": "1.7.12",
20
20
  "engines": {
21
21
  "node": ">=22.19.0"
22
22
  },
@@ -46,20 +46,20 @@
46
46
  ],
47
47
  "dependencies": {
48
48
  "@scalar/helpers": "0.19.0",
49
- "@scalar/json-magic": "0.21.1",
50
- "@scalar/markdown": "0.1.0",
49
+ "@scalar/json-magic": "0.22.0",
50
+ "@scalar/markdown": "0.1.2",
51
51
  "@scalar/openapi-upgrader": "0.5.1",
52
- "@scalar/workspace-store": "0.75.0"
52
+ "@scalar/workspace-store": "0.76.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@scalar/components": "0.35.3",
55
+ "@scalar/components": "0.35.5",
56
56
  "@scalar/galaxy": "0.7.4",
57
- "@scalar/highlight": "0.7.0",
58
- "@scalar/themes": "0.20.3",
57
+ "@scalar/highlight": "0.8.1",
58
+ "@scalar/themes": "0.21.1",
59
59
  "@tailwindcss/vite": "^4.3.5",
60
60
  "@types/mdast": "^4.0.4",
61
61
  "@vitejs/plugin-vue": "^6.0.11",
62
- "marked": "^18.2.0",
62
+ "marked": "^18.2.1",
63
63
  "rehype-parse": "^9.0.1",
64
64
  "rehype-sanitize": "^6.0.0",
65
65
  "rehype-stringify": "^10.0.1",
@@ -70,7 +70,7 @@
70
70
  "tsx": "4.23.15",
71
71
  "unified": "^11.0.5",
72
72
  "vite": "8.3.8",
73
- "vitest": "5.1.0",
73
+ "vitest": "5.1.1",
74
74
  "vue": "^3.5.45",
75
75
  "vue-tsc": "3.3.11"
76
76
  },