Skip to content

RND-2311: enums for server url in openapi block #2452

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

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
4d476a8
Select variables in server url
BrettJephson Aug 27, 2024
7e79e14
Update server url based on variable selection
BrettJephson Sep 3, 2024
e852206
Update server choice based on selection
BrettJephson Sep 12, 2024
cb454a3
Format
BrettJephson Sep 12, 2024
ca4518d
Changeset
BrettJephson Sep 12, 2024
2d15453
Revised client state with context
BrettJephson Sep 20, 2024
d919d2c
Add icons for editing url
BrettJephson Sep 20, 2024
adaf0de
Fix type
BrettJephson Sep 20, 2024
69414bd
Formatting
BrettJephson Sep 20, 2024
3b0f5d8
Add server url cache to update request code sample
BrettJephson Sep 24, 2024
087a783
Formatting
BrettJephson Sep 24, 2024
9573535
Update icon
BrettJephson Sep 24, 2024
e793a17
Select variables in server url
BrettJephson Aug 27, 2024
b87ec84
Update server url based on variable selection
BrettJephson Sep 3, 2024
4f59d18
Update server choice based on selection
BrettJephson Sep 12, 2024
c338bca
Format
BrettJephson Sep 12, 2024
7244a04
Changeset
BrettJephson Sep 12, 2024
d29a7a6
Revised client state with context
BrettJephson Sep 20, 2024
a6adfaa
Add icons for editing url
BrettJephson Sep 20, 2024
3d14790
Fix type
BrettJephson Sep 20, 2024
28c59d8
Formatting
BrettJephson Sep 20, 2024
96d5537
Add server url cache to update request code sample
BrettJephson Sep 24, 2024
768b555
Formatting
BrettJephson Sep 24, 2024
ea4f70e
Update icon
BrettJephson Sep 24, 2024
0b44528
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Sep 24, 2024
949f25c
Merge branch 'brett/RND-2311-openapi-enum' of github.com:GitbookIO/gi…
BrettJephson Sep 24, 2024
f6b75e7
Self review changes
BrettJephson Sep 24, 2024
4b9f206
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Sep 25, 2024
4026fc1
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Sep 25, 2024
8d1c349
Don't make server url editable if no update function or context
BrettJephson Sep 25, 2024
5b93377
Merge remote-tracking branch 'origin/main' into brett/RND-2311-openap…
BrettJephson Oct 1, 2024
ce890c6
Refactor - naming and comments
BrettJephson Oct 2, 2024
cb3c1f9
Formatting
BrettJephson Oct 2, 2024
abf7ec3
Remove unused imports
BrettJephson Oct 2, 2024
f98b7b2
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Oct 2, 2024
39d8886
Formatting
BrettJephson Oct 2, 2024
586e66d
Update comment
BrettJephson Oct 2, 2024
60a9b95
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Oct 3, 2024
c1193fd
Select variables in server url
BrettJephson Aug 27, 2024
1ae1715
Update server url based on variable selection
BrettJephson Sep 3, 2024
77d64d0
Update server choice based on selection
BrettJephson Sep 12, 2024
9437aa2
Format
BrettJephson Sep 12, 2024
f6823e9
Changeset
BrettJephson Sep 12, 2024
ac492e0
Revised client state with context
BrettJephson Sep 20, 2024
f65e3f5
Add icons for editing url
BrettJephson Sep 20, 2024
f67b143
Fix type
BrettJephson Sep 20, 2024
9b78692
Formatting
BrettJephson Sep 20, 2024
184d616
Add server url cache to update request code sample
BrettJephson Sep 24, 2024
74392ec
Formatting
BrettJephson Sep 24, 2024
7b02f72
Update icon
BrettJephson Sep 24, 2024
dce39c4
Update server url based on variable selection
BrettJephson Sep 3, 2024
e866080
Update server choice based on selection
BrettJephson Sep 12, 2024
662df6f
Format
BrettJephson Sep 12, 2024
65d7729
Revised client state with context
BrettJephson Sep 20, 2024
2d4ddc9
Formatting
BrettJephson Sep 20, 2024
c7ca921
Self review changes
BrettJephson Sep 24, 2024
9675290
Don't make server url editable if no update function or context
BrettJephson Sep 25, 2024
95e8772
Refactor - naming and comments
BrettJephson Oct 2, 2024
0ccc503
Formatting
BrettJephson Oct 2, 2024
3ee149d
Remove unused imports
BrettJephson Oct 2, 2024
152aad2
Update comment
BrettJephson Oct 2, 2024
d19e350
Merge branch 'brett/RND-2311-openapi-enum' of github.com:GitbookIO/gi…
BrettJephson Oct 9, 2024
5beb2db
Tidy
BrettJephson Oct 9, 2024
3d9aefa
Merge remote-tracking branch 'origin/main' into brett/RND-2311-openap…
BrettJephson Oct 14, 2024
846de0e
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Oct 18, 2024
d9ee1a7
Merge branch 'main' into brett/RND-2311-openapi-enum
BrettJephson Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatting
  • Loading branch information
BrettJephson committed Oct 9, 2024
commit 0ccc5034c48b1e3e30410b3215dc6e73ebc6a9ad
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {

// To update the code sample we need to re-render the server component
// so reading the cached value from search params
const serverUrl = serverUrlCache.get('serverUrl');
const serverUrl = serverUrlCache.get('serverUrl');

return (
<OpenAPIClientStateContainer block={block} servers={data.servers}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OpenAPIV3 } from 'openapi-types';
import * as React from 'react';

/**
* Client component that wraps `OpenAPIClientState` so we can
* Client component that wraps `OpenAPIClientState` so we can
* use some hooks (e.g. useRouter) in the `onUpdate` callback.
*/
export default function OpenAPIClientStateContainer(props: {
Expand Down
5 changes: 4 additions & 1 deletion packages/react-openapi/src/OpenAPIClientStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export function OpenAPIClientState(props: {
);
}

function parseClientStateModifiers(servers: OpenAPIV3.ServerObject[], params: Record<string, string>) {
function parseClientStateModifiers(
servers: OpenAPIV3.ServerObject[],
params: Record<string, string>,
) {
if (!servers) {
return null;
}
Expand Down
10 changes: 7 additions & 3 deletions packages/react-openapi/src/OpenAPIServerURL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ export function OpenAPIServerURL(props: {
const { path, servers, context } = props;
const stateContext = useOpenAPIClientState();

const serverIndex = !isNaN(Number(stateContext?.state?.server)) ? Number(stateContext?.state?.server) : 0;
const serverIndex = !isNaN(Number(stateContext?.state?.server))
? Number(stateContext?.state?.server)
: 0;
const server = servers[serverIndex];
const parts = parseServerURL(server?.url ?? '');

if (!server) { return null; }
if (!server) {
return null;
}

return (
<ServerURLForm context={context} servers={servers} serverIndex={serverIndex}>
<span className={classNames(stateContext?.isPending && "openapi-pending")}>
<span className={classNames(stateContext?.isPending && 'openapi-pending')}>
{parts.map((part, i) => {
if (part.kind === 'text') {
return <span key={i}>{part.text}</span>;
Expand Down
8 changes: 3 additions & 5 deletions packages/react-openapi/src/OpenAPIServerURLForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export function ServerURLForm(props: {
});
}

// Only make the server url editable if there is some onUpdate callback
// Only make the server url editable if there is some onUpdate callback
// and if there are variations on the server url (e.g. an array of servers or url variables).
const isEditable = stateContext?.onUpdate && (servers.length > 1 || server.variables);
const isEditable = stateContext?.onUpdate && (servers.length > 1 || server.variables);
const isEditing = isEditable && stateContext?.state?.edit;
return (
<form
Expand Down Expand Up @@ -89,9 +89,7 @@ export function ServerURLForm(props: {
: { edit: 'true' }),
});
}}
title={
isEditing ? undefined : 'Try different server options'
}
title={isEditing ? undefined : 'Try different server options'}
aria-label={isEditing ? 'Clear' : 'Edit'}
>
{isEditing ? context.icons.editDone : context.icons.edit}
Expand Down