1
1
import clsx from 'clsx' ;
2
-
3
- import type {
4
- OpenAPICustomOperationProperties ,
5
- OpenAPIStability ,
6
- OpenAPIV3 ,
7
- } from '@gitbook/openapi-parser' ;
8
- import { Markdown } from './Markdown' ;
9
2
import { OpenAPICodeSample } from './OpenAPICodeSample' ;
10
- import { OpenAPIPath } from './OpenAPIPath' ;
11
3
import { OpenAPIResponseExample } from './OpenAPIResponseExample' ;
12
- import { OpenAPISpec } from './OpenAPISpec ' ;
13
- import { getOpenAPIClientContext } from './context ' ;
4
+ import { OpenAPIColumnSpec } from './common/OpenAPIColumnSpec ' ;
5
+ import { OpenAPISummary } from './common/OpenAPISummary ' ;
14
6
import type { OpenAPIContext , OpenAPIOperationData } from './types' ;
15
- import { resolveDescription } from './utils' ;
16
7
17
8
/**
18
9
* Display an interactive OpenAPI operation.
@@ -23,46 +14,12 @@ export function OpenAPIOperation(props: {
23
14
context : OpenAPIContext ;
24
15
} ) {
25
16
const { className, data, context } = props ;
26
- const { operation } = data ;
27
-
28
- const clientContext = getOpenAPIClientContext ( context ) ;
29
17
30
18
return (
31
19
< div className = { clsx ( 'openapi-operation' , className ) } >
32
- < div className = "openapi-summary" id = { operation . summary ? undefined : context . id } >
33
- { ( operation . deprecated || operation [ 'x-stability' ] ) && (
34
- < div className = "openapi-summary-tags" >
35
- { operation . deprecated && (
36
- < div className = "openapi-deprecated" > Deprecated</ div >
37
- ) }
38
- { operation [ 'x-stability' ] && (
39
- < OpenAPIOperationStability stability = { operation [ 'x-stability' ] } />
40
- ) }
41
- </ div >
42
- ) }
43
- { operation . summary
44
- ? context . renderHeading ( {
45
- deprecated : operation . deprecated ?? false ,
46
- stability : operation [ 'x-stability' ] ,
47
- title : operation . summary ,
48
- } )
49
- : null }
50
- < OpenAPIPath data = { data } />
51
- </ div >
20
+ < OpenAPISummary data = { data } context = { context } />
52
21
< div className = "openapi-columns" >
53
- < div className = "openapi-column-spec" >
54
- { operation [ 'x-deprecated-sunset' ] ? (
55
- < div className = "openapi-deprecated-sunset openapi-description openapi-markdown" >
56
- This operation is deprecated and will be sunset on{ ' ' }
57
- < span className = "openapi-deprecated-sunset-date" >
58
- { operation [ 'x-deprecated-sunset' ] }
59
- </ span >
60
- { '.' }
61
- </ div >
62
- ) : null }
63
- < OpenAPIOperationDescription operation = { operation } context = { context } />
64
- < OpenAPISpec data = { data } context = { clientContext } />
65
- </ div >
22
+ < OpenAPIColumnSpec data = { data } context = { context } />
66
23
< div className = "openapi-column-preview" >
67
24
< div className = "openapi-column-preview-body" >
68
25
< OpenAPICodeSample { ...props } />
@@ -73,52 +30,3 @@ export function OpenAPIOperation(props: {
73
30
</ div >
74
31
) ;
75
32
}
76
-
77
- function OpenAPIOperationDescription ( props : {
78
- operation : OpenAPIV3 . OperationObject < OpenAPICustomOperationProperties > ;
79
- context : OpenAPIContext ;
80
- } ) {
81
- const { operation } = props ;
82
- if ( operation [ 'x-gitbook-description-document' ] ) {
83
- return (
84
- < div className = "openapi-intro" >
85
- { props . context . renderDocument ( {
86
- document : operation [ 'x-gitbook-description-document' ] ,
87
- } ) }
88
- </ div >
89
- ) ;
90
- }
91
-
92
- const description = resolveDescription ( operation ) ;
93
- if ( ! description ) {
94
- return null ;
95
- }
96
-
97
- return (
98
- < div className = "openapi-intro" >
99
- < Markdown className = "openapi-description" source = { description } />
100
- </ div >
101
- ) ;
102
- }
103
-
104
- const stabilityEnum = {
105
- experimental : 'Experimental' ,
106
- alpha : 'Alpha' ,
107
- beta : 'Beta' ,
108
- } as const ;
109
-
110
- function OpenAPIOperationStability ( props : { stability : OpenAPIStability } ) {
111
- const { stability } = props ;
112
-
113
- const foundStability = stabilityEnum [ stability ] ;
114
-
115
- if ( ! foundStability ) {
116
- return null ;
117
- }
118
-
119
- return (
120
- < div className = { `openapi-stability openapi-stability-${ foundStability . toLowerCase ( ) } ` } >
121
- { foundStability }
122
- </ div >
123
- ) ;
124
- }
0 commit comments