mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +03:00
parent
99bef64d37
commit
00bd966797
|
@ -173,6 +173,7 @@ Operation code sample
|
||||||
| Field Name | Type | Description |
|
| Field Name | Type | Description |
|
||||||
| :---------- | :------: | :----------- |
|
| :---------- | :------: | :----------- |
|
||||||
| lang | string | Code sample language. Value should be one of the following [list](https://github.com/github/linguist/blob/master/lib/linguist/popular.yml) |
|
| lang | string | Code sample language. Value should be one of the following [list](https://github.com/github/linguist/blob/master/lib/linguist/popular.yml) |
|
||||||
|
| label | string? | Code sample label e.g. `Node` or `Python2.7`, _optional_, `lang` will be used by default |
|
||||||
| source | string | Code sample source code |
|
| source | string | Code sample source code |
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,16 @@ export class RequestSamples extends React.Component<RequestSamplesProps> {
|
||||||
<Tabs defaultIndex={0}>
|
<Tabs defaultIndex={0}>
|
||||||
<TabList>
|
<TabList>
|
||||||
{hasBodySample && <Tab key="payload"> Payload </Tab>}
|
{hasBodySample && <Tab key="payload"> Payload </Tab>}
|
||||||
{samples.map(sample => <Tab key={sample.lang}>{sample.lang}</Tab>)}
|
{samples.map(sample => (
|
||||||
|
<Tab key={sample.lang}>
|
||||||
|
{sample.label !== undefined ? sample.label : sample.lang}
|
||||||
|
</Tab>
|
||||||
|
))}
|
||||||
</TabList>
|
</TabList>
|
||||||
{hasBodySample && (
|
{hasBodySample && (
|
||||||
<TabPanel key="payload">
|
<TabPanel key="payload">
|
||||||
<div>
|
<div>
|
||||||
{' '}
|
<PayloadSamples content={requestBodyContent!} />
|
||||||
<PayloadSamples content={requestBodyContent!} />{' '}
|
|
||||||
</div>
|
</div>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { IMenuItem } from '../MenuStore';
|
||||||
import { GroupModel } from './Group.model';
|
import { GroupModel } from './Group.model';
|
||||||
import { SecurityRequirementModel } from './SecurityRequirement';
|
import { SecurityRequirementModel } from './SecurityRequirement';
|
||||||
|
|
||||||
import { OpenAPIExternalDocumentation, OpenAPIServer } from '../../types';
|
import { OpenAPIExternalDocumentation, OpenAPIServer, OpenAPIXCodeSample } from '../../types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getOperationSummary,
|
getOperationSummary,
|
||||||
|
@ -22,7 +22,7 @@ import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
||||||
import { FieldModel } from './Field';
|
import { FieldModel } from './Field';
|
||||||
import { RequestBodyModel } from './RequestBody';
|
import { RequestBodyModel } from './RequestBody';
|
||||||
import { ResponseModel } from './Response';
|
import { ResponseModel } from './Response';
|
||||||
import { CodeSample } from './types';
|
|
||||||
/**
|
/**
|
||||||
* Operation model ready to be used by components
|
* Operation model ready to be used by components
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,7 @@ export class OperationModel implements IMenuItem {
|
||||||
path: string;
|
path: string;
|
||||||
servers: OpenAPIServer[];
|
servers: OpenAPIServer[];
|
||||||
security: SecurityRequirementModel[];
|
security: SecurityRequirementModel[];
|
||||||
codeSamples: CodeSample[];
|
codeSamples: OpenAPIXCodeSample[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private parser: OpenAPIParser,
|
private parser: OpenAPIParser,
|
||||||
|
|
|
@ -9,5 +9,4 @@ export * from './Response';
|
||||||
export * from './Schema';
|
export * from './Schema';
|
||||||
export * from './Field';
|
export * from './Field';
|
||||||
export * from './ApiInfo';
|
export * from './ApiInfo';
|
||||||
export * from './types';
|
|
||||||
export * from './SecuritySchemes';
|
export * from './SecuritySchemes';
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
export interface CodeSample {
|
|
||||||
lang: string;
|
|
||||||
source: string;
|
|
||||||
}
|
|
1
src/types/open-api.d.ts
vendored
1
src/types/open-api.d.ts
vendored
|
@ -59,6 +59,7 @@ export interface OpenAPIPath {
|
||||||
|
|
||||||
export interface OpenAPIXCodeSample {
|
export interface OpenAPIXCodeSample {
|
||||||
lang: string;
|
lang: string;
|
||||||
|
label?: string;
|
||||||
source: string;
|
source: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ export function mapLang(lang: string): string {
|
||||||
* @return highlighted souce code as **html string**
|
* @return highlighted souce code as **html string**
|
||||||
*/
|
*/
|
||||||
export function highlight(source: string, lang: string): string {
|
export function highlight(source: string, lang: string): string {
|
||||||
|
lang = lang.toLowerCase();
|
||||||
let grammar = Prism.languages[lang];
|
let grammar = Prism.languages[lang];
|
||||||
if (!grammar) {
|
if (!grammar) {
|
||||||
grammar = Prism.languages[mapLang(lang)];
|
grammar = Prism.languages[mapLang(lang)];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user