Replies: 4 comments 1 reply
-
hi 👋 i think you want something like below import { Elysia, t } from "elysia";
import swagger from "@elysiajs/swagger";
new Elysia()
.use(swagger())
.model({ a: t.String({ $id: "a" }) })
.get("/a", () => "a", { type: "json", response: "a" })
.get("/as", () => ["a", "a", "a"], { type: "json", response: t.Array(t.Ref("a")) })
.listen(3000, ({ hostname, port }) => {
console.log(`🦊 Elysia is running at ${hostname}:${port}`);
});
setInterval(async () => {
const l = await Promise.all([
fetch("http://localhost:3000/a").then(r => r.text()),
fetch("http://localhost:3000/as").then(r => r.text()),
fetch("http://localhost:3000/swagger/json").then(r => r.text()),
]);
console.log(l.join("\n"))
}, 3000) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
you're right,
// filename adminUserModels.ts
import Elysia, { t } from "elysia";
const adminUserModel = t.Object(
{
id: t.String({
format: "uuid",
}),
email: t.String(),
createdAt: t.Date(),
updatedAt: t.Date(),
},
{
$id: "#/components/schemas/admin-users.user",
},
);
export const adminUsersModels = new Elysia().model({
"admin-users.user": adminUserModel,
"admin-users.users": t.Array(
t.Ref<typeof adminUserModel>("#/components/schemas/admin-users.user"),
)
}); import Elysia from "elysia";
import { adminUsersModels } from "./adminUserModels";
import swagger from "@elysiajs/swagger";
export const readUsers = new Elysia()
.use(swagger())
.use(adminUsersModels)
.get("/user", () => ({
id: "123e4567-e89b-12d3-a456-426614174000",
email: "[email protected]",
createdAt: new Date("2023-01-01T10:00:00Z"),
updatedAt: new Date("2023-06-01T15:30:00Z"),
}), {
type: "json",
response: "admin-users.user",
})
.get(
"/users",
() => [{
id: "123e4567-e89b-12d3-a456-426614174000",
email: "[email protected]",
createdAt: new Date("2023-01-01T10:00:00Z"),
updatedAt: new Date("2023-06-01T15:30:00Z"),
}],
{
type: "json",
response: "admin-users.users",
},
).listen(3000, async ({ hostname, port }) => {
console.log(`🦊 Elysia is running at ${hostname}:${port}`);
const l = await Promise.all([
fetch("http://localhost:3000/users").then(r => r.text()),
fetch("http://localhost:3000/swagger/json").then(r => r.text()),
]);
console.log(l.join("\n"))
});
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there !
First, I would like to thank you for this work, the DX is super smooth and features are covering almost everything I need !
I was wondering one thing though:
I have a model for my user data :
that is used as it :
I used the "users" in plural because I need a list here.
It means, logically, that the swagger documentation will generate two models.
I did not find a way, so far, to have only "user" that is a array only for this response; to allow in fine having only one model.
It would avoid confusing an openAPI generator to have duplicated models.
Same in the answer, it "does not" point to the model , isn't it ?
If you have any answers I take it,
Thank you !
Beta Was this translation helpful? Give feedback.
All reactions