docs-util: add exceptions for routes with custom auth middleware (#11755)

This commit is contained in:
Shahed Nasser
2025-03-06 13:05:50 +02:00
committed by GitHub
parent 3616003145
commit 08ce70a368
20 changed files with 228 additions and 58 deletions
@@ -17443,7 +17443,7 @@ paths:
operationId: GetInvites operationId: GetInvites
summary: List Invites summary: List Invites
description: Retrieve a list of invites. The invites can be filtered by fields such as `id`. The invites can also be sorted or paginated. description: Retrieve a list of invites. The invites can be filtered by fields such as `id`. The invites can also be sorted or paginated.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -17950,11 +17950,15 @@ paths:
$ref: '#/components/responses/invalid_request_error' $ref: '#/components/responses/invalid_request_error'
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
post: post:
operationId: PostInvites operationId: PostInvites
summary: Create Invite summary: Create Invite
description: Create a invite. description: Create a invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -18014,6 +18018,10 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: createInvitesWorkflow x-workflow: createInvitesWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
/admin/invites/accept: /admin/invites/accept:
post: post:
operationId: PostInvitesAccept operationId: PostInvitesAccept
@@ -18021,7 +18029,7 @@ paths:
description: | description: |
Accept an invite and create a new user. Accept an invite and create a new user.
Since the user isn't created yet, the JWT token used in the authorization header is retrieved from the `/auth/user/emailpass/register` API route (or a provider other than `emailpass`). The user can then authenticate using the `/auth/user/emailpass` API route. Since the user isn't created yet, the JWT token used in the authorization header is retrieved from the `/auth/user/emailpass/register` API route (or a provider other than `emailpass`). The user can then authenticate using the `/auth/user/emailpass` API route.
x-authenticated: false x-authenticated: true
requestBody: requestBody:
content: content:
application/json: application/json:
@@ -18091,12 +18099,15 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: acceptInviteWorkflow x-workflow: acceptInviteWorkflow
security:
- cookie_auth: []
- jwt_token: []
/admin/invites/{id}: /admin/invites/{id}:
get: get:
operationId: GetInvitesId operationId: GetInvitesId
summary: Get an Invite summary: Get an Invite
description: Retrieve an invite by its ID. You can expand the invite's relations or select the fields that should be returned. description: Retrieve an invite by its ID. You can expand the invite's relations or select the fields that should be returned.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -18139,11 +18150,15 @@ paths:
$ref: '#/components/responses/invalid_request_error' $ref: '#/components/responses/invalid_request_error'
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
delete: delete:
operationId: DeleteInvitesId operationId: DeleteInvitesId
summary: Delete Invite summary: Delete Invite
description: Delete an invite. description: Delete an invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -18196,12 +18211,16 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: deleteInvitesWorkflow x-workflow: deleteInvitesWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
/admin/invites/{id}/resend: /admin/invites/{id}/resend:
post: post:
operationId: PostInvitesIdResend operationId: PostInvitesIdResend
summary: Refresh Invite Token summary: Refresh Invite Token
description: Refresh the token of an invite. description: Refresh the token of an invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -18245,6 +18264,10 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: refreshInviteTokensWorkflow x-workflow: refreshInviteTokensWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
/admin/notifications: /admin/notifications:
get: get:
operationId: GetNotifications operationId: GetNotifications
@@ -41910,7 +41933,7 @@ paths:
operationId: GetUsers operationId: GetUsers
summary: List Users summary: List Users
description: Retrieve a list of users. The users can be filtered by fields such as `id`. The users can also be sorted or paginated. description: Retrieve a list of users. The users can be filtered by fields such as `id`. The users can also be sorted or paginated.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -42379,12 +42402,15 @@ paths:
$ref: '#/components/responses/invalid_request_error' $ref: '#/components/responses/invalid_request_error'
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
security:
- cookie_auth: []
- jwt_token: []
/admin/users/me: /admin/users/me:
get: get:
operationId: GetUsersMe operationId: GetUsersMe
summary: Get Logged-In User summary: Get Logged-In User
description: Retrieve the logged-in user's details. description: Retrieve the logged-in user's details.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -42421,12 +42447,15 @@ paths:
$ref: '#/components/responses/invalid_request_error' $ref: '#/components/responses/invalid_request_error'
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
security:
- cookie_auth: []
- jwt_token: []
/admin/users/{id}: /admin/users/{id}:
get: get:
operationId: GetUsersId operationId: GetUsersId
summary: Get a User summary: Get a User
description: Retrieve a user by its ID. You can expand the user's relations or select the fields that should be returned. description: Retrieve a user by its ID. You can expand the user's relations or select the fields that should be returned.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -42469,11 +42498,14 @@ paths:
$ref: '#/components/responses/invalid_request_error' $ref: '#/components/responses/invalid_request_error'
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
security:
- cookie_auth: []
- jwt_token: []
post: post:
operationId: PostUsersId operationId: PostUsersId
summary: Update a User summary: Update a User
description: Update a user's details. description: Update a user's details.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -42529,11 +42561,14 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: updateUsersWorkflow x-workflow: updateUsersWorkflow
security:
- cookie_auth: []
- jwt_token: []
delete: delete:
operationId: DeleteUsersId operationId: DeleteUsersId
summary: Delete a User summary: Delete a User
description: Delete a user. description: Delete a user.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -42567,6 +42602,9 @@ paths:
'500': '500':
$ref: '#/components/responses/500_error' $ref: '#/components/responses/500_error'
x-workflow: removeUserAccountWorkflow x-workflow: removeUserAccountWorkflow
security:
- cookie_auth: []
- jwt_token: []
/admin/workflows-executions: /admin/workflows-executions:
get: get:
operationId: GetWorkflowsExecutions operationId: GetWorkflowsExecutions
@@ -4,7 +4,7 @@ get:
description: >- description: >-
Retrieve a list of invites. The invites can be filtered by fields such as Retrieve a list of invites. The invites can be filtered by fields such as
`id`. The invites can also be sorted or paginated. `id`. The invites can also be sorted or paginated.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -589,11 +589,15 @@ get:
$ref: ../components/responses/invalid_request_error.yaml $ref: ../components/responses/invalid_request_error.yaml
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
post: post:
operationId: PostInvites operationId: PostInvites
summary: Create Invite summary: Create Invite
description: Create a invite. description: Create a invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -657,3 +661,7 @@ post:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: createInvitesWorkflow x-workflow: createInvitesWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
@@ -8,7 +8,7 @@ post:
header is retrieved from the `/auth/user/emailpass/register` API route (or a header is retrieved from the `/auth/user/emailpass/register` API route (or a
provider other than `emailpass`). The user can then authenticate using the provider other than `emailpass`). The user can then authenticate using the
`/auth/user/emailpass` API route. `/auth/user/emailpass` API route.
x-authenticated: false x-authenticated: true
requestBody: requestBody:
content: content:
application/json: application/json:
@@ -72,3 +72,6 @@ post:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: acceptInviteWorkflow x-workflow: acceptInviteWorkflow
security:
- cookie_auth: []
- jwt_token: []
@@ -4,7 +4,7 @@ get:
description: >- description: >-
Retrieve an invite by its ID. You can expand the invite's relations or Retrieve an invite by its ID. You can expand the invite's relations or
select the fields that should be returned. select the fields that should be returned.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -56,11 +56,15 @@ get:
$ref: ../components/responses/invalid_request_error.yaml $ref: ../components/responses/invalid_request_error.yaml
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
delete: delete:
operationId: DeleteInvitesId operationId: DeleteInvitesId
summary: Delete Invite summary: Delete Invite
description: Delete an invite. description: Delete an invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -114,3 +118,7 @@ delete:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: deleteInvitesWorkflow x-workflow: deleteInvitesWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
@@ -2,7 +2,7 @@ post:
operationId: PostInvitesIdResend operationId: PostInvitesIdResend
summary: Refresh Invite Token summary: Refresh Invite Token
description: Refresh the token of an invite. description: Refresh the token of an invite.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -55,3 +55,7 @@ post:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: refreshInviteTokensWorkflow x-workflow: refreshInviteTokensWorkflow
security:
- api_token: []
- cookie_auth: []
- jwt_token: []
@@ -4,7 +4,7 @@ get:
description: >- description: >-
Retrieve a list of users. The users can be filtered by fields such as `id`. Retrieve a list of users. The users can be filtered by fields such as `id`.
The users can also be sorted or paginated. The users can also be sorted or paginated.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -547,3 +547,6 @@ get:
$ref: ../components/responses/invalid_request_error.yaml $ref: ../components/responses/invalid_request_error.yaml
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
security:
- cookie_auth: []
- jwt_token: []
@@ -2,7 +2,7 @@ get:
operationId: GetUsersMe operationId: GetUsersMe
summary: Get Logged-In User summary: Get Logged-In User
description: Retrieve the logged-in user's details. description: Retrieve the logged-in user's details.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: fields - name: fields
in: query in: query
@@ -48,3 +48,6 @@ get:
$ref: ../components/responses/invalid_request_error.yaml $ref: ../components/responses/invalid_request_error.yaml
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
security:
- cookie_auth: []
- jwt_token: []
@@ -4,7 +4,7 @@ get:
description: >- description: >-
Retrieve a user by its ID. You can expand the user's relations or select the Retrieve a user by its ID. You can expand the user's relations or select the
fields that should be returned. fields that should be returned.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -56,11 +56,14 @@ get:
$ref: ../components/responses/invalid_request_error.yaml $ref: ../components/responses/invalid_request_error.yaml
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
security:
- cookie_auth: []
- jwt_token: []
post: post:
operationId: PostUsersId operationId: PostUsersId
summary: Update a User summary: Update a User
description: Update a user's details. description: Update a user's details.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -118,11 +121,14 @@ post:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: updateUsersWorkflow x-workflow: updateUsersWorkflow
security:
- cookie_auth: []
- jwt_token: []
delete: delete:
operationId: DeleteUsersId operationId: DeleteUsersId
summary: Delete a User summary: Delete a User
description: Delete a user. description: Delete a user.
x-authenticated: false x-authenticated: true
parameters: parameters:
- name: id - name: id
in: path in: path
@@ -157,3 +163,6 @@ delete:
'500': '500':
$ref: ../components/responses/500_error.yaml $ref: ../components/responses/500_error.yaml
x-workflow: removeUserAccountWorkflow x-workflow: removeUserAccountWorkflow
security:
- cookie_auth: []
- jwt_token: []
@@ -3,7 +3,7 @@
* operationId: DeleteInvitesId * operationId: DeleteInvitesId
* summary: Delete Invite * summary: Delete Invite
* description: Delete an invite. * description: Delete an invite.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -56,6 +56,10 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: deleteInvitesWorkflow * x-workflow: deleteInvitesWorkflow
* security:
* - api_token: []
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: DeleteUsersId * operationId: DeleteUsersId
* summary: Delete a User * summary: Delete a User
* description: Delete a user. * description: Delete a user.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -37,6 +37,9 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: removeUserAccountWorkflow * x-workflow: removeUserAccountWorkflow
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: GetInvites * operationId: GetInvites
* summary: List Invites * summary: List Invites
* description: Retrieve a list of invites. The invites can be filtered by fields such as `id`. The invites can also be sorted or paginated. * description: Retrieve a list of invites. The invites can be filtered by fields such as `id`. The invites can also be sorted or paginated.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: fields * - name: fields
* in: query * in: query
@@ -512,6 +512,10 @@
* $ref: "#/components/responses/invalid_request_error" * $ref: "#/components/responses/invalid_request_error"
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* security:
* - api_token: []
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: GetInvitesId * operationId: GetInvitesId
* summary: Get an Invite * summary: Get an Invite
* description: Retrieve an invite by its ID. You can expand the invite's relations or select the fields that should be returned. * description: Retrieve an invite by its ID. You can expand the invite's relations or select the fields that should be returned.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -48,6 +48,10 @@
* $ref: "#/components/responses/invalid_request_error" * $ref: "#/components/responses/invalid_request_error"
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* security:
* - api_token: []
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: GetUsers * operationId: GetUsers
* summary: List Users * summary: List Users
* description: Retrieve a list of users. The users can be filtered by fields such as `id`. The users can also be sorted or paginated. * description: Retrieve a list of users. The users can be filtered by fields such as `id`. The users can also be sorted or paginated.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: fields * - name: fields
* in: query * in: query
@@ -474,6 +474,9 @@
* $ref: "#/components/responses/invalid_request_error" * $ref: "#/components/responses/invalid_request_error"
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: GetUsersId * operationId: GetUsersId
* summary: Get a User * summary: Get a User
* description: Retrieve a user by its ID. You can expand the user's relations or select the fields that should be returned. * description: Retrieve a user by its ID. You can expand the user's relations or select the fields that should be returned.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -48,6 +48,9 @@
* $ref: "#/components/responses/invalid_request_error" * $ref: "#/components/responses/invalid_request_error"
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: GetUsersMe * operationId: GetUsersMe
* summary: Get Logged-In User * summary: Get Logged-In User
* description: Retrieve the logged-in user's details. * description: Retrieve the logged-in user's details.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: fields * - name: fields
* in: query * in: query
@@ -42,6 +42,9 @@
* $ref: "#/components/responses/invalid_request_error" * $ref: "#/components/responses/invalid_request_error"
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: PostInvites * operationId: PostInvites
* summary: Create Invite * summary: Create Invite
* description: Create a invite. * description: Create a invite.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: fields * - name: fields
* in: query * in: query
@@ -65,6 +65,10 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: createInvitesWorkflow * x-workflow: createInvitesWorkflow
* security:
* - api_token: []
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: PostInvitesIdResend * operationId: PostInvitesIdResend
* summary: Refresh Invite Token * summary: Refresh Invite Token
* description: Refresh the token of an invite. * description: Refresh the token of an invite.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -49,6 +49,10 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: refreshInviteTokensWorkflow * x-workflow: refreshInviteTokensWorkflow
* security:
* - api_token: []
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -6,7 +6,7 @@
* Accept an invite and create a new user. * Accept an invite and create a new user.
* *
* Since the user isn't created yet, the JWT token used in the authorization header is retrieved from the `/auth/user/emailpass/register` API route (or a provider other than `emailpass`). The user can then authenticate using the `/auth/user/emailpass` API route. * Since the user isn't created yet, the JWT token used in the authorization header is retrieved from the `/auth/user/emailpass/register` API route (or a provider other than `emailpass`). The user can then authenticate using the `/auth/user/emailpass` API route.
* x-authenticated: false * x-authenticated: true
* requestBody: * requestBody:
* content: * content:
* application/json: * application/json:
@@ -76,6 +76,9 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: acceptInviteWorkflow * x-workflow: acceptInviteWorkflow
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -3,7 +3,7 @@
* operationId: PostUsersId * operationId: PostUsersId
* summary: Update a User * summary: Update a User
* description: Update a user's details. * description: Update a user's details.
* x-authenticated: false * x-authenticated: true
* parameters: * parameters:
* - name: id * - name: id
* in: path * in: path
@@ -61,6 +61,9 @@
* "500": * "500":
* $ref: "#/components/responses/500_error" * $ref: "#/components/responses/500_error"
* x-workflow: updateUsersWorkflow * x-workflow: updateUsersWorkflow
* security:
* - cookie_auth: []
* - jwt_token: []
* *
*/ */
@@ -52,6 +52,8 @@ type AuthRequests = {
exact?: string exact?: string
startsWith?: string startsWith?: string
requiresAuthentication: boolean requiresAuthentication: boolean
allowedAuthTypes?: string[]
httpMethods?: string[]
} }
/** /**
@@ -99,6 +101,21 @@ class OasKindGenerator extends FunctionKindGenerator {
exact: "store/orders/[id]/transfer/cancel", exact: "store/orders/[id]/transfer/cancel",
requiresAuthentication: true, requiresAuthentication: true,
}, },
{
exact: "admin/invites/accept",
httpMethods: ["post"],
requiresAuthentication: true,
allowedAuthTypes: ["cookie_auth", "jwt_token"],
},
{
startsWith: "admin/invites",
requiresAuthentication: true,
},
{
startsWith: "admin/users",
requiresAuthentication: true,
allowedAuthTypes: ["cookie_auth", "jwt_token"],
},
] ]
readonly RESPONSE_TYPE_NAMES = ["MedusaResponse"] readonly RESPONSE_TYPE_NAMES = ["MedusaResponse"]
readonly FIELD_QUERY_PARAMS = ["fields", "expand"] readonly FIELD_QUERY_PARAMS = ["fields", "expand"]
@@ -275,8 +292,12 @@ class OasKindGenerator extends FunctionKindGenerator {
const { oasPath, normalized: normalizedOasPath } = this.getOasPath(node) const { oasPath, normalized: normalizedOasPath } = this.getOasPath(node)
const splitOasPath = oasPath.split("/") const splitOasPath = oasPath.split("/")
const oasPrefix = this.getOasPrefix(methodName, normalizedOasPath) const oasPrefix = this.getOasPrefix(methodName, normalizedOasPath)
const { isAdminAuthenticated, isStoreAuthenticated, isAuthenticated } = const {
this.getAuthenticationDetails(node, oasPath) isAdminAuthenticated,
isStoreAuthenticated,
isAuthenticated,
allowedAuthTypes,
} = this.getAuthenticationDetails(node, oasPath, methodName)
const tagName = this.getTagName(splitOasPath) const tagName = this.getTagName(splitOasPath)
const { summary, description } = const { summary, description } =
this.knowledgeBaseFactory.tryToGetOasMethodSummaryAndDescription({ this.knowledgeBaseFactory.tryToGetOasMethodSummaryAndDescription({
@@ -370,7 +391,11 @@ class OasKindGenerator extends FunctionKindGenerator {
} }
// add security details if applicable // add security details if applicable
oas.security = this.getSecurity({ isAdminAuthenticated, isAuthenticated }) oas.security = this.getSecurity({
isAdminAuthenticated,
isAuthenticated,
auth_types: allowedAuthTypes,
})
if (tagName) { if (tagName) {
oas.tags = [tagName] oas.tags = [tagName]
@@ -484,11 +509,19 @@ class OasKindGenerator extends FunctionKindGenerator {
} }
// check if authentication details (including security) should be updated // check if authentication details (including security) should be updated
const { isAdminAuthenticated, isStoreAuthenticated, isAuthenticated } = const {
this.getAuthenticationDetails(node, oasPath) isAdminAuthenticated,
isStoreAuthenticated,
isAuthenticated,
allowedAuthTypes,
} = this.getAuthenticationDetails(node, oasPath, methodName)
oas["x-authenticated"] = isAuthenticated oas["x-authenticated"] = isAuthenticated
oas.security = this.getSecurity({ isAdminAuthenticated, isAuthenticated }) oas.security = this.getSecurity({
isAdminAuthenticated,
isAuthenticated,
auth_types: allowedAuthTypes,
})
let parametersUpdated = false let parametersUpdated = false
@@ -815,7 +848,8 @@ class OasKindGenerator extends FunctionKindGenerator {
*/ */
getAuthenticationDetails( getAuthenticationDetails(
node: FunctionNode, node: FunctionNode,
oasPath: string oasPath: string,
httpMethod: string
): { ): {
/** /**
* Whether the OAS operation requires admin authentication. * Whether the OAS operation requires admin authentication.
@@ -829,34 +863,42 @@ class OasKindGenerator extends FunctionKindGenerator {
* Whether the OAS operation requires authentication in genral. * Whether the OAS operation requires authentication in genral.
*/ */
isAuthenticated: boolean isAuthenticated: boolean
/**
* Override the default security requirements.
*/
allowedAuthTypes?: string[]
} { } {
const isAuthenticationDisabled = node const isAuthenticationDisabled = node
.getSourceFile() .getSourceFile()
.statements.some((statement) => .statements.some((statement) =>
statement.getText().includes("AUTHENTICATE = false") statement.getText().includes("AUTHENTICATE = false")
) )
const hasAuthenticationOverride = const hasAuthenticationOverride = this.AUTH_REQUESTS.find((authRequest) => {
this.AUTH_REQUESTS.find((authRequest) => { const pathMatch =
return ( authRequest.exact === oasPath ||
authRequest.exact === oasPath || (authRequest.startsWith && oasPath.startsWith(authRequest.startsWith))
(authRequest.startsWith && oasPath.startsWith(authRequest.startsWith)) const httpMethodMatch =
) !authRequest.httpMethods || authRequest.httpMethods.includes(httpMethod)
})?.requiresAuthentication === true return pathMatch && httpMethodMatch
})
const isAuthRequired =
hasAuthenticationOverride?.requiresAuthentication === true
const isAdminAuthenticated = const isAdminAuthenticated =
(!isAuthenticationDisabled || hasAuthenticationOverride) && (!isAuthenticationDisabled || isAuthRequired) &&
oasPath.startsWith("admin") oasPath.startsWith("admin")
const isStoreAuthenticated = hasAuthenticationOverride const isStoreAuthenticated = isAuthRequired
? oasPath.startsWith("store") ? oasPath.startsWith("store")
: !isAuthenticationDisabled && : !isAuthenticationDisabled &&
hasAuthenticationOverride && isAuthRequired &&
oasPath.startsWith("store") oasPath.startsWith("store")
const isAuthenticated = const isAuthenticated =
isAdminAuthenticated || isStoreAuthenticated || hasAuthenticationOverride isAdminAuthenticated || isStoreAuthenticated || isAuthRequired
return { return {
isAdminAuthenticated, isAdminAuthenticated,
isStoreAuthenticated, isStoreAuthenticated,
isAuthenticated, isAuthenticated,
allowedAuthTypes: hasAuthenticationOverride?.allowedAuthTypes,
} }
} }
@@ -903,6 +945,7 @@ class OasKindGenerator extends FunctionKindGenerator {
getSecurity({ getSecurity({
isAdminAuthenticated, isAdminAuthenticated,
isAuthenticated, isAuthenticated,
auth_types,
}: { }: {
/** /**
* Whether the operation requires admin authentication. * Whether the operation requires admin authentication.
@@ -912,22 +955,35 @@ class OasKindGenerator extends FunctionKindGenerator {
* Whether the operation requires general authentication. * Whether the operation requires general authentication.
*/ */
isAuthenticated: boolean isAuthenticated: boolean
/**
* Override the default security requirements.
*/
auth_types?: string[]
}): OpenAPIV3.SecurityRequirementObject[] | undefined { }): OpenAPIV3.SecurityRequirementObject[] | undefined {
const security: OpenAPIV3.SecurityRequirementObject[] = [] const security: OpenAPIV3.SecurityRequirementObject[] = []
if (isAdminAuthenticated) { const allowed_auth_types =
auth_types ||
[
"cookie_auth",
"jwt_token",
isAdminAuthenticated ? "api_token" : undefined,
].filter(Boolean)
if (isAdminAuthenticated && allowed_auth_types.includes("api_token")) {
security.push({ security.push({
api_token: [], api_token: [],
}) })
} }
if (isAuthenticated) { if (isAuthenticated) {
security.push( if (allowed_auth_types.includes("cookie_auth")) {
{ security.push({
cookie_auth: [], cookie_auth: [],
}, })
{ }
if (allowed_auth_types.includes("jwt_token")) {
security.push({
jwt_token: [], jwt_token: [],
} })
) }
} }
return security.length ? security : undefined return security.length ? security : undefined