diff --git a/src/errors/validation.ts b/src/errors/validation.ts index 5304da8..3283524 100644 --- a/src/errors/validation.ts +++ b/src/errors/validation.ts @@ -1,7 +1,6 @@ export interface IFastifyValidationError { statusCode?: number; code?: string; - validation?: any; } export function getFastifyError(error: Error) { diff --git a/src/routes/raw-html.ts b/src/routes/raw-html.ts index 4665fe2..32ccfe5 100644 --- a/src/routes/raw-html.ts +++ b/src/routes/raw-html.ts @@ -1,7 +1,6 @@ import { FastifyInstance } from "fastify"; import { IParseSchema, rawHtmlSchema } from "../types/requests/api"; -import { GetRequest } from "../types/requests/browser"; import handlePage from "../handlers/main"; import { generateRequestUrl } from "../utils/generate"; @@ -10,7 +9,7 @@ export default async function rawHtml(fastify: FastifyInstance) { fastify.get( "/api/raw-html", { schema: rawHtmlSchema }, - async (request: GetRequest) => { + async (request) => { return ( await handlePage( request.query.url, diff --git a/src/types/requests/api.ts b/src/types/requests/api.ts index 9e13803..0472505 100644 --- a/src/types/requests/api.ts +++ b/src/types/requests/api.ts @@ -2,21 +2,13 @@ import { FastifySchema, FastifyRequest } from "fastify"; import { IApiError, errorResponseSchema } from "../../errors/api"; import { handlerSchema } from "../../handlers/handler.interface"; import { engineList } from "../../handlers/main"; +import { FromSchema } from "json-schema-to-ts"; export interface IApiResponse { data?: T; error?: IApiError; } -export interface IParseQuery { - url: string; - engine?: string; -} - -export interface IParseSchema { - Querystring: IParseQuery; -} - export const parseQuerySchema = { type: "object", required: ["url"], @@ -30,7 +22,7 @@ export const parseQuerySchema = { enum: [...engineList, ""], }, }, -}; +} as const; export const parseSchema: FastifySchema = { description: "Parse the page and get all data from the engine", @@ -52,6 +44,10 @@ export const parseSchema: FastifySchema = { produces: ["text/json"], }; +export interface IParseSchema { + Querystring: FromSchema; +} + export const rawHtmlSchema: FastifySchema = { description: "Parse the page and get raw HTML from the engine", querystring: parseQuerySchema, diff --git a/src/types/requests/browser.ts b/src/types/requests/browser.ts index df526d9..e9891ed 100644 --- a/src/types/requests/browser.ts +++ b/src/types/requests/browser.ts @@ -1,18 +1,9 @@ -import { FastifyRequest, FastifySchema } from "fastify"; +import { FastifySchema } from "fastify"; import { engineList } from "../../handlers/main"; - -export type GetRequest = FastifyRequest<{ - Querystring: IGetQuery; -}>; - -export interface IGetQuery { - url: string; - format?: string; - engine?: string; -} +import { FromSchema } from "json-schema-to-ts"; export interface IGetSchema { - Querystring: IGetQuery; + Querystring: IGetQuerySchema; } export const indexSchema = { @@ -38,7 +29,8 @@ export const getQuerySchema = { enum: [...engineList, ""], }, }, -}; +} as const; +export type IGetQuerySchema = FromSchema; export const GetSchema: FastifySchema = { description: "Get page",