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

Allow specifying security field when generating spec #4

Open
tonyxiao opened this issue Feb 13, 2024 · 2 comments
Open

Allow specifying security field when generating spec #4

tonyxiao opened this issue Feb 13, 2024 · 2 comments

Comments

@tonyxiao
Copy link

Right now we allow specifying the securitySchemes field, but not the security field which is a top level field in the oas

@tonyxiao
Copy link
Author

on that note, we should also allow for each endpoint to specify security field as well, as security requirement can change on a per-endpoint basis. Right now the openAPI meta is notably missing this information

export type OpenApiMeta<TMeta = TRPCMeta> = TMeta & {
    openapi?: {
        enabled?: boolean;
        method: OpenApiMethod;
        path: `/${string}`;
        summary?: string;
        description?: string;
        protect?: boolean;
        tags?: string[];
        contentTypes?: OpenApiContentType[];
        deprecated?: boolean;
        requestHeaders?: AnyZodObject;
        responseHeaders?: AnyZodObject;
        successDescription?: string;
        errorResponses?: number[] | {
            [key: number]: string;
        };
    };
};

@tonyxiao
Copy link
Author

I see that in generator/paths.ts we have handling (below) for the protect field. It is unfortunately too simplistic and doesn't cover the spectrum of the spec (e.g. ability to specify oauth scope required)

const security = protect ? securitySchemeNames.map((name) => ({ [name]: [] })) : undefined;

      pathsObject[path] = {
        ...pathsObject[path],
        [httpMethod]: {
          operationId: procedurePath.replace(/\./g, '-'),
          summary,
          description,
          tags,
          security,
          ...requestData,
          responses,
          ...(openapi.deprecated ? { deprecated: openapi.deprecated } : {}),
        },
      };

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

No branches or pull requests

1 participant