Commit 20eb9ce4 authored by Lê Bảo Hồng Đức's avatar Lê Bảo Hồng Đức

fix

parent 85518ad1
This diff is collapsed.
...@@ -40,23 +40,52 @@ const swaggerCandidates = [ ...@@ -40,23 +40,52 @@ const swaggerCandidates = [
async function fetchSwagger() { async function fetchSwagger() {
for (const url of swaggerCandidates) { for (const url of swaggerCandidates) {
if (typeof url === "string" && fs.existsSync(url)) { if (!url) continue;
return JSON.parse(fs.readFileSync(url, "utf8"));
// 1) Local file path
if (fs.existsSync(url) && fs.statSync(url).isFile()) {
const raw = fs.readFileSync(url, "utf8");
try {
return JSON.parse(raw);
} catch (error) {
throw new Error(`Swagger spec tại ${url} không phải JSON hợp lệ: ${error}`);
}
} }
try { // 2) HTTP fetch — chỉ chấp nhận JSON, bỏ qua HTML (404, page app,...)
const { data } = await axios.get(url, { if (/^https?:\/\//i.test(url)) {
headers: { Origin: siteURL }, try {
}); const { data, headers } = await axios.get(url, {
return data; headers: { Origin: siteURL },
} catch { // Ngăn axios tự nhận HTML là JSON — ép raw response để check Content-Type
continue; responseType: "json",
validateStatus: (status) => status >= 200 && status < 400,
});
const contentType = String(headers?.["content-type"] ?? "").toLowerCase();
if (!contentType.includes("application/json") && typeof data === "string") {
// Phản hồi không phải JSON (thường là HTML 404) — bỏ qua candidate này
continue;
}
if (data && typeof data === "object") {
return data;
}
} catch {
continue;
}
} }
} }
// 3) Fallback cuối: openapi/swagger-output.json nằm trong repo
const localSwagger = path.resolve(process.cwd(), "openapi/swagger-output.json"); const localSwagger = path.resolve(process.cwd(), "openapi/swagger-output.json");
if (fs.existsSync(localSwagger)) { if (fs.existsSync(localSwagger)) {
return JSON.parse(fs.readFileSync(localSwagger, "utf8")); const raw = fs.readFileSync(localSwagger, "utf8");
try {
return JSON.parse(raw);
} catch (error) {
throw new Error(`Swagger spec tại ${localSwagger} không phải JSON hợp lệ: ${error}`);
}
} }
throw new Error( throw new Error(
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/** /**
* Generated by orval v8.0.0-rc.0 🍺 * Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually. * Do not edit manually.
* Backend Template * VietProDev CMS Backend API
* Coded by Meu TEAM * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
import type { BadRequestResponseError } from './badRequestResponseError'; import type { BadRequestResponseError } from './badRequestResponseError';
......
/** /**
* Generated by orval v8.0.0-rc.0 🍺 * Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually. * Do not edit manually.
* Backend Template * VietProDev CMS Backend API
* Coded by Meu TEAM * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
import type { BadRequestResponseErrorMessage } from './badRequestResponseErrorMessage'; import type { BadRequestResponseErrorMessage } from './badRequestResponseErrorMessage';
......
/** /**
* Generated by orval v8.0.0-rc.0 🍺 * Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually. * Do not edit manually.
* Backend Template * VietProDev CMS Backend API
* Coded by Meu TEAM * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
......
/** /**
* Generated by orval v8.0.0-rc.0 🍺 * Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually. * Do not edit manually.
* Backend Template * VietProDev CMS Backend API
* Coded by Meu TEAM * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
......
/** /**
* Generated by orval v8.0.0-rc.0 🍺 * Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually. * Do not edit manually.
* Backend Template * VietProDev CMS Backend API
* Coded by Meu TEAM * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
......
...@@ -5,16 +5,21 @@ ...@@ -5,16 +5,21 @@
* Generated API documentation * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
import type { BannerStatus } from './bannerStatus';
export interface Banner { export interface Banner {
id?: string; id: string;
banner_name?: string; /** @maxLength 255 */
display_order?: number; banner_name: string;
status?: string; display_order: number;
file_id?: string; /** @minimum 1 */
created_at?: string;
created_by?: string;
updated_at?: string;
updated_by?: string;
display_time?: number; display_time?: number;
status: BannerStatus;
file_id: string;
created_at: string;
/** @nullable */
created_by?: string | null;
updated_at: string;
/** @nullable */
updated_by?: string | null;
} }
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* OpenAPI spec version: 1.0.0
*/
import type { BannerCreateStatus } from './bannerCreateStatus';
export interface BannerCreate {
/** @maxLength 255 */
banner_name: string;
display_order?: number;
/** @minimum 1 */
display_time?: number;
status?: BannerCreateStatus;
file_id: string;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* OpenAPI spec version: 1.0.0
*/
export type BannerCreateStatus = typeof BannerCreateStatus[keyof typeof BannerCreateStatus];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const BannerCreateStatus = {
ACTIVE: 'ACTIVE',
INACTIVE: 'INACTIVE',
} as const;
...@@ -5,11 +5,6 @@ ...@@ -5,11 +5,6 @@
* Generated API documentation * Generated API documentation
* OpenAPI spec version: 1.0.0 * OpenAPI spec version: 1.0.0
*/ */
import type { BannerCreate } from './bannerCreate';
export interface BannerMutate { export type BannerMutate = BannerCreate;
banner_name?: string;
display_order?: number;
status?: string;
file_id?: string;
display_time?: number;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* OpenAPI spec version: 1.0.0
*/
export type BannerStatus = typeof BannerStatus[keyof typeof BannerStatus];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const BannerStatus = {
ACTIVE: 'ACTIVE',
INACTIVE: 'INACTIVE',
} as const;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* OpenAPI spec version: 1.0.0
*/
import type { BannerUpdateStatus } from './bannerUpdateStatus';
export interface BannerUpdate {
/** @maxLength 255 */
banner_name?: string;
display_order?: number;
/** @minimum 1 */
display_time?: number;
status?: BannerUpdateStatus;
file_id?: string;
}
This diff is collapsed.
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { DeleteApiV10BannerId200AllOf } from './deleteApiV10BannerId200AllOf';
export type DeleteApiV10BannerId200 = ApiResponse & DeleteApiV10BannerId200AllOf;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment