-
Notifications
You must be signed in to change notification settings - Fork 281
Add Callbacks support #691
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
Merged
sserrata
merged 7 commits into
PaloAltoNetworks:main
from
lucasassisrosa:DOTCOM-2899-support-callbacks
Jan 9, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
120c018
add support to callbacks in openapi specs
lucasassisrosa 72937fb
set package manager in package json
lucasassisrosa 9a048e9
implement operations as tabs within request panel
lucasassisrosa dc578d3
render callbacks below Request and Responses
lucasassisrosa 42ea4a4
remove unwanted files
lucasassisrosa cb41ff4
rename create file
lucasassisrosa 980324d
restore json settings
lucasassisrosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
sserrata marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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": "yarn@1.22.1" | ||
} |
95 changes: 95 additions & 0 deletions
95
packages/docusaurus-plugin-openapi-docs/src/markdown/createCallbacks.ts
This file contains hidden or 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, | ||
}), | ||
], | ||
}), | ||
]; | ||
}); | ||
}), | ||
}), | ||
], | ||
}); | ||
} |
sserrata marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.