Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(accept external swagger paths) #113

Merged
merged 1 commit into from Apr 11, 2024
Merged

Conversation

Autumnlight02
Copy link
Contributor

This PR resolves an issue related to path options.
The reason as to why is the following scenario:
I use trpc with Elysia.js, my goal is now to include Swagger documentation of that process.
Below is my personal usecase / way as in how I generate the trpc documentation and how I use it.

import { trpc } from "@elysiajs/trpc";
import { Elysia } from "elysia";
import { appRouter } from "./router/router";
import { swagger } from "@elysiajs/swagger";
import {
    generateOpenApiDocument,
} from "trpc-openapi";

export const openApiDocument = generateOpenApiDocument(appRouter, {
  title: "tRPC OpenAPI",
  version: "1.0.0",
  baseUrl: "http://localhost:3000",
});

const swaggerExec = swagger({
  documentation: {
    paths: openApiDocument.paths,
  },
});

const app = new Elysia()
  .use(
    trpc(appRouter, {
      endpoint: "/trpc",
      createContext: (args) => {
        console.log(args);
        return {};
      },
    })
  )
  .use(swaggerExec)
  .listen(3000);

console.log(
  `馃 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);

@marclave marclave self-requested a review April 11, 2024 04:50
Copy link
Collaborator

@marclave marclave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice fix @Autumnlight02 ! : )

@marclave marclave merged commit 9d697b2 into elysiajs:main Apr 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants