feat(): add m2m badge to operations and fields

This commit is contained in:
Depickere Sven 2023-04-26 16:04:31 +01:00
parent 21279e1d9f
commit fc58641560
9 changed files with 40 additions and 4 deletions

View File

@ -34,6 +34,7 @@ export const FieldDetailsComponent = observer((props: FieldProps) => {
schema, schema,
description, description,
deprecated, deprecated,
m2m,
extensions, extensions,
in: _in, in: _in,
const: _const, const: _const,
@ -105,6 +106,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} />

View File

@ -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">
{' '} {' '}

View File

@ -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} />

View File

@ -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>;
@ -119,6 +120,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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,5 @@
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_M2M: 'x-miles-m2m',
HIDE_LOGO_QUERY_PARAM: 'hideLogo', HIDE_LOGO_QUERY_PARAM: 'hideLogo',
}; };

View File

@ -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;