ts-spec / tspec

Type-driven API Documentation library. Auto-generating REST API document based on TypeScript types.
https://ts-spec.github.io/tspec/
MIT License
108 stars 5 forks source link

Authentication config won't work #47

Closed seoes closed 1 month ago

seoes commented 6 months ago

Despite defining the security scheme for JWT in my Tspec configuration, the output in the JSON file doesn't reflect this correctly

Tspec Configuration

const tspecParams: Tspec.GenerateParams = {
        specPathGlobs: ["./src/**/*"],
        // tsconfigPath: "./tsconfig.json",
        outputPath: "./src/config/openapi.json",
        openapi: {
            title: "Tspec API",
            version: "0.0.1",
            securityDefinitions: {
                jwt: {
                    type: "http",
                    scheme: "bearer",
                    bearerFormat: "JWT",
                },
            },
        },
        debug: true,
        ignoreErrors: true,
    };

    const openApiSpec = await generateTspec(tspecParams);

API Specification:

export type CommentApiSpec = Tspec.DefineApiSpec<{
    security: "jwt";
    paths: {
        "/comment/:postId": {
            get: {
                summary: "Get comment by post id";
                path: { postId: Tspec.UuidString };
                responses: { 200: CommentType[] };
        };
    };
}>;

Resulting JSON Output (part of):

  "info": {
    "title": "Tspec API",
    "version": "0.0.1"
  },
  "openapi": "3.0.3",
  "paths": {
    "/comment/:postId": {
      "get": {
        "operationId": "CommentApiSpec_get_/comment/:postId",
        "tags": [],
        "summary": "Get comment by post id",
        "security": [
          {
            "jwt": []
          }
        ],
      },
    },
  },

I checked that this code generates output correctly

But I can't find any Authorization button at all in swagger ui page

digitalcrafted commented 1 month ago

Hi @seoes,

I tested the Authentication configuration and I can confirm it works well.

My tspec version: "tspec": "^0.1.112"

I hope this helps.

Screenshot 2024-05-29 at 11 30 33
hyeonss0417 commented 1 month ago

Hi, @seoes.

Thank you very much for taking the time to report the issue and for your interest in our project.

As @digitalcrafted has already tested it, I have also tested it and can confirm it works well in the latest tspec version 0.1.114.

image

I have also added this to the example book-advanced (commit: c573d83324e085b02dd573ee85a3727abab3f977).

Please update your tspec version and try again. If the issue persists, let us know.