tspec icon indicating copy to clipboard operation
tspec copied to clipboard

Authentication config won't work

Open seoes opened this issue 2 years ago • 0 comments

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

seoes avatar Jan 15 '24 19:01 seoes