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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi-metadata #1992

Merged
merged 25 commits into from
Nov 10, 2024
Merged

openapi-metadata #1992

merged 25 commits into from
Nov 10, 2024

Conversation

kerwanp
Copy link
Contributor

@kerwanp kerwanp commented Nov 6, 2024

This Pull request brings a new library openapi-metadata. It is a complete rewrite of the original one that has never been released to bring a better developer experience, improved extensibility and a smaller and cleaner codebase.

openapi-metadata makes it easy to generate OpenAPI compliant documents using Typescript decorators. It is intended to be used through specific integrations depending on the backend but can also be used as it is.

Here is an example using express:

import express from "express";
import { generateDocument } from "openapi-metadata";
import { generateScalarUI } from "openapi-metadata/ui";
import { ApiProperty, ApiOperation, ApiResponse } from "openapi-metadata/decorators";

const app = express();

class Post {
  @ApiProperty()
  declare id: number;

  @ApiProperty()
  declare title: string;
}

class PostsController {
  @ApiOperation({ summary: "List all posts" })
  @ApiResponse({ type: [Post] })
  index() {}
}

const document = await generateDocument({
  controllers: [PostsController],
  document: {
    info: {
      name: "My API",
      version: "1.0.0",
    },
  },
});

app.get("/api", async (req, res) => {
  res.send(JSON.stringify(document));
});

app.get("/api/docs", (req, res) => {
  const ui = generateScalarUI("/api");
  res.send(ui);
});

I will keep this PR as draft until v1 of Adonis OpenAPI implementation is ready to be release.

@kerwanp kerwanp requested a review from a team as a code owner November 6, 2024 17:51
Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: b9f3cae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-metadata Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kerwanp kerwanp marked this pull request as draft November 6, 2024 18:28
Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

This looks good to me; merge whenever!

docs/.vitepress/en.ts Show resolved Hide resolved
packages/openapi-metadata/LICENSE Outdated Show resolved Hide resolved
@kerwanp kerwanp marked this pull request as ready for review November 10, 2024 12:29
@kerwanp kerwanp merged commit 09624c3 into openapi-ts:main Nov 10, 2024
8 checks passed
@openapi-ts-bot openapi-ts-bot mentioned this pull request Nov 10, 2024
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.

2 participants