@@ -92,7 +96,7 @@ export const FieldDetailsComponent = observer((props: FieldProps) => {
{l('deprecated')}
)}
-
+
{!renderDiscriminatorSwitch && (
)}{' '}
diff --git a/src/components/RedocStandalone.tsx b/src/components/RedocStandalone.tsx
index 24ea13e0..abb83ace 100644
--- a/src/components/RedocStandalone.tsx
+++ b/src/components/RedocStandalone.tsx
@@ -34,7 +34,12 @@ export const RedocStandalone = function (props: RedocStandaloneProps) {
return (
-
+
{({ loading, store }) =>
!loading ? (
diff --git a/src/components/SchemaDefinition/SchemaDefinition.tsx b/src/components/SchemaDefinition/SchemaDefinition.tsx
index a3c5189f..b9398912 100644
--- a/src/components/SchemaDefinition/SchemaDefinition.tsx
+++ b/src/components/SchemaDefinition/SchemaDefinition.tsx
@@ -14,6 +14,7 @@ export interface ObjectDescriptionProps {
exampleRef?: string;
showReadOnly?: boolean;
showWriteOnly?: boolean;
+ showExample?: boolean;
parser: OpenAPIParser;
options: RedocNormalizedOptions;
}
@@ -53,7 +54,7 @@ export class SchemaDefinition extends React.PureComponent
@@ -64,11 +65,16 @@ export class SchemaDefinition extends React.PureComponent
-
-
-
-
-
+ {showExample && (
+
+
+
+
+
+ )}
);
diff --git a/src/components/SideMenu/MenuItem.tsx b/src/components/SideMenu/MenuItem.tsx
index 163b7d52..376e9afa 100644
--- a/src/components/SideMenu/MenuItem.tsx
+++ b/src/components/SideMenu/MenuItem.tsx
@@ -44,7 +44,7 @@ export class MenuItem extends React.Component {
render() {
const { item, withoutChildren } = this.props;
return (
-
+
{item.type === 'operation' ? (
) : (
diff --git a/src/components/SideMenu/styled.elements.ts b/src/components/SideMenu/styled.elements.ts
index 8ca79a1a..9ebeb212 100644
--- a/src/components/SideMenu/styled.elements.ts
+++ b/src/components/SideMenu/styled.elements.ts
@@ -125,7 +125,6 @@ export interface MenuItemLabelType {
}
export const MenuItemLabel = styled.label.attrs((props: MenuItemLabelType) => ({
- role: 'menuitem',
className: classnames('-depth' + props.depth, {
active: props.active,
}),
diff --git a/src/components/StoreBuilder.ts b/src/components/StoreBuilder.ts
index 14f8446d..6e8378c4 100644
--- a/src/components/StoreBuilder.ts
+++ b/src/components/StoreBuilder.ts
@@ -48,6 +48,9 @@ export function StoreBuilder(props: StoreBuilderProps) {
const resolved = await loadAndBundleSpec(spec || specUrl!);
setResolvedSpec(resolved);
} catch (e) {
+ if (onLoaded) {
+ onLoaded(e);
+ }
setError(e);
throw e;
}
diff --git a/src/components/__tests__/SchemaDefinition.test.tsx b/src/components/__tests__/SchemaDefinition.test.tsx
new file mode 100644
index 00000000..215f6ecb
--- /dev/null
+++ b/src/components/__tests__/SchemaDefinition.test.tsx
@@ -0,0 +1,82 @@
+/* tslint:disable:no-implicit-dependencies */
+
+import { shallow } from 'enzyme';
+import * as React from 'react';
+
+import { SchemaDefinition } from '..';
+import { OpenAPIParser } from '../../services';
+import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
+import { withTheme } from '../testProviders';
+
+const options = new RedocNormalizedOptions({});
+describe('Components', () => {
+ describe('SchemaDefinition', () => {
+ const parser = new OpenAPIParser(
+ {
+ openapi: '3.0',
+ info: {
+ title: 'test',
+ version: '0',
+ },
+ paths: {},
+ components: {
+ schemas: {
+ test: {
+ type: 'object',
+ properties: {
+ id: {
+ type: 'string',
+ },
+ },
+ },
+ },
+ },
+ },
+ undefined,
+ options,
+ );
+
+ describe('Show example constraints', () => {
+ it('should show the example as default', () => {
+ const component = shallow(
+ withTheme(
+ ,
+ ),
+ );
+ expect(component.html().includes('')).toBe(true);
+ });
+
+ it('should show the example if `showExample` is `true`', () => {
+ const component = shallow(
+ withTheme(
+ ,
+ ),
+ );
+ expect(component.html().includes('')).toBe(true);
+ });
+
+ it('should hide the example if `showExample` is `false`', () => {
+ const component = shallow(
+ withTheme(
+ ,
+ ),
+ );
+ expect(component.html().includes('')).toBe(false);
+ });
+ });
+ });
+});
diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts
index 61a755d5..1542cf7e 100644
--- a/src/services/OpenAPIParser.ts
+++ b/src/services/OpenAPIParser.ts
@@ -41,7 +41,7 @@ export class OpenAPIParser {
}
}
- validate(spec: GenericObject): void {
+ validate(spec: Record): void {
if (spec.openapi === undefined) {
throw new Error('Document must be valid OpenAPI 3.0.0 definition');
}
@@ -153,7 +153,7 @@ export class OpenAPIParser {
} else {
// small optimization
return {
- ...(resolved as GenericObject),
+ ...(resolved as object),
...rest,
} as T;
}
diff --git a/src/types/open-api.ts b/src/types/open-api.ts
index 75644062..fd80bf8d 100644
--- a/src/types/open-api.ts
+++ b/src/types/open-api.ts
@@ -1,4 +1,4 @@
-import { Omit } from './index';
+import type { Omit } from './index';
export interface OpenAPISpec {
openapi: string;
diff --git a/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap b/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap
index 4e7fea79..ecdf3e21 100644
--- a/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap
+++ b/src/utils/__tests__/__snapshots__/loadAndBundleSpec.test.ts.snap
@@ -1743,6 +1743,9 @@ culpa qui officia deserunt mollit anim id est laborum.
},
},
},
+ "security": Array [
+ Object {},
+ ],
"servers": Array [
Object {
"description": "Default server",
@@ -3729,6 +3732,9 @@ culpa qui officia deserunt mollit anim id est laborum.
},
},
},
+ "security": Array [
+ Object {},
+ ],
"servers": Array [
Object {
"description": "Default server",
diff --git a/src/utils/object.ts b/src/utils/object.ts
index 1a220764..6efaab15 100644
--- a/src/utils/object.ts
+++ b/src/utils/object.ts
@@ -1,4 +1,4 @@
-export function objectHas(object: GenericObject, path: string | Array): boolean {
+export function objectHas(object: object, path: string | Array): boolean {
let _path = >path;
if (typeof path === 'string') {
@@ -12,7 +12,7 @@ export function objectHas(object: GenericObject, path: string | Array):
});
}
-export function objectSet(object: GenericObject, path: string | Array, value: any): void {
+export function objectSet(object: object, path: string | Array, value: any): void {
let _path = >path;
if (typeof path === 'string') {