Skip to content

Commit

Permalink
feat(useSidebar): methodAliases option to customize method bag (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
enzonotario authored Nov 15, 2024
1 parent 4636f94 commit 50d1883
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/layouts/sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,25 @@ module.exports = {
},
}
```

## Method Aliases

By default, the methods are displayed in uppercase.

You can specify aliases for the methods by passing the `methodAliases` option to the `useSidebar` composable.

```ts
const sidebar = useSidebar({
spec,
methodAliases: {
get: 'GE',
post: 'PO',
put: 'PU',
delete: 'DE',
patch: 'PA',
options: 'OP',
head: 'HE',
},
})
```

6 changes: 5 additions & 1 deletion src/composables/useSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export function useSidebar({
linkPrefix,
tagLinkPrefix,
defaultTag,
methodAliases,
}: {
spec?: OpenAPI
linkPrefix?: string
tagLinkPrefix?: string
defaultTag?: string
methodAliases?: Record<string, string>
} = {
...defaultOptions,
}) {
Expand All @@ -53,8 +55,10 @@ export function useSidebar({
})

function sidebarItemTemplate(method: string, title: string) {
const resolvedMethod = methodAliases?.[method] || method.toUpperCase()

return `<span class="OASidebarItem group/oaSidebarItem">
<span class="OASidebarItem-badge OAMethodBadge--${method.toLowerCase()}">${method.toUpperCase()}</span>
<span class="OASidebarItem-badge OAMethodBadge--${method.toLowerCase()}">${resolvedMethod}</span>
<span class="OASidebarItem-text text">${title}</span>
</span>`
}
Expand Down

0 comments on commit 50d1883

Please sign in to comment.