fix display manual request web service (swagger ui)

This commit is contained in:
Warunee Tamkoo 2025-08-08 11:07:33 +07:00
parent e50d9948df
commit 0c256b6cf6
3 changed files with 32 additions and 78 deletions

View file

@ -2,8 +2,10 @@ import env from "../index";
const apiKey = `${env.API_URI}/org/apiKey`;
const apiManage = `${env.API_URI}/org/api-manage/`;
const apiManualSwagger = `${env.API_URI}/org/api-manage/manual/swagger`;
export default {
apiKeyMain: apiKey,
apiManage: apiManage,
apiManualSwagger: apiManualSwagger,
};

View file

@ -10,19 +10,13 @@ function onCloseDialog() {
</script>
<template>
<q-dialog v-model="modal" persistent maximized>
<q-card style="max-width: 85vw; height: 85vh">
<q-card style="max-width: 85vw; height: 90vh">
<DialogHeader tittle="วิธีการใช้งาน" :close="onCloseDialog" />
<q-separator />
<q-card-section>
<q-card-section style="height: 80vh; overflow: auto">
<SwaggerViewer />
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn label="ปิด" color="secondary" @click.pervent="onCloseDialog()" />
</q-card-actions>
</q-card>
</q-dialog>
</template>

View file

@ -3,83 +3,34 @@
</template>
<script lang="ts" setup>
import { onMounted } from "vue";
import { onMounted, ref } from "vue";
import SwaggerUI from "swagger-ui";
import "swagger-ui/dist/swagger-ui.css";
// 🔁 URL Swagger JSON API
// const swaggerUrl: string = "https://petstore.swagger.io/v2/swagger.json";
import http from "@/plugins/http";
import config from "@/app.config";
onMounted(() => {
// URL Swagger JSON API
// const swaggerUrl: string = "https://petstore.swagger.io/v2/swagger.json";
const swaggerJson = ref();
async function fetchSwaggerJson() {
swaggerJson.value = await http
.get(`${config.API.apiManualSwagger}`)
.then((res) => {
return res.data.result;
})
.catch((error) => {
console.error("Error fetching Swagger JSON:", error);
return null; //
});
}
onMounted(async () => {
await fetchSwaggerJson();
SwaggerUI({
dom_id: "#swagger-ui",
// url: swaggerUrl,
spec: {
openapi: "3.0.0",
info: {
title: "API Web service",
version: "1.0.0",
description: "Example API for getting registry data",
},
servers: [
{
url: "https://api.example.com",
},
],
paths: {
"/registry": {
get: {
summary: "รายการข้อมูลทะเบียนประวัติข้าราชการ",
description: "แสดงข้อมูลข้าราชการทั้งหมด",
tags: ["ทะเบียนประวัติ"],
responses: {
"200": {
description: "รายการข้อมูลทะเบียนประวัติ",
content: {
"application/json": {
schema: {
type: "array",
items: {
$ref: "#/components/schemas/Registry",
},
},
example: [
{
id_card: "1234567890123",
firstname: "Developer",
lastname: "Lastname",
},
],
},
},
},
},
},
},
},
components: {
schemas: {
Registry: {
type: "object",
properties: {
id_card: {
type: "string",
example: "1234567890123",
},
firstname: {
type: "string",
example: "Developer",
},
lastname: {
type: "string",
example: "Lastname",
},
},
required: ["id_card", "firstname", "lastname"],
},
},
},
},
spec: swaggerJson.value,
});
});
</script>
@ -88,4 +39,11 @@ onMounted(() => {
.swagger-ui h2.title {
line-height: 1rem;
}
.swagger-ui .scheme-container {
margin: 0 0 0px;
padding: 0px 0px 20px;
}
.swagger-ui .scheme-container .schemes .auth-wrapper {
justify-content: end;
}
</style>