@publier/openapi 0.3.38
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/README.md +1 -0
- package/dist/generate.d.mts +156 -0
- package/dist/generate.mjs +1 -0
- package/dist/index.d.mts +461 -0
- package/dist/index.mjs +1 -0
- package/dist/parser.d.mts +136 -0
- package/dist/parser.mjs +1 -0
- package/dist/server.d.mts +238 -0
- package/dist/server.mjs +1 -0
- package/package.json +80 -0
- package/src/components/_collapsible-section.astro +14 -0
- package/src/components/_schema-row.astro +11 -0
- package/src/components/api-page.astro +21 -0
- package/src/components/api-playground-ce-element.ts +90 -0
- package/src/components/api-playground.astro +14 -0
- package/src/components/api-reference.astro +21 -0
- package/src/components/async-channel.astro +11 -0
- package/src/components/async-message.astro +10 -0
- package/src/components/code-samples.astro +28 -0
- package/src/components/method-badge.astro +26 -0
- package/src/components/param-field.astro +11 -0
- package/src/components/props.ts +91 -0
- package/src/components/request-example.astro +12 -0
- package/src/components/response-example.astro +17 -0
- package/src/components/response-field.astro +11 -0
- package/src/components/schema-view.astro +15 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderCodeSamples } from '@publier/native';
|
|
3
|
+
import { buildCodeSamples } from '../code-sample-generators.ts';
|
|
4
|
+
import type { CodeSamplesProps } from './props.ts';
|
|
5
|
+
type Props = CodeSamplesProps;
|
|
6
|
+
|
|
7
|
+
const { method, path, operation, baseUrl = 'https://api.example.com' } = Astro.props;
|
|
8
|
+
const samples = buildCodeSamples(method, path, operation, baseUrl);
|
|
9
|
+
const html = openapiRenderCodeSamples(method, path, JSON.stringify(samples));
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<Fragment set:html={html} />
|
|
13
|
+
|
|
14
|
+
<style is:global>
|
|
15
|
+
.cs-code {
|
|
16
|
+
background-color: var(--color-zinc-950);
|
|
17
|
+
}
|
|
18
|
+
.cs-code .tab::before {
|
|
19
|
+
font-size: 0.75rem;
|
|
20
|
+
font-weight: 500;
|
|
21
|
+
color: var(--color-zinc-500);
|
|
22
|
+
transition: color 0.15s;
|
|
23
|
+
}
|
|
24
|
+
.cs-code .tab:hover::before { color: var(--color-zinc-300); }
|
|
25
|
+
.cs-code .tab:checked::before { color: var(--color-zinc-100); }
|
|
26
|
+
.cs-code .tab:checked { border-bottom-color: var(--color-primary); }
|
|
27
|
+
.cs-code .tab-content { border: none; border-radius: 0; padding: 0; background: transparent; }
|
|
28
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderMethodBadge } from '@publier/native';
|
|
3
|
+
import type { MethodBadgeProps } from './props.ts';
|
|
4
|
+
type Props = MethodBadgeProps;
|
|
5
|
+
|
|
6
|
+
const { method } = Astro.props;
|
|
7
|
+
const html = openapiRenderMethodBadge(method);
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<Fragment set:html={html} />
|
|
11
|
+
|
|
12
|
+
<style is:global>
|
|
13
|
+
.method-badge {
|
|
14
|
+
--badge-h: var(--color-zinc-500);
|
|
15
|
+
--badge-l: var(--color-zinc-600);
|
|
16
|
+
--badge-d: var(--color-zinc-400);
|
|
17
|
+
color: light-dark(var(--badge-l), var(--badge-d));
|
|
18
|
+
background: color-mix(in oklch, var(--badge-h) 10%, transparent);
|
|
19
|
+
border-color: color-mix(in oklch, var(--badge-h) 20%, transparent);
|
|
20
|
+
}
|
|
21
|
+
.method-badge[data-method="get"] { --badge-h: var(--color-green-500); --badge-l: var(--color-green-600); --badge-d: var(--color-green-400); }
|
|
22
|
+
.method-badge[data-method="post"] { --badge-h: var(--color-blue-500); --badge-l: var(--color-blue-600); --badge-d: var(--color-blue-400); }
|
|
23
|
+
.method-badge[data-method="put"] { --badge-h: var(--color-yellow-500); --badge-l: var(--color-yellow-600); --badge-d: var(--color-yellow-400); }
|
|
24
|
+
.method-badge[data-method="delete"] { --badge-h: var(--color-red-500); --badge-l: var(--color-red-600); --badge-d: var(--color-red-400); }
|
|
25
|
+
.method-badge[data-method="patch"] { --badge-h: var(--color-orange-500); --badge-l: var(--color-orange-600); --badge-d: var(--color-orange-400); }
|
|
26
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderParamField } from '@publier/native';
|
|
3
|
+
import type { ParamFieldProps } from './props.ts';
|
|
4
|
+
type Props = ParamFieldProps;
|
|
5
|
+
|
|
6
|
+
const { name, type, required, default: d, deprecated, placeholder } = Astro.props;
|
|
7
|
+
const slotHtml = await Astro.slots.render('default');
|
|
8
|
+
const html = openapiRenderParamField(name, type, required ?? false, deprecated ?? false, d ?? null, placeholder ?? null, slotHtml);
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<Fragment set:html={html} />
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AsyncApiChannel,
|
|
3
|
+
AsyncApiMessage,
|
|
4
|
+
AsyncApiOperation,
|
|
5
|
+
AsyncApiServer,
|
|
6
|
+
} from '../async-types.ts';
|
|
7
|
+
import type {
|
|
8
|
+
HttpMethod,
|
|
9
|
+
OpenApiOperation,
|
|
10
|
+
OpenApiResponse,
|
|
11
|
+
OpenApiServer,
|
|
12
|
+
OpenApiSpec,
|
|
13
|
+
} from '../types.ts';
|
|
14
|
+
|
|
15
|
+
export interface APIReferenceProps {
|
|
16
|
+
method: HttpMethod;
|
|
17
|
+
path: string;
|
|
18
|
+
operation: OpenApiOperation;
|
|
19
|
+
spec?: OpenApiSpec;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface APIPageProps {
|
|
24
|
+
method: HttpMethod;
|
|
25
|
+
path: string;
|
|
26
|
+
operation: OpenApiOperation;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MethodBadgeProps {
|
|
30
|
+
method: HttpMethod;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface APIPlaygroundProps {
|
|
34
|
+
method: HttpMethod;
|
|
35
|
+
path: string;
|
|
36
|
+
operation: OpenApiOperation;
|
|
37
|
+
servers?: OpenApiServer[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CodeSamplesProps {
|
|
41
|
+
method: HttpMethod;
|
|
42
|
+
path: string;
|
|
43
|
+
operation: OpenApiOperation;
|
|
44
|
+
baseUrl?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RequestExampleProps {
|
|
48
|
+
method: HttpMethod;
|
|
49
|
+
path: string;
|
|
50
|
+
operation: OpenApiOperation;
|
|
51
|
+
baseUrl?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ResponseExampleProps {
|
|
55
|
+
responses: Record<string, OpenApiResponse>;
|
|
56
|
+
instanceId?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SchemaViewProps {
|
|
60
|
+
schema: import('../types.ts').OpenApiSchema;
|
|
61
|
+
name?: string;
|
|
62
|
+
required?: boolean;
|
|
63
|
+
depth?: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ParamFieldProps {
|
|
67
|
+
name: string;
|
|
68
|
+
type: string;
|
|
69
|
+
required?: boolean;
|
|
70
|
+
default?: string;
|
|
71
|
+
deprecated?: boolean;
|
|
72
|
+
placeholder?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ResponseFieldProps {
|
|
76
|
+
name: string;
|
|
77
|
+
type: string;
|
|
78
|
+
required?: boolean;
|
|
79
|
+
deprecated?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface AsyncChannelProps {
|
|
83
|
+
channelName: string;
|
|
84
|
+
channel: AsyncApiChannel;
|
|
85
|
+
operations: { name: string; operation: AsyncApiOperation; messages: AsyncApiMessage[] }[];
|
|
86
|
+
servers?: Record<string, AsyncApiServer>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface AsyncMessageProps {
|
|
90
|
+
message: AsyncApiMessage;
|
|
91
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderRequestExample } from '@publier/native';
|
|
3
|
+
import { getMediaTypeExample } from '../example-utils.ts';
|
|
4
|
+
import type { RequestExampleProps } from './props.ts';
|
|
5
|
+
type Props = RequestExampleProps;
|
|
6
|
+
|
|
7
|
+
const { method, path, operation, baseUrl = 'https://api.example.com' } = Astro.props;
|
|
8
|
+
const body = operation.requestBody?.content ? getMediaTypeExample(operation.requestBody.content) : null;
|
|
9
|
+
const html = openapiRenderRequestExample(method, path, JSON.stringify(operation), baseUrl, body ?? null);
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<Fragment set:html={html} />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderResponseExample } from '@publier/native';
|
|
3
|
+
import { getMediaTypeExample } from '../example-utils.ts';
|
|
4
|
+
import type { ResponseExampleProps } from './props.ts';
|
|
5
|
+
type Props = ResponseExampleProps;
|
|
6
|
+
|
|
7
|
+
const { responses, instanceId } = Astro.props;
|
|
8
|
+
const tabs = Object.entries(responses).map(([code, r]) => ({
|
|
9
|
+
code,
|
|
10
|
+
description: r.description,
|
|
11
|
+
body: r.content ? getMediaTypeExample(r.content) : undefined,
|
|
12
|
+
headers: r.headers ? Object.entries(r.headers).map(([n, h]) => ({ name: n, description: h.description })) : undefined,
|
|
13
|
+
}));
|
|
14
|
+
const html = openapiRenderResponseExample(JSON.stringify(tabs), instanceId ?? null);
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<Fragment set:html={html} />
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderResponseField } from '@publier/native';
|
|
3
|
+
import type { ResponseFieldProps } from './props.ts';
|
|
4
|
+
type Props = ResponseFieldProps;
|
|
5
|
+
|
|
6
|
+
const { name, type, required, deprecated } = Astro.props;
|
|
7
|
+
const slotHtml = await Astro.slots.render('default');
|
|
8
|
+
const html = openapiRenderResponseField(name, type, required ?? false, deprecated ?? false, slotHtml);
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<Fragment set:html={html} />
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { openapiRenderSchemaView } from '@publier/native';
|
|
3
|
+
import type { SchemaViewProps } from './props.ts';
|
|
4
|
+
type Props = SchemaViewProps;
|
|
5
|
+
|
|
6
|
+
const { schema, name, required, depth = 0 } = Astro.props;
|
|
7
|
+
const html = openapiRenderSchemaView(
|
|
8
|
+
JSON.stringify(schema),
|
|
9
|
+
name ?? null,
|
|
10
|
+
required ?? false,
|
|
11
|
+
depth,
|
|
12
|
+
);
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<Fragment set:html={html} />
|