@kawapress/plugin-openapi 0.0.1 → 0.2.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/package.json +3 -3
- package/src/components/KawaOpenApiCard.vue +2 -1
- package/src/components/KawaOpenApiEndpoint.vue +3 -2
- package/src/components/KawaOpenApiJourney.vue +412 -53
- package/src/components/KawaOpenApiMap.vue +2 -1
- package/src/components/KawaOpenApiPath.vue +16 -0
- package/src/components/journey.ts +401 -0
- package/src/components/openapi.css +205 -50
- package/src/data/components.ts +129 -111
- package/src/index.ts +3 -2
- package/src/options.ts +56 -8
- package/src/pages.ts +34 -6
- package/src/read/arazzo.ts +1 -0
- package/src/render/labels.ts +137 -15
- package/src/render/pages.ts +30 -6
- package/src/service.ts +53 -25
- package/src/types.ts +15 -4
- package/src/vite.ts +7 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kawapress/plugin-openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "HTTP API reference pages for KawaPress from OpenAPI 3.x: example-first payload views, a resource map, Arazzo journeys, mock try-it and API change pages",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://kawapress.dev/",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"registry": "https://registry.npmjs.org/"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"kawapress": ">=0.9.0 <0.
|
|
52
|
+
"kawapress": ">=0.9.0 <0.11.0",
|
|
53
53
|
"markdown-exit": "^1.3.0",
|
|
54
54
|
"vite": "^8.2.2",
|
|
55
55
|
"vue": "^3.5.41"
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"markdown-exit": "^1.3.0",
|
|
66
66
|
"vite": "^8.2.2",
|
|
67
67
|
"vue": "^3.5.41",
|
|
68
|
-
"kawapress": "0.0
|
|
68
|
+
"kawapress": "0.10.0"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { CardData } from '../data/components'
|
|
3
|
+
import KawaOpenApiPath from './KawaOpenApiPath.vue'
|
|
3
4
|
|
|
4
5
|
defineProps<{
|
|
5
6
|
data: CardData
|
|
@@ -15,7 +16,7 @@ const isSsgMarkdown = import.meta.env.SSG_MD
|
|
|
15
16
|
<div v-else class="kawa-openapi-card">
|
|
16
17
|
<div class="kawa-openapi-card__head">
|
|
17
18
|
<span :class="`kawa-openapi-method kawa-openapi-method--${data.method.toLowerCase()}`">{{ data.method }}</span>
|
|
18
|
-
<code
|
|
19
|
+
<code><KawaOpenApiPath :path="data.path" /></code>
|
|
19
20
|
<a :href="data.href" class="kawa-openapi-card__title">{{ data.title }}</a>
|
|
20
21
|
</div>
|
|
21
22
|
<div v-if="data.summaryHtml" class="kawa-openapi-card__summary" v-html="data.summaryHtml" />
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { EndpointData } from '../data/components'
|
|
3
3
|
import type { Rule } from './validate'
|
|
4
4
|
import { computed, reactive, shallowRef } from 'vue'
|
|
5
|
+
import KawaOpenApiPath from './KawaOpenApiPath.vue'
|
|
5
6
|
import { validate } from './validate'
|
|
6
7
|
|
|
7
8
|
const props = defineProps<{
|
|
@@ -119,7 +120,7 @@ async function send(): Promise<void> {
|
|
|
119
120
|
<div v-else class="kawa-openapi-endpoint">
|
|
120
121
|
<div class="kawa-openapi-endpoint__bar">
|
|
121
122
|
<span :class="methodClass">{{ data.method }}</span>
|
|
122
|
-
<code class="kawa-openapi-endpoint__path"
|
|
123
|
+
<code class="kawa-openapi-endpoint__path"><KawaOpenApiPath :path="data.path" /></code>
|
|
123
124
|
<span class="kawa-openapi-endpoint__spacer" />
|
|
124
125
|
<button v-if="data.curl" type="button" class="kawa-openapi-button" @click="copyCurl">
|
|
125
126
|
{{ copyState === 'copied' ? data.text.copied : copyState === 'failed' ? data.text.copyFailed : data.text.copyCurl }}
|
|
@@ -170,7 +171,7 @@ async function send(): Promise<void> {
|
|
|
170
171
|
<button type="button" class="kawa-openapi-button kawa-openapi-button--primary" :disabled="sending" @click="send">
|
|
171
172
|
{{ sending ? data.text.sending : data.text.send }}
|
|
172
173
|
</button>
|
|
173
|
-
<code class="kawa-openapi-try__target">{{ request.method }}
|
|
174
|
+
<code class="kawa-openapi-try__target">{{ request.method }} <KawaOpenApiPath :path="resolvedPath()" /></code>
|
|
174
175
|
</div>
|
|
175
176
|
<div class="kawa-openapi-try__output" :class="{ 'is-error': output?.error }" aria-live="polite">
|
|
176
177
|
<template v-if="output">
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type { JourneyData } from '../data/components'
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import type { JourneyData, JourneyStepData } from '../data/components'
|
|
3
|
+
import type { CodeStep, JourneyExpression, Line, Values } from './journey'
|
|
4
|
+
import { computed, onBeforeUnmount, reactive, shallowRef } from 'vue'
|
|
5
|
+
import { curlScript, evaluate, EXPRESSION_KEY, javascriptScript, mockResponse, readPointer, resolve, templateLines, valueLines } from './journey'
|
|
6
|
+
import { validate } from './validate'
|
|
5
7
|
|
|
6
8
|
const props = defineProps<{
|
|
7
9
|
data: JourneyData
|
|
@@ -9,42 +11,292 @@ const props = defineProps<{
|
|
|
9
11
|
|
|
10
12
|
const isSsgMarkdown = import.meta.env.SSG_MD
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
interface Result {
|
|
15
|
+
ok: boolean
|
|
16
|
+
status: string
|
|
17
|
+
path: string
|
|
18
|
+
body?: unknown
|
|
19
|
+
/** Why the request could not work. */
|
|
20
|
+
problems: string[]
|
|
21
|
+
missing: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const text = props.data.text
|
|
25
|
+
function fill(template: string, values: Record<string, string | number>): string {
|
|
26
|
+
return template.replaceAll(/\{(\w+)\}/g, (whole, name: string) => (name in values ? String(values[name]) : whole))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* ------------------------------------------------------------------- state */
|
|
30
|
+
|
|
31
|
+
const inputText = reactive<Record<string, string>>(Object.fromEntries(
|
|
32
|
+
props.data.inputs.map(input => [input.name, typeof input.value === 'string' ? input.value : JSON.stringify(input.value)]),
|
|
33
|
+
))
|
|
34
|
+
const outputs = reactive<Record<string, unknown>>({})
|
|
35
|
+
const results = reactive<Record<number, Result>>({})
|
|
36
|
+
const opened = reactive<Record<number, boolean>>({})
|
|
37
|
+
const log = shallowRef<{ kind: 'request' | 'response' | 'error', text: string }[]>([])
|
|
38
|
+
const landed = shallowRef('')
|
|
39
|
+
const notice = shallowRef('')
|
|
14
40
|
const running = shallowRef(false)
|
|
41
|
+
const language = shallowRef<'curl' | 'javascript'>('curl')
|
|
42
|
+
const copyState = shallowRef<'idle' | 'copied' | 'failed'>('idle')
|
|
15
43
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
44
|
+
onBeforeUnmount(() => clearTimeout(timer))
|
|
45
|
+
|
|
46
|
+
const stepIndex = new Map(props.data.steps.map(step => [step.id, step.index]))
|
|
47
|
+
const outputList = props.data.steps.flatMap(step => step.outputs.map(output => ({ ...output, step: step.index })))
|
|
48
|
+
|
|
49
|
+
function inputValue(name: string): unknown {
|
|
50
|
+
const original = props.data.inputs.find(input => input.name === name)?.value
|
|
51
|
+
const raw = inputText[name] ?? ''
|
|
52
|
+
if (typeof original === 'string') {
|
|
53
|
+
return raw
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(raw)
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return raw
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const values = computed<Values>(() => ({
|
|
64
|
+
inputs: Object.fromEntries(props.data.inputs.map(input => [input.name, inputValue(input.name)])),
|
|
65
|
+
outputs,
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
const doneCount = computed(() => props.data.steps.filter(step => results[step.index]?.ok).length)
|
|
69
|
+
const next = computed(() => props.data.steps.find(step => !results[step.index]?.ok)?.index ?? -1)
|
|
70
|
+
const passed = computed(() => props.data.steps.reduce((count, step) => count + step.needs.length, 0))
|
|
71
|
+
|
|
72
|
+
/* -------------------------------------------------------------------- send */
|
|
73
|
+
|
|
74
|
+
function stepLabel(key: string): string {
|
|
75
|
+
return fill(text.stepRef, { n: (stepIndex.get(key.split('.')[0]) ?? 0) + 1 })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function nameOf(key: string): string {
|
|
79
|
+
return key.startsWith('input:') ? key.slice(6) : key.split('.').slice(1).join('.')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function pathOf(step: JourneyStepData): { path: string, missing: Set<string> } {
|
|
83
|
+
const missing = new Set<string>()
|
|
84
|
+
const path = step.path.replaceAll(/\{([^}]+)\}/g, (whole, name: string) => {
|
|
85
|
+
const parameter = step.parameters.find(item => item.in === 'path' && item.name === name)
|
|
86
|
+
if (!parameter) {
|
|
87
|
+
return whole
|
|
88
|
+
}
|
|
89
|
+
const value = evaluate({ [EXPRESSION_KEY]: parameter.value }, values.value, missing)
|
|
90
|
+
return value === undefined ? whole : encodeURIComponent(String(value))
|
|
91
|
+
})
|
|
92
|
+
return { path, missing }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function errorOf(step: JourneyStepData, prefer: string[]): { status: string, body?: unknown } {
|
|
96
|
+
return step.errors.find(error => prefer.includes(error.status)) ?? step.errors[0] ?? { status: '4XX' }
|
|
97
|
+
}
|
|
16
98
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
99
|
+
function send(index: number): void {
|
|
100
|
+
const step = props.data.steps[index]
|
|
101
|
+
const { path, missing: pathMissing } = pathOf(step)
|
|
102
|
+
const missing = new Set(pathMissing)
|
|
103
|
+
for (const parameter of step.parameters.filter(item => item.in !== 'path')) {
|
|
104
|
+
evaluate({ [EXPRESSION_KEY]: parameter.value }, values.value, missing)
|
|
20
105
|
}
|
|
106
|
+
const body = step.body === undefined ? undefined : evaluate(step.body, values.value, missing)
|
|
107
|
+
log.value = [...log.value, { kind: 'request', text: `${step.method} ${path}` }]
|
|
108
|
+
notice.value = ''
|
|
109
|
+
|
|
110
|
+
let result: Result
|
|
111
|
+
if (missing.size) {
|
|
112
|
+
const keys = [...missing]
|
|
113
|
+
const error = errorOf(step, pathMissing.size ? ['404'] : ['422', '400'])
|
|
114
|
+
result = {
|
|
115
|
+
ok: false,
|
|
116
|
+
status: error.status,
|
|
117
|
+
path,
|
|
118
|
+
...(error.body !== undefined ? { body: error.body } : {}),
|
|
119
|
+
missing: keys,
|
|
120
|
+
problems: [fill(text.missing, { names: keys.map(nameOf).join(text.separator), steps: [...new Set(keys.filter(key => !key.startsWith('input:')).map(stepLabel))].join(text.separator) })],
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const problems = step.rule && body !== undefined ? validate(body, step.rule, props.data.messages) : []
|
|
125
|
+
if (problems.length) {
|
|
126
|
+
const error = errorOf(step, ['422', '400'])
|
|
127
|
+
result = { ok: false, status: error.status, path, ...(error.body !== undefined ? { body: error.body } : {}), missing: [], problems: [text.invalid, ...problems] }
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const response = mockResponse(step.response, body)
|
|
131
|
+
for (const output of step.outputs) {
|
|
132
|
+
outputs[output.key] = readPointer(response, output.pointer)
|
|
133
|
+
landed.value = output.key
|
|
134
|
+
}
|
|
135
|
+
result = { ok: true, status: step.status, path, ...(response !== undefined ? { body: response } : {}), missing: [], problems: [] }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
results[index] = result
|
|
139
|
+
log.value = [...log.value, { kind: result.ok ? 'response' : 'error', text: result.status }]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function clear(): void {
|
|
143
|
+
clearTimeout(timer)
|
|
144
|
+
running.value = false
|
|
145
|
+
for (const key of Object.keys(outputs)) {
|
|
146
|
+
delete outputs[key]
|
|
147
|
+
}
|
|
148
|
+
for (const key of Object.keys(results)) {
|
|
149
|
+
delete results[Number(key)]
|
|
150
|
+
}
|
|
151
|
+
log.value = []
|
|
152
|
+
landed.value = ''
|
|
153
|
+
notice.value = ''
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function runAll(): void {
|
|
157
|
+
clear()
|
|
21
158
|
const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
22
159
|
running.value = true
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (finished.value >= props.data.steps.length) {
|
|
160
|
+
const step = (index: number): void => {
|
|
161
|
+
if (index >= props.data.steps.length) {
|
|
26
162
|
running.value = false
|
|
27
163
|
return
|
|
28
164
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
165
|
+
send(index)
|
|
166
|
+
if (!results[index]?.ok) {
|
|
167
|
+
running.value = false
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
timer = setTimeout(step, reduced ? 0 : 450, index + 1)
|
|
33
171
|
}
|
|
34
|
-
|
|
172
|
+
step(0)
|
|
35
173
|
}
|
|
36
174
|
|
|
37
|
-
|
|
175
|
+
function editInput(name: string, value: string): void {
|
|
176
|
+
inputText[name] = value
|
|
177
|
+
if (log.value.length) {
|
|
178
|
+
clear()
|
|
179
|
+
notice.value = text.inputsChanged
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* ----------------------------------------------------------------- display */
|
|
184
|
+
|
|
185
|
+
function requestLines(step: JourneyStepData): Line[] {
|
|
186
|
+
return templateLines(step.body, { values: values.value, marks: props.data.marks })
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function responseLines(step: JourneyStepData): Line[] {
|
|
190
|
+
const result = results[step.index]
|
|
191
|
+
if (!result || result.body === undefined) {
|
|
192
|
+
return []
|
|
193
|
+
}
|
|
194
|
+
const outlines = result.ok ? Object.fromEntries(step.outputs.map(output => [output.pointer, props.data.marks[output.key] ?? 0])) : {}
|
|
195
|
+
return valueLines(result.body, { values: values.value, marks: props.data.marks, outlines })
|
|
196
|
+
}
|
|
38
197
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
198
|
+
/** The path split into text and parameter slots. */
|
|
199
|
+
function pathParts(step: JourneyStepData): { text: string, slot?: ReturnType<typeof resolve> }[] {
|
|
200
|
+
return step.path.split(/(\{[^}]+\})/).filter(Boolean).map((part) => {
|
|
201
|
+
const parameter = part.startsWith('{') ? step.parameters.find(item => item.in === 'path' && item.name === part.slice(1, -1)) : undefined
|
|
202
|
+
return parameter ? { text: part, slot: resolve(parameter.value, values.value) } : { text: part }
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function otherParameters(step: JourneyStepData): { name: string, in: string, slot: ReturnType<typeof resolve> }[] {
|
|
207
|
+
return step.parameters.filter(item => item.in !== 'path').map(item => ({ name: item.name, in: item.in, slot: resolve(item.value, values.value) }))
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function tokenClass(token: Line[number]): string[] {
|
|
211
|
+
const classes = token.kind.split(' ').map(kind => `kawa-openapi-journey__t--${kind}`)
|
|
212
|
+
if (token.mark !== undefined) {
|
|
213
|
+
classes.push(`kawa-openapi-mark kawa-openapi-mark--${token.mark}`)
|
|
214
|
+
}
|
|
215
|
+
return classes
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function tokenTitle(token: Line[number]): string | undefined {
|
|
219
|
+
if (!token.slot) {
|
|
220
|
+
return undefined
|
|
221
|
+
}
|
|
222
|
+
return token.slot.startsWith('input:')
|
|
223
|
+
? fill(text.fromInput, { name: token.slot.slice(6) })
|
|
224
|
+
: fill(text.fromStep, { name: nameOf(token.slot), n: (stepIndex.get(token.slot.split('.')[0]) ?? 0) + 1 })
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function slotClass(slot: ReturnType<typeof resolve>): string[] {
|
|
228
|
+
if (slot.missing) {
|
|
229
|
+
return ['kawa-openapi-journey__t--missing']
|
|
230
|
+
}
|
|
231
|
+
if (slot.key.startsWith('input:')) {
|
|
232
|
+
return ['kawa-openapi-journey__t--input']
|
|
233
|
+
}
|
|
234
|
+
const mark = props.data.marks[slot.key]
|
|
235
|
+
return mark === undefined ? [] : ['kawa-openapi-journey__t--output', `kawa-openapi-mark kawa-openapi-mark--${mark}`]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function slotText(slot: ReturnType<typeof resolve>): string {
|
|
239
|
+
return slot.missing ? `${slot.name}: ${text.missingValue}` : typeof slot.value === 'string' ? slot.value : JSON.stringify(slot.value)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function slotTitle(slot: ReturnType<typeof resolve>): string | undefined {
|
|
243
|
+
if (!slot.key) {
|
|
244
|
+
return undefined
|
|
245
|
+
}
|
|
246
|
+
return slot.key.startsWith('input:') ? fill(text.fromInput, { name: slot.name }) : fill(text.fromStep, { name: slot.name, n: (stepIndex.get(slot.key.split('.')[0]) ?? 0) + 1 })
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function flows(step: JourneyStepData): { text: string, mark?: number }[] {
|
|
250
|
+
return step.needs.map(key => ({ text: fill(text.fromStep, { name: nameOf(key), n: (stepIndex.get(key.split('.')[0]) ?? 0) + 1 }), mark: props.data.marks[key] }))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function summaryOf(step: JourneyStepData): string {
|
|
254
|
+
const result = results[step.index]
|
|
255
|
+
if (!result) {
|
|
256
|
+
return ''
|
|
42
257
|
}
|
|
43
|
-
|
|
258
|
+
if (!result.ok) {
|
|
259
|
+
return result.status
|
|
260
|
+
}
|
|
261
|
+
const output = step.outputs[0]
|
|
262
|
+
return output ? `${output.name} = ${String(outputs[output.key])}` : result.status
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function isOpen(step: JourneyStepData): boolean {
|
|
266
|
+
return step.index === next.value || (results[step.index] !== undefined && !results[step.index].ok) || Boolean(opened[step.index])
|
|
44
267
|
}
|
|
45
268
|
|
|
46
|
-
|
|
47
|
-
|
|
269
|
+
/* -------------------------------------------------------------------- code */
|
|
270
|
+
|
|
271
|
+
const code = computed(() => {
|
|
272
|
+
const steps: CodeStep[] = props.data.steps.map(step => ({
|
|
273
|
+
id: step.id,
|
|
274
|
+
method: step.method,
|
|
275
|
+
path: step.path,
|
|
276
|
+
webhook: step.webhook,
|
|
277
|
+
auth: step.auth,
|
|
278
|
+
parameters: step.parameters.map(parameter => ({ name: parameter.name, in: parameter.in, value: parameter.value as JourneyExpression })),
|
|
279
|
+
...(step.body !== undefined ? { body: step.body } : {}),
|
|
280
|
+
outputs: step.outputs,
|
|
281
|
+
}))
|
|
282
|
+
const inputs = props.data.inputs.map(input => ({ name: input.name, value: inputValue(input.name) }))
|
|
283
|
+
const comment = (step: CodeStep, index: number): string => step.webhook
|
|
284
|
+
? fill(text.waitWebhook, { name: step.path })
|
|
285
|
+
: fill(text.step, { n: index + 1, title: props.data.steps[index].title })
|
|
286
|
+
return language.value === 'curl'
|
|
287
|
+
? curlScript(props.data.base, inputs, steps, comment)
|
|
288
|
+
: javascriptScript(props.data.base, inputs, steps, comment)
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
async function copyCode(): Promise<void> {
|
|
292
|
+
try {
|
|
293
|
+
await navigator.clipboard.writeText(code.value)
|
|
294
|
+
copyState.value = 'copied'
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
copyState.value = 'failed'
|
|
298
|
+
}
|
|
299
|
+
timer = setTimeout(() => (copyState.value = 'idle'), 1600)
|
|
48
300
|
}
|
|
49
301
|
</script>
|
|
50
302
|
|
|
@@ -54,47 +306,154 @@ function markClass(mark: number): string {
|
|
|
54
306
|
</div>
|
|
55
307
|
<div v-else class="kawa-openapi-journey">
|
|
56
308
|
<div class="kawa-openapi-journey__toolbar">
|
|
57
|
-
<button type="button" class="kawa-openapi-button kawa-openapi-button--primary" :disabled="running" @click="
|
|
58
|
-
{{
|
|
309
|
+
<button type="button" class="kawa-openapi-button kawa-openapi-button--primary" :disabled="next < 0 || running" @click="send(next)">
|
|
310
|
+
{{ next < 0 ? text.allDone : fill(text.sendStep, { n: next + 1 }) }}
|
|
311
|
+
</button>
|
|
312
|
+
<button type="button" class="kawa-openapi-button" :disabled="running" @click="runAll">
|
|
313
|
+
{{ text.runAll }}
|
|
314
|
+
</button>
|
|
315
|
+
<button type="button" class="kawa-openapi-button" :disabled="!log.length" @click="clear">
|
|
316
|
+
{{ text.reset }}
|
|
59
317
|
</button>
|
|
318
|
+
<span class="kawa-openapi-journey__spacer" />
|
|
319
|
+
<span class="kawa-openapi-journey__progress" aria-live="polite">{{ notice || fill(text.progress, { n: doneCount, total: data.steps.length }) }}</span>
|
|
60
320
|
</div>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<div class="kawa-openapi-
|
|
321
|
+
|
|
322
|
+
<div class="kawa-openapi-journey__console">
|
|
323
|
+
<aside class="kawa-openapi-journey__side">
|
|
324
|
+
<div class="kawa-openapi-journey__panel">
|
|
325
|
+
<div class="kawa-openapi-journey__panel-title">
|
|
326
|
+
{{ text.values }}
|
|
327
|
+
</div>
|
|
328
|
+
<label v-for="input in data.inputs" :key="input.name" class="kawa-openapi-journey__value is-input">
|
|
329
|
+
<span class="kawa-openapi-journey__value-name">{{ input.name }} <small>{{ text.input }}</small></span>
|
|
330
|
+
<input :value="inputText[input.name]" type="text" spellcheck="false" :title="input.description || undefined" @input="editInput(input.name, ($event.target as HTMLInputElement).value)">
|
|
331
|
+
</label>
|
|
332
|
+
<div
|
|
333
|
+
v-for="output in outputList"
|
|
334
|
+
:key="output.key"
|
|
335
|
+
class="kawa-openapi-journey__value"
|
|
336
|
+
:class="[outputs[output.key] === undefined ? 'is-empty' : `kawa-openapi-mark kawa-openapi-mark--${data.marks[output.key] ?? 0}`, landed === output.key ? 'is-landed' : '']"
|
|
337
|
+
>
|
|
338
|
+
<span class="kawa-openapi-journey__value-name">{{ output.name }}</span>
|
|
339
|
+
<span v-if="outputs[output.key] !== undefined" class="kawa-openapi-journey__value-text">{{ typeof outputs[output.key] === 'string' ? outputs[output.key] : JSON.stringify(outputs[output.key]) }}</span>
|
|
340
|
+
<span v-else class="kawa-openapi-journey__value-wait">{{ fill(text.waiting, { n: output.step + 1 }) }}</span>
|
|
341
|
+
<small>{{ fill(text.fromResponse, { n: output.step + 1, pointer: `body${output.pointer.replaceAll('/', '.')}` }) }}</small>
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
</aside>
|
|
345
|
+
|
|
346
|
+
<ol class="kawa-openapi-journey__steps">
|
|
347
|
+
<li
|
|
348
|
+
v-for="step in data.steps"
|
|
349
|
+
:key="step.id"
|
|
350
|
+
class="kawa-openapi-journey__step"
|
|
351
|
+
:class="{ 'is-current': step.index === next, 'is-done': results[step.index]?.ok, 'is-failed': results[step.index] && !results[step.index].ok }"
|
|
352
|
+
>
|
|
65
353
|
<div class="kawa-openapi-journey__head">
|
|
354
|
+
<span class="kawa-openapi-journey__dot" aria-hidden="true">{{ results[step.index]?.ok ? '✓' : step.index + 1 }}</span>
|
|
66
355
|
<span :class="`kawa-openapi-method kawa-openapi-method--${step.method.toLowerCase()}`">{{ step.method }}</span>
|
|
67
|
-
<
|
|
356
|
+
<span class="kawa-openapi-journey__path">{{ step.path }}</span>
|
|
68
357
|
<a :href="step.href" class="kawa-openapi-journey__title">{{ step.title }}</a>
|
|
69
|
-
<span class="kawa-openapi-
|
|
70
|
-
<span class="kawa-openapi-journey__state">
|
|
71
|
-
{{ stateOf(step.index) === 'done' ? `${step.status} · ${data.text.done}` : stateOf(step.index) === 'running' ? data.text.running : stateOf(step.index) === 'pending' ? data.text.pending : '' }}
|
|
72
|
-
</span>
|
|
73
|
-
</div>
|
|
74
|
-
<div v-if="step.descriptionHtml" class="kawa-openapi-journey__description" v-html="step.descriptionHtml" />
|
|
75
|
-
<div v-if="step.flows.length" class="kawa-openapi-journey__flows">
|
|
76
|
-
<span v-for="flow in step.flows" :key="flow.text" :class="markClass(flow.mark)">{{ flow.text }}</span>
|
|
358
|
+
<span class="kawa-openapi-journey__summary">{{ summaryOf(step) }}</span>
|
|
77
359
|
</div>
|
|
78
|
-
<div v-if="step
|
|
79
|
-
<
|
|
80
|
-
<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
<div
|
|
84
|
-
<div class="kawa-openapi-
|
|
85
|
-
|
|
360
|
+
<div v-if="isOpen(step)" class="kawa-openapi-journey__body">
|
|
361
|
+
<div v-if="step.descriptionHtml" class="kawa-openapi-journey__description" v-html="step.descriptionHtml" />
|
|
362
|
+
<div v-if="step.needs.length" class="kawa-openapi-journey__flows">
|
|
363
|
+
<span v-for="flow in flows(step)" :key="flow.text" :class="flow.mark !== undefined ? `kawa-openapi-mark kawa-openapi-mark--${flow.mark}` : ''">← {{ flow.text }}</span>
|
|
364
|
+
</div>
|
|
365
|
+
<div class="kawa-openapi-journey__io">
|
|
366
|
+
<div class="kawa-openapi-journey__box">
|
|
367
|
+
<div class="kawa-openapi-journey__box-title">
|
|
368
|
+
{{ step.webhook ? data.text.receive : text.request }}
|
|
369
|
+
</div>
|
|
370
|
+
<pre><code><span :class="`kawa-openapi-method kawa-openapi-method--${step.method.toLowerCase()}`">{{ step.method }}</span> <template v-for="(part, position) in pathParts(step)" :key="position"><span v-if="part.slot" :class="slotClass(part.slot)" :title="slotTitle(part.slot)">{{ slotText(part.slot) }}</span><template v-else>{{ part.text }}</template></template><template v-for="parameter in otherParameters(step)" :key="parameter.name">{{ `\n${parameter.in === 'query' ? '?' : ''}${parameter.name}${parameter.in === 'query' ? '=' : ': '}` }}<span :class="slotClass(parameter.slot)" :title="slotTitle(parameter.slot)">{{ slotText(parameter.slot) }}</span></template>{{ '\n\n' }}<template v-if="step.body !== undefined"><template v-for="(line, row) in requestLines(step)" :key="row"><span v-for="(token, column) in line" :key="column" :class="tokenClass(token)" :title="tokenTitle(token)">{{ token.kind === 'missing' ? `${token.text}: ${text.missingValue}` : token.text }}</span>{{ '\n' }}</template></template><span v-else class="kawa-openapi-journey__t--note">{{ text.noBody }}</span></code></pre>
|
|
371
|
+
</div>
|
|
372
|
+
<div class="kawa-openapi-journey__box">
|
|
373
|
+
<div class="kawa-openapi-journey__box-title">
|
|
374
|
+
{{ text.response }}<template v-if="!results[step.index]">
|
|
375
|
+
· {{ text.notSent }}
|
|
376
|
+
</template>
|
|
377
|
+
</div>
|
|
378
|
+
<pre v-if="results[step.index]"><code><span :class="results[step.index].ok ? 'kawa-openapi-journey__t--ok' : 'kawa-openapi-journey__t--error'">{{ results[step.index].status }}</span>{{ '\n\n' }}<template v-if="results[step.index].body !== undefined"><template v-for="(line, row) in responseLines(step)" :key="row"><span v-for="(token, column) in line" :key="column" :class="tokenClass(token)">{{ token.text }}</span>{{ '\n' }}</template></template><span v-else class="kawa-openapi-journey__t--note">{{ results[step.index].ok ? text.noResponse : text.noExample }}</span></code></pre>
|
|
86
379
|
</div>
|
|
87
|
-
<KawaOpenApiPayload :payload="step.request" />
|
|
88
380
|
</div>
|
|
89
|
-
<div v-if="step.
|
|
90
|
-
<div
|
|
91
|
-
{{
|
|
381
|
+
<div v-if="results[step.index] && !results[step.index].ok" class="kawa-openapi-journey__problem" role="alert">
|
|
382
|
+
<div v-for="problem in results[step.index].problems" :key="problem">
|
|
383
|
+
{{ problem }}
|
|
92
384
|
</div>
|
|
93
|
-
<KawaOpenApiPayload :payload="step.response" />
|
|
94
385
|
</div>
|
|
386
|
+
<div class="kawa-openapi-journey__actions">
|
|
387
|
+
<button
|
|
388
|
+
type="button"
|
|
389
|
+
class="kawa-openapi-button"
|
|
390
|
+
:class="{ 'kawa-openapi-button--primary': step.index === next, 'kawa-openapi-button--ghost': step.index > next && next >= 0 }"
|
|
391
|
+
:disabled="running"
|
|
392
|
+
@click="send(step.index)"
|
|
393
|
+
>
|
|
394
|
+
{{ results[step.index]?.ok ? text.sendAgain : step.index > next && next >= 0 ? text.tryAhead : step.webhook ? text.receive : text.sendThis }}
|
|
395
|
+
</button>
|
|
396
|
+
<button v-if="opened[step.index]" type="button" class="kawa-openapi-button kawa-openapi-button--ghost" @click="opened[step.index] = false">
|
|
397
|
+
{{ text.hide }}
|
|
398
|
+
</button>
|
|
399
|
+
</div>
|
|
400
|
+
</div>
|
|
401
|
+
<div v-else class="kawa-openapi-journey__closed">
|
|
402
|
+
<template v-if="results[step.index]?.ok">
|
|
403
|
+
<button type="button" class="kawa-openapi-button kawa-openapi-button--ghost" @click="opened[step.index] = true">
|
|
404
|
+
{{ text.show }}
|
|
405
|
+
</button>
|
|
406
|
+
</template>
|
|
407
|
+
<template v-else>
|
|
408
|
+
{{ text.waitEarlier }}
|
|
409
|
+
<button type="button" class="kawa-openapi-button kawa-openapi-button--ghost" @click="opened[step.index] = true">
|
|
410
|
+
{{ text.openEarly }}
|
|
411
|
+
</button>
|
|
412
|
+
</template>
|
|
413
|
+
</div>
|
|
414
|
+
</li>
|
|
415
|
+
</ol>
|
|
416
|
+
</div>
|
|
417
|
+
|
|
418
|
+
<div class="kawa-openapi-journey__panel kawa-openapi-journey__calls">
|
|
419
|
+
<div class="kawa-openapi-journey__panel-title">
|
|
420
|
+
{{ text.calls }}
|
|
421
|
+
</div>
|
|
422
|
+
<div class="kawa-openapi-journey__log">
|
|
423
|
+
<span class="kawa-openapi-journey__lane">{{ text.client }}</span>
|
|
424
|
+
<span class="kawa-openapi-journey__lane">{{ text.server }}</span>
|
|
425
|
+
<template v-if="log.length">
|
|
426
|
+
<div v-for="(entry, position) in log" :key="position" class="kawa-openapi-journey__call" :class="`is-${entry.kind}`">
|
|
427
|
+
<span>{{ entry.text }}</span>
|
|
95
428
|
</div>
|
|
429
|
+
</template>
|
|
430
|
+
<div v-else class="kawa-openapi-journey__no-calls">
|
|
431
|
+
{{ text.noCalls }}
|
|
432
|
+
</div>
|
|
433
|
+
</div>
|
|
434
|
+
</div>
|
|
435
|
+
|
|
436
|
+
<div v-if="next < 0" class="kawa-openapi-journey__finish">
|
|
437
|
+
<div class="kawa-openapi-journey__finish-head">
|
|
438
|
+
<strong>{{ text.finished }}</strong>
|
|
439
|
+
<span>{{ fill(text.summary, { calls: data.steps.length, values: passed }) }}</span>
|
|
440
|
+
</div>
|
|
441
|
+
<div class="kawa-openapi-journey__code-bar">
|
|
442
|
+
<span>{{ text.code }}</span>
|
|
443
|
+
<span class="kawa-openapi-journey__spacer" />
|
|
444
|
+
<div class="kawa-openapi-segmented" role="group">
|
|
445
|
+
<button type="button" :aria-pressed="language === 'curl'" @click="language = 'curl'">
|
|
446
|
+
curl
|
|
447
|
+
</button>
|
|
448
|
+
<button type="button" :aria-pressed="language === 'javascript'" @click="language = 'javascript'">
|
|
449
|
+
JavaScript
|
|
450
|
+
</button>
|
|
96
451
|
</div>
|
|
97
|
-
|
|
98
|
-
|
|
452
|
+
<button type="button" class="kawa-openapi-button" @click="copyCode">
|
|
453
|
+
{{ copyState === 'copied' ? text.copied : copyState === 'failed' ? text.copyFailed : text.copy }}
|
|
454
|
+
</button>
|
|
455
|
+
</div>
|
|
456
|
+
<pre class="kawa-openapi-journey__code"><code>{{ code }}</code></pre>
|
|
457
|
+
</div>
|
|
99
458
|
</div>
|
|
100
459
|
</template>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { MapData } from '../data/components'
|
|
3
|
+
import KawaOpenApiPath from './KawaOpenApiPath.vue'
|
|
3
4
|
|
|
4
5
|
defineProps<{
|
|
5
6
|
data: MapData
|
|
@@ -38,7 +39,7 @@ const isSsgMarkdown = import.meta.env.SSG_MD
|
|
|
38
39
|
:title="cell.title"
|
|
39
40
|
>
|
|
40
41
|
<span :class="`kawa-openapi-method kawa-openapi-method--${cell.method.toLowerCase()}`">{{ cell.method }}</span>
|
|
41
|
-
<span class="kawa-openapi-map__path"
|
|
42
|
+
<span class="kawa-openapi-map__path"><KawaOpenApiPath :path="cell.path" /></span>
|
|
42
43
|
<span v-if="cell.since" class="kawa-openapi-badge kawa-openapi-badge--new">{{ data.text.since.replace('{n}', cell.since) }}</span>
|
|
43
44
|
</a>
|
|
44
45
|
<span v-if="row.cells[column.action].length === 0" class="kawa-openapi-map__gap">—</span>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
path: string
|
|
6
|
+
}>()
|
|
7
|
+
|
|
8
|
+
/** `/orders/{orderId}` → `/orders`, `/{orderId}`: a narrow column wraps before a slash, never inside a segment. */
|
|
9
|
+
const segments = computed(() => props.path.split(/(?=\/)/))
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<template v-for="(segment, index) in segments" :key="index">
|
|
14
|
+
<wbr v-if="index > 0">{{ segment }}
|
|
15
|
+
</template>
|
|
16
|
+
</template>
|