(props: {
data: OpenAPIOperationData;
context: OpenAPIContext;
})
| 24 | * It supports the Redocly custom syntax as well (https://redocly.com/docs/api-reference-docs/specification-extensions/x-code-samples/) |
| 25 | */ |
| 26 | export function OpenAPICodeSample(props: { |
| 27 | data: OpenAPIOperationData; |
| 28 | context: OpenAPIContext; |
| 29 | }) { |
| 30 | const { data, context } = props; |
| 31 | |
| 32 | // If code samples are disabled at operation level, we don't display the code samples. |
| 33 | if (data.operation['x-codeSamples'] === false) { |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | const customCodeSamples = getCustomCodeSamples(props); |
| 38 | |
| 39 | // If code samples are disabled at the top-level and not custom code samples are defined, |
| 40 | // we don't display the code samples. |
| 41 | if (data['x-codeSamples'] === false && !customCodeSamples) { |
| 42 | return null; |
| 43 | } |
| 44 | |
| 45 | const samples = customCodeSamples ?? generateCodeSamples(props); |
| 46 | |
| 47 | if (samples.length === 0) { |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | return ( |
| 52 | <OpenAPICodeSampleBody |
| 53 | context={getOpenAPIClientContext(context)} |
| 54 | data={data} |
| 55 | items={samples} |
| 56 | selectIcon={context.icons.chevronDown} |
| 57 | /> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Generate code samples for the operation. |
nothing calls this directly
no test coverage detected