-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(code-gen): always expose the Compas structure in OpenAPI format
This allows interop with a new OpenAPI based code-generator
- Loading branch information
Showing
4 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { mainTestFn, test } from "@compas/cli"; | ||
import { closeTestApp, createTestAppAndClient } from "@compas/server"; | ||
import axios from "axios"; | ||
import { axiosInterceptErrorAndWrapWithAppError } from "./generated/application/common/api-client.js"; | ||
import { apiCompasStructure } from "./generated/application/compas/apiClient.js"; | ||
import { app } from "./services/core.js"; | ||
|
||
mainTestFn(import.meta); | ||
|
||
test("structure/controller", async (t) => { | ||
// Run the Koa instance on a random port and create an Axios instance that uses that as | ||
// the baseUrl. | ||
const axiosInstance = axios.create(); | ||
await createTestAppAndClient(app, axiosInstance); | ||
axiosInterceptErrorAndWrapWithAppError(axiosInstance); | ||
|
||
t.test("compas structure", async (t) => { | ||
const results = await Promise.all([ | ||
apiCompasStructure(axiosInstance, {}), | ||
apiCompasStructure(axiosInstance, { format: "compas" }), | ||
]); | ||
|
||
t.deepEqual(results[0], results[1]); | ||
}); | ||
|
||
t.test("openapi structure", async (t) => { | ||
const results = await Promise.all([ | ||
apiCompasStructure(axiosInstance, {}), | ||
apiCompasStructure(axiosInstance, { format: "openapi" }), | ||
]); | ||
|
||
t.notEqual(JSON.stringify(results[0]), JSON.stringify(results[1])); | ||
}); | ||
|
||
t.test("teardown", async (t) => { | ||
// Since subtests run in the order they are registered, we can always do some | ||
// teardown in the last subtest. | ||
|
||
await closeTestApp(app); | ||
|
||
t.pass(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters