@scalar/openapi-to-markdown 0.5.43 → 0.6.0
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 +8 -0
- package/README.md +32 -2
- package/dist/components/MarkdownReference.vue.d.ts +1 -1
- package/dist/components/MarkdownReference.vue.d.ts.map +1 -1
- package/dist/components/Schema.vue.d.ts +2 -1
- package/dist/components/Schema.vue.d.ts.map +1 -1
- package/dist/components/Security.vue.d.ts +9 -0
- package/dist/components/Security.vue.d.ts.map +1 -0
- package/dist/create-markdown-from-openapi.d.ts +13 -2
- package/dist/create-markdown-from-openapi.d.ts.map +1 -1
- package/dist/index.js +443 -193
- package/dist/index.js.map +1 -1
- package/dist/selection.test.d.ts +2 -0
- package/dist/selection.test.d.ts.map +1 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @scalar/openapi-to-markdown
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#10169](https://github.com/scalar/scalar/pull/10169): Render scoped operation, tag, model, webhook, and introduction pages in Markdown and HTML while preserving referenced schemas and inherited context.
|
|
8
|
+
|
|
9
|
+
## 0.5.44
|
|
10
|
+
|
|
3
11
|
## 0.5.43
|
|
4
12
|
|
|
5
13
|
## 0.5.42
|
package/README.md
CHANGED
|
@@ -73,8 +73,8 @@ const operationMarkdownByPointer = await createMarkdownFromOpenApi(content, {
|
|
|
73
73
|
You use the package with any Node.js framework. Here is an example for [Hono](https://hono.dev/):
|
|
74
74
|
|
|
75
75
|
```ts
|
|
76
|
-
import { Hono } from 'hono'
|
|
77
76
|
import { createMarkdownFromOpenApi } from '@scalar/openapi-to-markdown'
|
|
77
|
+
import { Hono } from 'hono'
|
|
78
78
|
|
|
79
79
|
// Generate Markdown from an OpenAPI document
|
|
80
80
|
const markdown = await createMarkdownFromOpenApi(content)
|
|
@@ -102,8 +102,8 @@ transforms the HTML to Markdown then.
|
|
|
102
102
|
So if you'd like to have a really light-weight HTML API Reference, here you are:
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
|
-
import { Hono } from 'hono'
|
|
106
105
|
import { createHtmlFromOpenApi } from '@scalar/openapi-to-markdown'
|
|
106
|
+
import { Hono } from 'hono'
|
|
107
107
|
|
|
108
108
|
// Generate HTML from an OpenAPI document
|
|
109
109
|
const html = await createHtmlFromOpenApi(content)
|
|
@@ -139,3 +139,33 @@ We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
|
|
|
139
139
|
## License
|
|
140
140
|
|
|
141
141
|
The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
|
|
142
|
+
|
|
143
|
+
## Individual reference pages
|
|
144
|
+
|
|
145
|
+
Both `createMarkdownFromOpenApi` and `createHtmlFromOpenApi` accept the same options. Choose one selector per call:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
await createMarkdownFromOpenApi(content, { tag: 'pets' })
|
|
149
|
+
await createMarkdownFromOpenApi(content, { model: 'Pet' })
|
|
150
|
+
await createMarkdownFromOpenApi(content, {
|
|
151
|
+
webhook: { name: 'petCreated', method: 'post' },
|
|
152
|
+
})
|
|
153
|
+
await createMarkdownFromOpenApi(content, { introduction: true })
|
|
154
|
+
await createHtmlFromOpenApi(content, { operation: { operationId: 'getUser' } })
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- **Operation:** One operation, effective parameters, servers and authentication, its tags, and referenced component schemas. Existing path/method, operation ID, and JSON pointer selectors still work. Methods are case insensitive.
|
|
158
|
+
- **Tag:** Tag metadata and all path operations with that exact tag, plus their context and schema dependencies. A tag used only by operations is supported. A declared tag with no operations renders its metadata. Operations with multiple tags appear once, with only the selected tag shown.
|
|
159
|
+
- **Model:** One component schema and its referenced schemas. Primitive, array, composed, and recursive models use the shared schema renderer.
|
|
160
|
+
- **Webhook:** One operation selected by its exact OpenAPI webhook name and method, including parameters, payload and responses. The name is a label, not a delivery URL.
|
|
161
|
+
- **Introduction:** API title, versions, description, contact, license, terms of service, servers and global authentication requirements. No operations, tags, models or webhooks.
|
|
162
|
+
|
|
163
|
+
Selected pages retain API title, versions and description. They exclude unrelated reference content. Operation servers override path servers, which override document servers. Operation security overrides document security, including `security: []` for anonymous access. Parameter overrides use the parameter name and location. Required schemas are collected after reference resolution, so dependencies remain available even when their original section is omitted.
|
|
164
|
+
|
|
165
|
+
Omitting options, or passing `{}`, renders the whole document. OpenAPI 2.0 inputs are migrated before selection: use definition names with `model`. Webhooks require OpenAPI 3.1 or later.
|
|
166
|
+
|
|
167
|
+
### Errors and limitations
|
|
168
|
+
|
|
169
|
+
Invalid, combined, or missing selectors reject the returned promise with an error. Duplicate operation IDs are ambiguous and list matching paths and methods; use a path/method selector instead. Duplicate tag declarations are also rejected. Names are case sensitive. Operation JSON pointers must target `/paths/{path}/{method}`, with an optional leading `#` and standard `~0`/`~1` escaping.
|
|
170
|
+
|
|
171
|
+
Selection does not add support for every OpenAPI or JSON Schema keyword. Callbacks are not selectable pages. External references follow the existing workspace loader behavior. Recursive schema expansion stops on a repeated ancestor, with a depth limit of ten as a fallback. Shared dependencies have one component section, but may also appear inline where used. Authentication lists alternatives separately; schemes within one requirement must be used together.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.
|
|
1
|
+
import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
2
|
type MarkdownDocument = Partial<OpenApiDocument> & Pick<OpenApiDocument, 'openapi' | 'info'>;
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
content: MarkdownDocument;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownReference.vue.d.ts","sourceRoot":"","sources":["../../src/components/MarkdownReference.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarkdownReference.vue.d.ts","sourceRoot":"","sources":["../../src/components/MarkdownReference.vue"],"names":[],"mappings":"AAqnBA,OAAO,KAAK,EACV,eAAe,EAOhB,MAAM,8DAA8D,CAAA;AASrE,KAAK,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,GAC9C,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,MAAM,CAAC,CAAA;AA2C3C,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,gBAAgB,CAAA;CAC1B,CAAC;AA20BF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { MaybeRefSchemaObject } from '@scalar/workspace-store/schemas/v3.
|
|
1
|
+
import type { MaybeRefSchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/schema';
|
|
2
2
|
type __VLS_Props = {
|
|
3
3
|
schema: MaybeRefSchemaObject;
|
|
4
4
|
depth?: number;
|
|
5
|
+
ancestors?: unknown[];
|
|
5
6
|
};
|
|
6
7
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
8
|
declare const _default: typeof __VLS_export;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.vue.d.ts","sourceRoot":"","sources":["../../src/components/Schema.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Schema.vue.d.ts","sourceRoot":"","sources":["../../src/components/Schema.vue"],"names":[],"mappings":"AAiaA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAA;AAE9F,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,oBAAoB,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;CACtB,CAAC;AA+iBF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
requirements?: OpenApiDocument['security'];
|
|
4
|
+
schemes?: NonNullable<OpenApiDocument['components']>['securitySchemes'];
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const _default: typeof __VLS_export;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=Security.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Security.vue.d.ts","sourceRoot":"","sources":["../../src/components/Security.vue"],"names":[],"mappings":"AA0DA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AAGnG,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,eAAe,CAAC,UAAU,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;CACxE,CAAC;AAoGF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpMethod } from '@scalar/helpers/http/http-methods';
|
|
2
|
-
import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.
|
|
2
|
+
import type { OpenApiDocument } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
3
3
|
type AnyDocument = OpenApiDocument | Record<string, unknown> | string;
|
|
4
4
|
export type { HttpMethod };
|
|
5
5
|
export type OperationSelector = {
|
|
@@ -10,8 +10,19 @@ export type OperationSelector = {
|
|
|
10
10
|
} | {
|
|
11
11
|
pointer: string;
|
|
12
12
|
};
|
|
13
|
+
/** Select one reference page, or omit selectors for the whole document. */
|
|
13
14
|
export type OpenApiRenderOptions = {
|
|
14
|
-
|
|
15
|
+
[Key in keyof PageSelectors]: Partial<Record<Exclude<keyof PageSelectors, Key>, never>> & Pick<PageSelectors, Key>;
|
|
16
|
+
}[keyof PageSelectors] | Partial<Record<keyof PageSelectors, never>>;
|
|
17
|
+
type PageSelectors = {
|
|
18
|
+
operation: OperationSelector;
|
|
19
|
+
tag: string;
|
|
20
|
+
model: string;
|
|
21
|
+
webhook: {
|
|
22
|
+
name: string;
|
|
23
|
+
method: HttpMethod | Uppercase<HttpMethod>;
|
|
24
|
+
};
|
|
25
|
+
introduction: true;
|
|
15
26
|
};
|
|
16
27
|
export declare function createHtmlFromOpenApi(input: AnyDocument, options?: OpenApiRenderOptions): Promise<string>;
|
|
17
28
|
export declare function createMarkdownFromOpenApi(content: AnyDocument, options?: OpenApiRenderOptions): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-markdown-from-openapi.d.ts","sourceRoot":"","sources":["../src/create-markdown-from-openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"create-markdown-from-openapi.d.ts","sourceRoot":"","sources":["../src/create-markdown-from-openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAOnE,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,8DAA8D,CAAA;AAanH,KAAK,WAAW,GAAG,eAAe,GAAG,MAAM,CAAC,MAAM,EA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