forked from PaloAltoNetworks/docusaurus-openapi-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Callbacks support (PaloAltoNetworks#691)
* add support to callbacks in openapi specs * set package manager in package json * implement operations as tabs within request panel * render callbacks below Request and Responses * remove unwanted files * rename create file * restore json settings
- Loading branch information
1 parent
7f95285
commit 1d067a5
Showing
9 changed files
with
379 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,6 @@ | |
}, | ||
"engines": { | ||
"node": ">=14" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
95 changes: 95 additions & 0 deletions
95
packages/docusaurus-plugin-openapi-docs/src/markdown/createCallbacks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Palo Alto Networks | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* ========================================================================== */ | ||
|
||
import { MediaTypeObject } from "../openapi/types"; | ||
import { ApiItem } from "../types"; | ||
import { createDescription } from "./createDescription"; | ||
import { createMethodEndpoint } from "./createMethodEndpoint"; | ||
import { createRequestBodyDetails } from "./createRequestBodyDetails"; | ||
import { createStatusCodes } from "./createStatusCodes"; | ||
import { create } from "./utils"; | ||
|
||
interface Props { | ||
callbacks: ApiItem["callbacks"]; | ||
} | ||
|
||
interface RequestBodyProps { | ||
title: string; | ||
body: { | ||
content?: { | ||
[key: string]: MediaTypeObject; | ||
}; | ||
description?: string; | ||
required?: boolean; | ||
}; | ||
} | ||
|
||
export function createCallbacks({ callbacks }: Props) { | ||
if (callbacks === undefined) { | ||
return undefined; | ||
} | ||
|
||
const callbacksNames = Object.keys(callbacks); | ||
if (callbacksNames.length === 0) { | ||
return undefined; | ||
} | ||
|
||
return create("div", { | ||
children: [ | ||
create("div", { | ||
className: "openapi__divider", | ||
}), | ||
create("h2", { | ||
children: "Callbacks", | ||
id: "callbacks", | ||
}), | ||
create("OperationTabs", { | ||
className: "openapi-tabs__operation", | ||
children: callbacksNames.flatMap((name) => { | ||
const path = Object.keys(callbacks[name])[0]; | ||
const methods = new Map([ | ||
["delete", callbacks[name][path].delete], | ||
["get", callbacks[name][path].get], | ||
["head", callbacks[name][path].head], | ||
["options", callbacks[name][path].options], | ||
["patch", callbacks[name][path].patch], | ||
["post", callbacks[name][path].post], | ||
["put", callbacks[name][path].put], | ||
["trace", callbacks[name][path].trace], | ||
]); | ||
|
||
return Array.from(methods).flatMap(([method, operationObject]) => { | ||
if (!operationObject) return []; | ||
|
||
const { description, requestBody, responses } = operationObject; | ||
|
||
return [ | ||
create("TabItem", { | ||
label: `${method.toUpperCase()} ${name}`, | ||
value: `${method}-${name}`, | ||
children: [ | ||
createMethodEndpoint(method, path), | ||
// TODO: add `deprecation notice` when markdown support is added | ||
createDescription(description), | ||
createRequestBodyDetails({ | ||
title: "Body", | ||
body: requestBody, | ||
} as RequestBodyProps), | ||
createStatusCodes({ | ||
id: "callbacks-responses", | ||
label: "Callbacks Responses", | ||
responses, | ||
}), | ||
], | ||
}), | ||
]; | ||
}); | ||
}), | ||
}), | ||
], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/docusaurus-theme-openapi-docs/src/theme/OperationTabs/_OperationTabs.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.openapi-tabs__operation-container { | ||
display: flex; | ||
align-items: center; | ||
margin-top: 1rem; | ||
overflow: hidden; | ||
} | ||
|
||
.openapi-tabs__operation-item { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0.35rem 0.7rem; | ||
border: 1px solid transparent; | ||
margin-top: 0 !important; | ||
margin-right: 0.5rem; | ||
font-weight: var(--ifm-font-weight-bold); | ||
font-size: 12px; | ||
white-space: nowrap; | ||
transition: 300ms; | ||
|
||
&:hover { | ||
background-color: transparent; | ||
border: 1px solid var(--ifm-toc-border-color); | ||
} | ||
|
||
&.active { | ||
border: 1px solid var(--ifm-tabs-color-active-border); | ||
color: var(--ifm-tabs-color-active); | ||
} | ||
|
||
&:last-child { | ||
margin-right: 0 !important; | ||
} | ||
} | ||
|
||
.openapi-tabs__operation-list-container { | ||
overflow-y: hidden; | ||
overflow-x: scroll; | ||
scroll-behavior: smooth; | ||
|
||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
} | ||
|
||
.openapi-tabs__operation-schema-container { | ||
max-width: 600px; | ||
} | ||
|
||
@media screen and (max-width: 500px) { | ||
.operationTabsTopSection { | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
|
||
.operationTabsContainer { | ||
width: 100%; | ||
margin-top: var(--ifm-spacing-vertical); | ||
padding: 0; | ||
} | ||
} |
Oops, something went wrong.