Compare commits

...

3 Commits

Author SHA1 Message Date
github-actions[bot] e966e33e8f Version Packages (#2390)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-07-21 19:45:18 +02:00
Samy Pessé bd0ca5babd Fix @gitbook/react-openapi when react import are mandatory (#2389) 2024-07-21 19:43:50 +02:00
Samy Pessé f6bacea1ae Skip hidden pages in sitemap.xml (#2388) 2024-07-19 09:20:16 +02:00
15 changed files with 27 additions and 15 deletions
+6
View File
@@ -1,5 +1,11 @@
# @gitbook/react-openapi # @gitbook/react-openapi
## 0.3.0
### Minor Changes
- bd0ca5b: Fix missing react imports
## 0.2.0 ## 0.2.0
### Minor Changes ### Minor Changes
+2 -9
View File
@@ -1,12 +1,5 @@
# `@gitbook/react-openapi` # `@gitbook/react-openapi`
React components to render OpenAPI operations. Style-less React components to render OpenAPI operation blocks.
## Features Note: The package is a TypeScript package and do not expose JS built files.
- Generate code samples for the request
- Support custom cde samples with `x-codeSamples` (Redocly syntax)
## TODO
- Support for trying out the request
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@gitbook/react-openapi", "name": "@gitbook/react-openapi",
"exports": "./src/index.ts", "exports": "./src/index.ts",
"version": "0.2.0", "version": "0.3.0",
"dependencies": { "dependencies": {
"@scalar/api-client-react": "^0.3.7", "@scalar/api-client-react": "^0.3.7",
"@scalar/oas-utils": "0.1.6", "@scalar/oas-utils": "0.1.6",
+1
View File
@@ -1,3 +1,4 @@
import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
export function Markdown(props: { source: string; className?: string }) { export function Markdown(props: { source: string; className?: string }) {
@@ -1,4 +1,4 @@
import { OpenAPIV3 } from 'openapi-types'; import * as React from 'react';
import { CodeSampleInput, codeSampleGenerators } from './code-samples'; import { CodeSampleInput, codeSampleGenerators } from './code-samples';
import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation'; import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation';
@@ -1,3 +1,4 @@
import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation'; import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation';
@@ -1,3 +1,5 @@
import * as React from 'react';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIRootSchema } from './OpenAPISchema'; import { OpenAPIRootSchema } from './OpenAPISchema';
import { noReference } from './utils'; import { noReference } from './utils';
@@ -1,3 +1,4 @@
import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIRootSchema, OpenAPISchemaProperties } from './OpenAPISchema'; import { OpenAPIRootSchema, OpenAPISchemaProperties } from './OpenAPISchema';
@@ -1,3 +1,4 @@
import * as React from 'react';
import { InteractiveSection } from './InteractiveSection'; import { InteractiveSection } from './InteractiveSection';
import { OpenAPIOperationData } from './fetchOpenAPIOperation'; import { OpenAPIOperationData } from './fetchOpenAPIOperation';
import { generateSchemaExample } from './generateSchemaExample'; import { generateSchemaExample } from './generateSchemaExample';
@@ -1,3 +1,4 @@
import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { noReference } from './utils'; import { noReference } from './utils';
@@ -1,3 +1,4 @@
import * as React from 'react';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIClientContext } from './types'; import { OpenAPIClientContext } from './types';
import { InteractiveSection } from './InteractiveSection'; import { InteractiveSection } from './InteractiveSection';
@@ -1,3 +1,4 @@
import * as React from 'react';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIServerURLVariable } from './OpenAPIServerURLVariable'; import { OpenAPIServerURLVariable } from './OpenAPIServerURLVariable';
@@ -1,8 +1,8 @@
'use client'; 'use client';
import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import React from 'react';
/** /**
* Interactive component to show the value of a server variable and let the user change it. * Interactive component to show the value of a server variable and let the user change it.
@@ -1,5 +1,6 @@
'use client'; 'use client';
import * as React from 'react';
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { OpenAPIOperationData, fromJSON } from './fetchOpenAPIOperation'; import { OpenAPIOperationData, fromJSON } from './fetchOpenAPIOperation';
+6 -3
View File
@@ -15,7 +15,7 @@ export const runtime = 'edge';
*/ */
export async function GET(req: NextRequest) { export async function GET(req: NextRequest) {
const { pages: rootPages } = await getSpaceContentData(getContentPointer()); const { pages: rootPages } = await getSpaceContentData(getContentPointer());
const pages = flattenPages(rootPages); const pages = flattenPages(rootPages, (page) => !page.hidden);
const urls = pages.map(({ page, depth }) => { const urls = pages.map(({ page, depth }) => {
// Decay priority with depth // Decay priority with depth
const priority = Math.pow(2, -0.25 * depth); const priority = Math.pow(2, -0.25 * depth);
@@ -66,13 +66,16 @@ export async function GET(req: NextRequest) {
type FlatPageEntry = { page: RevisionPageDocument; depth: number }; type FlatPageEntry = { page: RevisionPageDocument; depth: number };
function flattenPages(rootPags: RevisionPage[]): FlatPageEntry[] { function flattenPages(
rootPags: RevisionPage[],
filter: (page: RevisionPageDocument) => boolean,
): FlatPageEntry[] {
const flattenPage = ( const flattenPage = (
page: RevisionPageDocument | RevisionPageGroup, page: RevisionPageDocument | RevisionPageGroup,
depth: number, depth: number,
): FlatPageEntry[] => { ): FlatPageEntry[] => {
return [ return [
...(page.type === 'document' ? [{ page, depth }] : []), ...(page.type === 'document' && filter(page) ? [{ page, depth }] : []),
...page.pages.flatMap((child) => ...page.pages.flatMap((child) =>
child.type === 'link' ? [] : flattenPage(child, depth + 1), child.type === 'link' ? [] : flattenPage(child, depth + 1),
), ),