Skip to content

Commit 2b1a517

Browse files
committed
Revert "Use fixed DON tools package for circular OAS dereference [deploy-test]"
This reverts commit f602d1f.
1 parent f602d1f commit 2b1a517

6 files changed

Lines changed: 27 additions & 82 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ HTTP API voor de tools op `developer.overheid.nl`.
44

55
Deze repository bevat de API-laag voor versie 1 van de Tools API: routing, OpenAPI-validatie,
66
response headers, foutafhandeling en de koppeling naar de daadwerkelijke businesslogica. Die
7-
businesslogica staat in `@developer-overheid-nl/don-tools` en wordt los beheerd in `don-tools`.
7+
businesslogica staat in `@developer-overheid-nl/don-tools-logic` en wordt los beheerd in
8+
`don-tools-api-v2`.
89

910
## Wat zit hierin?
1011

@@ -71,15 +72,15 @@ Mock mode kan ook direct via:
7172
npm run dev-mock
7273
```
7374

74-
## Relatie met `don-tools`
75+
## Relatie met `don-tools-api-v2`
7576

7677
`don-tools-api` is de v1 HTTP-adapter. De herbruikbare logica zit in
77-
`@developer-overheid-nl/don-tools`.
78+
`@developer-overheid-nl/don-tools-logic`.
7879

7980
Zodra de logic package op npm gepubliceerd is, pin deze API op een expliciete packageversie:
8081

8182
```sh
82-
npm install @developer-overheid-nl/don-tools@<version>
83+
npm install @developer-overheid-nl/don-tools-logic@<version>
8384
```
8485

8586
Gebruik liever een npm-versie dan een GitHub dependency in CI/CD. Dat voorkomt dat builds afhankelijk
@@ -119,7 +120,7 @@ api/ OpenAPI contract en gegenereerde API interfaces
119120
app/ NestJS/Fastify bootstrap en OpenAPI middleware
120121
controllers/ Gegenereerde NestJS controllers
121122
decorators/ Gegenereerde request decorators
122-
implementation/ Handgeschreven adapter naar don-tools
123+
implementation/ Handgeschreven adapter naar don-tools-logic
123124
models/ Gegenereerde request/response modellen
124125
test/ Vitest tests
125126
```
Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { HttpException, Injectable } from "@nestjs/common";
1+
import { BadRequestException, Injectable } from "@nestjs/common";
22
import type { FastifyReply } from "fastify";
3-
import type { OasInput, UntrustedClientInput, ValidateInput } from "@developer-overheid-nl/don-tools";
3+
import type { OasInput, UntrustedClientInput, ValidateInput } from "@developer-overheid-nl/don-tools-logic";
44
import { ToolsApi } from "../api";
55
import type { ModelsKeycloakClientResult, ModelsLintResult } from "../models";
66

@@ -10,31 +10,15 @@ const setHeaders = (reply: FastifyReply, headers: Record<string, string>) => {
1010

1111
const importEsm = new Function("specifier", "return import(specifier)") as <T>(specifier: string) => Promise<T>;
1212
const loadLogic = () =>
13-
import("@developer-overheid-nl/don-tools").catch(() =>
14-
importEsm<typeof import("@developer-overheid-nl/don-tools")>("@developer-overheid-nl/don-tools"),
13+
import("@developer-overheid-nl/don-tools-logic").catch(() =>
14+
importEsm<typeof import("@developer-overheid-nl/don-tools-logic")>("@developer-overheid-nl/don-tools-logic"),
1515
);
1616

17-
const getLogicErrorStatus = (error: unknown): number | undefined => {
18-
if (typeof error !== "object" || error === null || !("status" in error)) return undefined;
19-
const status = (error as { status: unknown }).status;
20-
return typeof status === "number" ? status : undefined;
21-
};
22-
23-
const getLogicErrorMessage = (error: unknown): string => {
24-
if (typeof error !== "object" || error === null) {
25-
return "Request validation failed";
26-
}
27-
if (error instanceof Error && error.message.length > 0) return error.message;
28-
const detail = "detail" in error ? (error as { detail: unknown }).detail : undefined;
29-
if (typeof detail === "string" && detail.length > 0) return detail;
30-
return "Request validation failed";
31-
};
32-
33-
const asHttpException = async <T>(operation: () => Promise<T>): Promise<T> => {
17+
const asBadRequest = async <T>(operation: () => Promise<T>): Promise<T> => {
3418
try {
3519
return await operation();
3620
} catch (error) {
37-
throw new HttpException(getLogicErrorMessage(error), getLogicErrorStatus(error) ?? 400);
21+
throw new BadRequestException(error instanceof Error ? error.message : "Request validation failed");
3822
}
3923
};
4024

@@ -43,52 +27,52 @@ export class ToolsApiService extends ToolsApi {
4327
async arazzoMarkdown(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<string> {
4428
const { arazzoMarkdown } = await loadLogic();
4529
reply.type("text/markdown; charset=utf-8");
46-
return asHttpException(() => arazzoMarkdown(oasInput as OasInput));
30+
return asBadRequest(() => arazzoMarkdown(oasInput as OasInput));
4731
}
4832

4933
async arazzoMermaid(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<string> {
5034
const { arazzoMermaid } = await loadLogic();
5135
reply.type("text/plain; charset=utf-8");
52-
return asHttpException(() => arazzoMermaid(oasInput as OasInput));
36+
return asBadRequest(() => arazzoMermaid(oasInput as OasInput));
5337
}
5438

5539
async bundleOAS(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<void> {
5640
const { bundleOAS } = await loadLogic();
57-
const result = await asHttpException(() => bundleOAS(oasInput as OasInput));
41+
const result = await asBadRequest(() => bundleOAS(oasInput as OasInput));
5842
setHeaders(reply, result.headers);
5943
return result.rawBody as never;
6044
}
6145

6246
async convertOAS(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<void> {
6347
const { convertOAS } = await loadLogic();
64-
const result = await asHttpException(() => convertOAS(oasInput as OasInput));
48+
const result = await asBadRequest(() => convertOAS(oasInput as OasInput));
6549
setHeaders(reply, result.headers);
6650
return result.rawBody as never;
6751
}
6852

6953
async createPostmanCollection(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<void> {
7054
const { createPostmanCollection } = await loadLogic();
71-
const result = await asHttpException(() => createPostmanCollection(oasInput as OasInput));
55+
const result = await asBadRequest(() => createPostmanCollection(oasInput as OasInput));
7256
setHeaders(reply, result.headers);
7357
return result.rawBody as never;
7458
}
7559

7660
async generateOAS(oasInput: OasInput | undefined, _request: Request, reply: FastifyReply): Promise<object> {
7761
const { generateOAS } = await loadLogic();
78-
const result = await asHttpException(() => generateOAS(oasInput as OasInput));
62+
const result = await asBadRequest(() => generateOAS(oasInput as OasInput));
7963
setHeaders(reply, result.headers);
8064
return JSON.parse(Buffer.from(result.rawBody).toString("utf8")) as object;
8165
}
8266

8367
async untrustClient(untrustClientInput: UntrustedClientInput | undefined): Promise<ModelsKeycloakClientResult> {
8468
const { untrustedClient } = await loadLogic();
85-
return asHttpException(() =>
69+
return asBadRequest(() =>
8670
untrustedClient(untrustClientInput as UntrustedClientInput),
8771
) as Promise<ModelsKeycloakClientResult>;
8872
}
8973

9074
async validatorOpenAPIPost(oasInput: OasInput | undefined): Promise<ModelsLintResult> {
9175
const { validatorOpenAPIPost } = await loadLogic();
92-
return asHttpException(() => validatorOpenAPIPost(oasInput as ValidateInput)) as Promise<ModelsLintResult>;
76+
return asBadRequest(() => validatorOpenAPIPost(oasInput as ValidateInput)) as Promise<ModelsLintResult>;
9377
}
9478
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"license": "EUPL-1.2",
1919
"private": true,
2020
"dependencies": {
21-
"@developer-overheid-nl/don-tools": "git+https://github.com/developer-overheid-nl/don-tools.git#d3d54ba222717d070b8d1ddd7689713dd0aaab26",
21+
"@developer-overheid-nl/don-tools-logic": "^0.0.2",
2222
"@fastify/cors": "^11.2.0",
2323
"@nestjs/common": "^11.1.27",
2424
"@nestjs/core": "^11.1.27",

test/app.test.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,6 @@ describe("app", () => {
6060
expect(JSON.parse(response.body)).toMatchObject({ openapi: "3.1.0" });
6161
});
6262

63-
it("returns 422 when an OpenAPI document cannot be fully dereferenced", async () => {
64-
const response = await inject({
65-
method: "POST",
66-
url: "/v1/oas/bundle",
67-
payload: {
68-
oasBody: JSON.stringify({
69-
openapi: "3.0.3",
70-
info: { title: "Recursive API", version: "1.0.0" },
71-
paths: {},
72-
components: {
73-
schemas: {
74-
Node: {
75-
type: "object",
76-
properties: {
77-
children: {
78-
type: "array",
79-
items: { $ref: "#/components/schemas/Node" },
80-
},
81-
},
82-
},
83-
},
84-
},
85-
}),
86-
},
87-
});
88-
89-
expect(response.statusCode).toBe(422);
90-
expect(response.headers["content-type"]).toContain("application/problem+json");
91-
expect(response.json()).toMatchObject({
92-
status: 422,
93-
title: "De OpenAPI specificatie bevat circulaire verwijzingen en kan niet volledig worden gedereferenced.",
94-
});
95-
});
96-
9763
it("returns generated OpenAPI directly", async () => {
9864
const response = await inject({
9965
method: "POST",

test/convert-oas.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { load } from "js-yaml";
3-
import { convertOAS } from "@developer-overheid-nl/don-tools";
3+
import { convertOAS } from "@developer-overheid-nl/don-tools-logic";
44

55
const toJson = (buffer: Buffer) => JSON.parse(buffer.toString("utf8"));
66
const toYaml = (buffer: Buffer) => load(buffer.toString("utf8")) as Record<string, unknown>;
@@ -53,13 +53,7 @@ components:
5353
});
5454

5555
it("downgrades 3.1 -> 3.0 (JSON)", async () => {
56-
const sourceSpec = {
57-
openapi: "3.1.0",
58-
info: { title: "Test API", version: "1.0.0" },
59-
paths: {},
60-
webhooks: { onEvent: { post: { responses: { 200: { description: "OK" } } } } },
61-
components: { schemas: { Pet: { type: "object", properties: { nickname: { type: ["string", "null"] } } } } },
62-
};
56+
const sourceSpec = { openapi: "3.1.0", info: { title: "Test API", version: "1.0.0" }, paths: {}, webhooks: { onEvent: { post: { responses: { 200: { description: "OK" } } } } }, components: { schemas: { Pet: { type: "object", properties: { nickname: { type: ["string", "null"] } } } } } };
6357
const result = await convertOAS({ oasBody: JSON.stringify(sourceSpec), targetVersion: "3.0" });
6458
const converted = toJson(result.rawBody);
6559
expect(converted.openapi).toBe("3.0.3");

0 commit comments

Comments
 (0)