From c7be4d581975aa85e3e516514fa799a8c8df2334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 14 Nov 2023 16:59:05 +0000 Subject: [PATCH] feat: OS Proxy docs (#2421) --- .../ordnanceSurvey/controller.ts} | 2 +- api.planx.uk/modules/ordnanceSurvey/docs.yaml | 62 +++++++++++++++++++ .../ordnanceSurvey}/ordnanceSurvey.test.ts | 4 +- api.planx.uk/modules/ordnanceSurvey/routes.ts | 8 +++ api.planx.uk/pay/proxy.ts | 2 +- api.planx.uk/server.ts | 5 +- .../index.ts => shared/middleware/proxy.ts} | 0 7 files changed, 76 insertions(+), 7 deletions(-) rename api.planx.uk/{proxy/ordnanceSurvey.ts => modules/ordnanceSurvey/controller.ts} (96%) create mode 100644 api.planx.uk/modules/ordnanceSurvey/docs.yaml rename api.planx.uk/{proxy => modules/ordnanceSurvey}/ordnanceSurvey.test.ts (98%) create mode 100644 api.planx.uk/modules/ordnanceSurvey/routes.ts rename api.planx.uk/{proxy/index.ts => shared/middleware/proxy.ts} (100%) diff --git a/api.planx.uk/proxy/ordnanceSurvey.ts b/api.planx.uk/modules/ordnanceSurvey/controller.ts similarity index 96% rename from api.planx.uk/proxy/ordnanceSurvey.ts rename to api.planx.uk/modules/ordnanceSurvey/controller.ts index ee9dd7a724..d950eb36ab 100644 --- a/api.planx.uk/proxy/ordnanceSurvey.ts +++ b/api.planx.uk/modules/ordnanceSurvey/controller.ts @@ -1,4 +1,4 @@ -import { useProxy } from "./index"; +import { useProxy } from "../../shared/middleware/proxy"; import { NextFunction, Request, Response } from "express"; import { IncomingMessage } from "http"; diff --git a/api.planx.uk/modules/ordnanceSurvey/docs.yaml b/api.planx.uk/modules/ordnanceSurvey/docs.yaml new file mode 100644 index 0000000000..b471079326 --- /dev/null +++ b/api.planx.uk/modules/ordnanceSurvey/docs.yaml @@ -0,0 +1,62 @@ +openapi: 3.1.0 +info: + title: Planâś• API + version: 0.1.0 +tags: + - name: ordnance survey + description: Proxy authenticated requests to the OS Data Hub APIs + externalDocs: + url: https://osdatahub.os.uk/docs +components: + schemas: + AnyParams: + description: Any query parameters accepted by OS Data Hub APIs + name: queryParams + in: query + schema: + type: object + example: + key1: value1 + key2: value2 + AnyBody: + description: Any JSON body accepted by OS Data Hub APIs + required: false + content: + application/json: + schema: + type: object + example: + key1: value1 + key2: value2 +paths: + /proxy/ordnance-survey: + get: + tags: [ordnance survey] + parameters: + - $ref: "#/components/schemas/AnyParams" + requestBody: + $ref: "#/components/schemas/AnyBody" + put: + tags: [ordnance survey] + parameters: + - $ref: "#/components/schemas/AnyParams" + requestBody: + $ref: "#/components/schemas/AnyBody" + post: + tags: [ordnance survey] + parameters: + - $ref: "#/components/schemas/AnyParams" + requestBody: + $ref: "#/components/schemas/AnyBody" + delete: + tags: [ordnance survey] + parameters: + - $ref: "#/components/schemas/AnyParams" + requestBody: + $ref: "#/components/schemas/AnyBody" + patch: + tags: [ordnance survey] + parameters: + - $ref: "#/components/schemas/AnyParams" + requestBody: + $ref: "#/components/schemas/AnyBody" diff --git a/api.planx.uk/proxy/ordnanceSurvey.test.ts b/api.planx.uk/modules/ordnanceSurvey/ordnanceSurvey.test.ts similarity index 98% rename from api.planx.uk/proxy/ordnanceSurvey.test.ts rename to api.planx.uk/modules/ordnanceSurvey/ordnanceSurvey.test.ts index ea42ad3a1b..eebd817e33 100644 --- a/api.planx.uk/proxy/ordnanceSurvey.test.ts +++ b/api.planx.uk/modules/ordnanceSurvey/ordnanceSurvey.test.ts @@ -1,8 +1,8 @@ import { Request } from "express"; import nock from "nock"; import supertest from "supertest"; -import app from "../server"; -import { appendAPIKey, OS_DOMAIN } from "./ordnanceSurvey"; +import app from "../../server"; +import { appendAPIKey, OS_DOMAIN } from "./controller"; const { get } = supertest(app); diff --git a/api.planx.uk/modules/ordnanceSurvey/routes.ts b/api.planx.uk/modules/ordnanceSurvey/routes.ts new file mode 100644 index 0000000000..b8f5204c94 --- /dev/null +++ b/api.planx.uk/modules/ordnanceSurvey/routes.ts @@ -0,0 +1,8 @@ +import { Router } from "express"; +import { useOrdnanceSurveyProxy } from "./controller"; + +const router = Router(); + +router.use("/proxy/ordnance-survey", useOrdnanceSurveyProxy); + +export default router; diff --git a/api.planx.uk/pay/proxy.ts b/api.planx.uk/pay/proxy.ts index b9a70606e5..e946101872 100644 --- a/api.planx.uk/pay/proxy.ts +++ b/api.planx.uk/pay/proxy.ts @@ -1,6 +1,6 @@ import { Request } from "express"; import { fixRequestBody, Options } from "http-proxy-middleware"; -import { useProxy } from "../proxy"; +import { useProxy } from "../shared/middleware/proxy"; export const usePayProxy = (options: Partial, req: Request) => { return useProxy({ diff --git a/api.planx.uk/server.ts b/api.planx.uk/server.ts index 88e608363a..859ee1aa70 100644 --- a/api.planx.uk/server.ts +++ b/api.planx.uk/server.ts @@ -53,7 +53,6 @@ import { downloadApplicationFiles, sendToEmail } from "./send/email"; import { sendToUniform } from "./send/uniform"; import { copyFlow } from "./editor/copyFlow"; import { moveFlow } from "./editor/moveFlow"; -import { useOrdnanceSurveyProxy } from "./proxy/ordnanceSurvey"; import { gql } from "graphql-request"; import { classifiedRoadsSearch } from "./gis/classifiedRoads"; import { googleStrategy } from "./modules/auth/strategy/google"; @@ -64,6 +63,7 @@ import userRoutes from "./modules/user/routes"; import webhookRoutes from "./modules/webhooks/routes"; import analyticsRoutes from "./modules/analytics/routes"; import adminRoutes from "./modules/admin/routes"; +import ordnanceSurveyRoutes from "./modules/ordnanceSurvey/routes"; import { useSwaggerDocs } from "./docs"; import { Role } from "@opensystemslab/planx-core/types"; import { $public } from "./client"; @@ -184,6 +184,7 @@ app.use("/team", teamRoutes); app.use("/webhooks", webhookRoutes); app.use("/analytics", analyticsRoutes); app.use("/admin", adminRoutes); +app.use(ordnanceSurveyRoutes); app.use("/gis", router); @@ -358,8 +359,6 @@ app.post("/validate-session", validateSession); app.post("/invite-to-pay/:sessionId", inviteToPay); -app.use("/proxy/ordnance-survey", useOrdnanceSurveyProxy); - const errorHandler: ErrorRequestHandler = (errorObject, _req, res, _next) => { const { status = 500, message = "Something went wrong" } = (() => { if ( diff --git a/api.planx.uk/proxy/index.ts b/api.planx.uk/shared/middleware/proxy.ts similarity index 100% rename from api.planx.uk/proxy/index.ts rename to api.planx.uk/shared/middleware/proxy.ts