Skip to content

Commit 6f8df0f

Browse files
committed
feat: save operation parameters in page URL
1 parent a56bc80 commit 6f8df0f

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

ui/dts/typed-router.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ declare module 'vue-router/auto-routes' {
1919
*/
2020
export interface RouteNamedMap {
2121
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
22+
'/dev': RouteRecordInfo<'/dev', '/dev', Record<never, never>, Record<never, never>>,
2223
}
2324
}

ui/src/components/layout/navigation-drawer-items.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'text-disabled font-italic': item.deprecated,
88
}"
99
rounded
10-
@click="$router.push({ query: { ...$route.query, operation: item.hash} })"
10+
@click="$router.push({ query: { ...$route.query, operation: item.hash, params: undefined } })"
1111
>
1212
<v-list-item-title class="text-wrap">
1313
{{ item.summary }}

ui/src/components/operation.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,23 @@ const { operation, pathItemParameters, serverUrl, method, path } = defineProps<{
192192
}>()
193193
194194
const { t } = useI18n()
195+
const route = useRoute()
196+
const router = useRouter()
195197
196-
const endpointQueryValues = ref<GenericEndpointQuery>({})
198+
// Init endpointQueryValues from URL query parameters if available
199+
const initialValues = (() => {
200+
const params = route.query.params as string | undefined
201+
if (params) {
202+
try {
203+
return JSON.parse(params)
204+
} catch (e) {
205+
console.error('Failed to parse params from URL:', e)
206+
}
207+
}
208+
return {}
209+
})()
210+
211+
const endpointQueryValues = ref<GenericEndpointQuery>(initialValues)
197212
const endpointQuerySchema = getVJSFSchema(operation, pathItemParameters)
198213
console.log(endpointQuerySchema)
199214
const responseData = ref<Record<string, any> | null>(null)
@@ -204,6 +219,16 @@ const exampleSelected = ref<string>('default')
204219
const loading = ref(false)
205220
const isValid = ref(false)
206221
222+
// Serialize the endpointQueryValues when they change
223+
watch(endpointQueryValues, (newValues) => {
224+
router.replace({
225+
query: {
226+
...route.query,
227+
params: JSON.stringify(newValues)
228+
}
229+
})
230+
}, { deep: true })
231+
207232
const fullPath = computed(() => {
208233
let fullPath = path
209234

ui/src/utils/serialize.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Parameter } from '~/utils/transform'
44
/**
55
* Serialize query parameters according to OpenAPI 3.0 specification
66
*
7-
* https://swagger.io/docs/specification/v3_0/serialization
87
* @param params - Object containing parameter name and values
98
* @param paramSpecs - Array of parameter specifications with style and explode properties
109
* @returns URLSearchParams object with properly serialized parameters

0 commit comments

Comments
 (0)