mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-29 17:40:05 +03:00
Merge branch 'master' into feat/add-reference-to-api-on-schema
This commit is contained in:
commit
2c281e0822
|
@ -51,8 +51,10 @@ export const Badge = styled.span<{ type: string }>`
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 2px 8px;
|
padding: 2px 8px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: ${props => props.theme.colors[props.type].main};
|
background-color: ${props =>
|
||||||
color: ${props => props.theme.colors[props.type].contrastText};
|
props.type == 'm2m' ? 'none' : props.theme.colors[props.type].main};
|
||||||
|
border: ${props => (props.type == 'm2m' ? 'rgba(38, 50, 56, 0.5) 1px solid' : 'none')};
|
||||||
|
color: ${props => (props.type == 'm2m' ? 'black' : props.theme.colors[props.type].contrastText)};
|
||||||
font-size: ${props => props.theme.typography.code.fontSize};
|
font-size: ${props => props.theme.typography.code.fontSize};
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
|
|
|
@ -35,6 +35,7 @@ export const FieldDetailsComponent = observer((props: FieldProps) => {
|
||||||
schema,
|
schema,
|
||||||
description,
|
description,
|
||||||
deprecated,
|
deprecated,
|
||||||
|
m2m,
|
||||||
extensions,
|
extensions,
|
||||||
in: _in,
|
in: _in,
|
||||||
const: _const,
|
const: _const,
|
||||||
|
@ -107,6 +108,11 @@ export const FieldDetailsComponent = observer((props: FieldProps) => {
|
||||||
<Badge type="warning"> {l('deprecated')} </Badge>
|
<Badge type="warning"> {l('deprecated')} </Badge>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{m2m && (
|
||||||
|
<div>
|
||||||
|
<Badge type="m2m"> M2M </Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<FieldDetail raw={rawDefault} label={l('default') + ':'} value={defaultValue} />
|
<FieldDetail raw={rawDefault} label={l('default') + ':'} value={defaultValue} />
|
||||||
{!renderDiscriminatorSwitch && (
|
{!renderDiscriminatorSwitch && (
|
||||||
<EnumValues isArrayType={isArrayType} values={schema.enum} />
|
<EnumValues isArrayType={isArrayType} values={schema.enum} />
|
||||||
|
|
|
@ -28,7 +28,15 @@ export interface OperationProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Operation = observer(({ operation }: OperationProps): JSX.Element => {
|
export const Operation = observer(({ operation }: OperationProps): JSX.Element => {
|
||||||
const { name: summary, description, deprecated, externalDocs, isWebhook, httpVerb } = operation;
|
const {
|
||||||
|
name: summary,
|
||||||
|
description,
|
||||||
|
deprecated,
|
||||||
|
externalDocs,
|
||||||
|
isWebhook,
|
||||||
|
httpVerb,
|
||||||
|
m2m,
|
||||||
|
} = operation;
|
||||||
const hasDescription = !!(description || externalDocs);
|
const hasDescription = !!(description || externalDocs);
|
||||||
const { showWebhookVerb } = React.useContext(OptionsContext);
|
const { showWebhookVerb } = React.useContext(OptionsContext);
|
||||||
return (
|
return (
|
||||||
|
@ -39,6 +47,7 @@ export const Operation = observer(({ operation }: OperationProps): JSX.Element =
|
||||||
<H2>
|
<H2>
|
||||||
<ShareLink to={operation.id} />
|
<ShareLink to={operation.id} />
|
||||||
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
|
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
|
||||||
|
{m2m && <Badge type="m2m"> M2M </Badge>}
|
||||||
{isWebhook && (
|
{isWebhook && (
|
||||||
<Badge type="primary">
|
<Badge type="primary">
|
||||||
{' '}
|
{' '}
|
||||||
|
|
|
@ -60,6 +60,7 @@ export class OneOfSchema extends React.Component<SchemaProps> {
|
||||||
</OneOfList>
|
</OneOfList>
|
||||||
<div>
|
<div>
|
||||||
{oneOf[schema.activeOneOf].deprecated && <Badge type="warning">Deprecated</Badge>}
|
{oneOf[schema.activeOneOf].deprecated && <Badge type="warning">Deprecated</Badge>}
|
||||||
|
{oneOf[schema.activeOneOf].m2m && <Badge type="m2m">M2M</Badge>}
|
||||||
</div>
|
</div>
|
||||||
<ConstraintsView constraints={activeSchema.constraints} />
|
<ConstraintsView constraints={activeSchema.constraints} />
|
||||||
<Schema {...this.props} schema={activeSchema} />
|
<Schema {...this.props} schema={activeSchema} />
|
||||||
|
|
|
@ -58,6 +58,8 @@ export class AppStore {
|
||||||
private scroll: ScrollService;
|
private scroll: ScrollService;
|
||||||
private disposer: Lambda | null = null;
|
private disposer: Lambda | null = null;
|
||||||
|
|
||||||
|
private readonly listener: EventListenerOrEventListenerObject = this.updateOnEvent.bind(this);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
spec: OpenAPISpec,
|
spec: OpenAPISpec,
|
||||||
specUrl?: string,
|
specUrl?: string,
|
||||||
|
@ -73,7 +75,7 @@ export class AppStore {
|
||||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||||
|
|
||||||
// Listen for external event to update
|
// Listen for external event to update
|
||||||
window.addEventListener('redocUpdatePosition', this.updateOnEvent);
|
window.addEventListener('redocUpdatePosition', this.listener);
|
||||||
|
|
||||||
// override the openApi standard to version 3.1.0
|
// override the openApi standard to version 3.1.0
|
||||||
// TODO remove when fully supporting open API 3.1.0
|
// TODO remove when fully supporting open API 3.1.0
|
||||||
|
@ -101,7 +103,7 @@ export class AppStore {
|
||||||
dispose() {
|
dispose() {
|
||||||
this.scroll.dispose();
|
this.scroll.dispose();
|
||||||
this.menu.dispose();
|
this.menu.dispose();
|
||||||
window.removeEventListener('redocUpdatePosition', this.updateOnEvent);
|
window.removeEventListener('redocUpdatePosition', this.listener);
|
||||||
if (this.search) {
|
if (this.search) {
|
||||||
this.search.dispose();
|
this.search.dispose();
|
||||||
}
|
}
|
||||||
|
@ -129,10 +131,6 @@ export class AppStore {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateOnEvent(): void {
|
|
||||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateMarkOnMenu(idx: number) {
|
private updateMarkOnMenu(idx: number) {
|
||||||
const start = Math.max(0, idx);
|
const start = Math.max(0, idx);
|
||||||
const end = Math.min(this.menu.flatItems.length, start + 5);
|
const end = Math.min(this.menu.flatItems.length, start + 5);
|
||||||
|
@ -157,6 +155,10 @@ export class AppStore {
|
||||||
this.marker.addOnly(elements);
|
this.marker.addOnly(elements);
|
||||||
this.marker.mark();
|
this.marker.mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateOnEvent(): void {
|
||||||
|
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_OPTIONS: RedocRawOptions = {
|
const DEFAULT_OPTIONS: RedocRawOptions = {
|
||||||
|
|
|
@ -51,6 +51,7 @@ export class FieldModel {
|
||||||
example?: string;
|
example?: string;
|
||||||
examples?: Record<string, ExampleModel> | any[];
|
examples?: Record<string, ExampleModel> | any[];
|
||||||
deprecated: boolean;
|
deprecated: boolean;
|
||||||
|
m2m: boolean;
|
||||||
in?: OpenAPIParameterLocation;
|
in?: OpenAPIParameterLocation;
|
||||||
kind: string;
|
kind: string;
|
||||||
extensions?: Record<string, any>;
|
extensions?: Record<string, any>;
|
||||||
|
@ -135,6 +136,7 @@ export class FieldModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
||||||
|
this.m2m = info.m2m === undefined ? !!this.schema.m2m : info.m2m;
|
||||||
|
|
||||||
if (options.showExtensions) {
|
if (options.showExtensions) {
|
||||||
this.extensions = extractExtensions(info, options.showExtensions);
|
this.extensions = extractExtensions(info, options.showExtensions);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import type { OpenAPIParser } from '../OpenAPIParser';
|
||||||
import type { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
import type { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
||||||
import type { MediaContentModel } from './MediaContent';
|
import type { MediaContentModel } from './MediaContent';
|
||||||
import type { ContentItemModel, ExtendedOpenAPIOperation, IMenuItem } from '../types';
|
import type { ContentItemModel, ExtendedOpenAPIOperation, IMenuItem } from '../types';
|
||||||
|
import { MilesConstants } from '../../types';
|
||||||
|
|
||||||
export interface XPayloadSample {
|
export interface XPayloadSample {
|
||||||
lang: 'payload';
|
lang: 'payload';
|
||||||
|
@ -72,6 +73,7 @@ export class OperationModel implements IMenuItem {
|
||||||
operationHash?: string;
|
operationHash?: string;
|
||||||
httpVerb: string;
|
httpVerb: string;
|
||||||
deprecated: boolean;
|
deprecated: boolean;
|
||||||
|
m2m: boolean;
|
||||||
path: string;
|
path: string;
|
||||||
servers: OpenAPIServer[];
|
servers: OpenAPIServer[];
|
||||||
security: SecurityRequirementModel[];
|
security: SecurityRequirementModel[];
|
||||||
|
@ -96,6 +98,9 @@ export class OperationModel implements IMenuItem {
|
||||||
this.externalDocs = operationSpec.externalDocs;
|
this.externalDocs = operationSpec.externalDocs;
|
||||||
|
|
||||||
this.deprecated = !!operationSpec.deprecated;
|
this.deprecated = !!operationSpec.deprecated;
|
||||||
|
this.m2m = !!extractExtensions(operationSpec, [MilesConstants.MILES_M2M])?.[
|
||||||
|
MilesConstants.MILES_M2M
|
||||||
|
];
|
||||||
this.httpVerb = operationSpec.httpVerb;
|
this.httpVerb = operationSpec.httpVerb;
|
||||||
this.deprecated = !!operationSpec.deprecated;
|
this.deprecated = !!operationSpec.deprecated;
|
||||||
this.operationId = operationSpec.operationId;
|
this.operationId = operationSpec.operationId;
|
||||||
|
|
|
@ -44,6 +44,7 @@ export class SchemaModel {
|
||||||
displayFormat?: string;
|
displayFormat?: string;
|
||||||
nullable: boolean;
|
nullable: boolean;
|
||||||
deprecated: boolean;
|
deprecated: boolean;
|
||||||
|
m2m: boolean;
|
||||||
pattern?: string;
|
pattern?: string;
|
||||||
example?: any;
|
example?: any;
|
||||||
examples?: any[];
|
examples?: any[];
|
||||||
|
@ -126,6 +127,9 @@ export class SchemaModel {
|
||||||
this.example = schema.example;
|
this.example = schema.example;
|
||||||
this.examples = schema.examples;
|
this.examples = schema.examples;
|
||||||
this.deprecated = !!schema.deprecated;
|
this.deprecated = !!schema.deprecated;
|
||||||
|
this.m2m = !!extractExtensions(this.schema, [MilesConstants.MILES_M2M])?.[
|
||||||
|
MilesConstants.MILES_M2M
|
||||||
|
];
|
||||||
this.pattern = schema.pattern;
|
this.pattern = schema.pattern;
|
||||||
this.externalDocs = schema.externalDocs;
|
this.externalDocs = schema.externalDocs;
|
||||||
|
|
||||||
|
|
13
src/theme.ts
13
src/theme.ts
|
@ -21,9 +21,15 @@ const defaultTheme: ThemeInterface = {
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
main: '#D47D17',
|
main: '#D47D17',
|
||||||
light: ({ colors }) => lighten(colors.tonalOffset, colors.primary.main),
|
light: ({ colors }) => lighten(colors.tonalOffset, colors.secondary.main),
|
||||||
dark: ({ colors }) => darken(colors.tonalOffset, colors.primary.main),
|
dark: ({ colors }) => darken(colors.tonalOffset, colors.secondary.main),
|
||||||
contrastText: ({ colors }) => readableColor(colors.primary.main),
|
contrastText: ({ colors }) => readableColor(colors.secondary.main),
|
||||||
|
},
|
||||||
|
m2m: {
|
||||||
|
main: '#343A40',
|
||||||
|
light: ({ colors }) => lighten(colors.tonalOffset, colors.m2m.main),
|
||||||
|
dark: ({ colors }) => darken(colors.tonalOffset, colors.m2m.main),
|
||||||
|
contrastText: ({ colors }) => readableColor(colors.m2m.main),
|
||||||
},
|
},
|
||||||
success: {
|
success: {
|
||||||
main: '#1d8127',
|
main: '#1d8127',
|
||||||
|
@ -271,6 +277,7 @@ export interface ResolvedThemeInterface {
|
||||||
tonalOffset: number;
|
tonalOffset: number;
|
||||||
primary: ColorSetting;
|
primary: ColorSetting;
|
||||||
secondary: ColorSetting;
|
secondary: ColorSetting;
|
||||||
|
m2m: ColorSetting;
|
||||||
success: ColorSetting;
|
success: ColorSetting;
|
||||||
warning: ColorSetting;
|
warning: ColorSetting;
|
||||||
error: ColorSetting;
|
error: ColorSetting;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export const MilesConstants = {
|
export const MilesConstants = {
|
||||||
MILES_EXTRA_DESCRIPTION_PROPERTY_NAME: 'x-miles-extra-description',
|
MILES_EXTRA_DESCRIPTION_PROPERTY_NAME: 'x-miles-extra-description',
|
||||||
MILES_VALIDATION_MODEL_PROPERTY_NAME: 'x-miles-validation-model',
|
MILES_VALIDATION_MODEL_PROPERTY_NAME: 'x-miles-validation-model',
|
||||||
|
MILES_M2M: 'x-miles-m2m',
|
||||||
HIDE_LOGO_QUERY_PARAM: 'hideLogo',
|
HIDE_LOGO_QUERY_PARAM: 'hideLogo',
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,6 +93,7 @@ export interface OpenAPIParameter {
|
||||||
description?: string;
|
description?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
deprecated?: boolean;
|
deprecated?: boolean;
|
||||||
|
m2m?: boolean;
|
||||||
allowEmptyValue?: boolean;
|
allowEmptyValue?: boolean;
|
||||||
style?: OpenAPIParameterStyle;
|
style?: OpenAPIParameterStyle;
|
||||||
explode?: boolean;
|
explode?: boolean;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user