Skip to content

Commit

Permalink
fix: rewrite recursive checks (#2072)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Hotsiy <[email protected]>
  • Loading branch information
AlexVarchuk and RomanHotsiy authored Jul 18, 2022
1 parent 9920991 commit 2970f95
Show file tree
Hide file tree
Showing 46 changed files with 1,300 additions and 500 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"license-checker": "^25.0.1",
"lodash.noop": "^3.0.1",
"mobx": "^6.3.2",
"outdent": "^0.8.0",
"prettier": "^2.3.2",
"pretty-quick": "^3.0.0",
"raf": "^3.4.1",
Expand Down Expand Up @@ -193,10 +194,12 @@
"coveragePathIgnorePatterns": [
"\\.d\\.ts$",
"/benchmark/",
"/node_modules/"
"/node_modules/",
"src/services/__tests__/models/helpers.ts"
],
"modulePathIgnorePatterns": [
"/benchmark/"
"/benchmark/",
"src/services/__tests__/models/helpers.ts"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContentItems/ContentItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as React from 'react';
import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation';
import { AdvancedMarkdown } from '../Markdown/AdvancedMarkdown';
import { H1, H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements';
import { ContentItemModel } from '../../services/MenuBuilder';
import { GroupModel, OperationModel } from '../../services/models';
import type { ContentItemModel } from '../../services';
import type { GroupModel, OperationModel } from '../../services/models';
import { Operation } from '../Operation/Operation';

@observer
Expand Down
16 changes: 16 additions & 0 deletions src/components/Schema/RecursiveSchema.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { observer } from 'mobx-react';

import { RecursiveLabel, TypeName, TypeTitle } from '../../common-elements/fields';
import { l } from '../../services/Labels';
import type { SchemaProps } from '.';

export const RecursiveSchema = observer(({ schema }: SchemaProps) => {
return (
<div>
<TypeName>{schema.displayType}</TypeName>
{schema.title && <TypeTitle> {schema.title} </TypeTitle>}
<RecursiveLabel> {l('recursive')} </RecursiveLabel>
</div>
);
});
18 changes: 7 additions & 11 deletions src/components/Schema/Schema.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { observer } from 'mobx-react';
import * as React from 'react';

import { RecursiveLabel, TypeName, TypeTitle } from '../../common-elements/fields';
import { FieldDetails } from '../Fields/FieldDetails';

import { FieldModel, SchemaModel } from '../../services/models';

import { ArraySchema } from './ArraySchema';
import { ObjectSchema } from './ObjectSchema';
import { OneOfSchema } from './OneOfSchema';
import { RecursiveSchema } from './RecursiveSchema';

import { l } from '../../services/Labels';
import { isArray } from '../../utils/helpers';

export interface SchemaOptions {
Expand All @@ -36,13 +35,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
const { type, oneOf, discriminatorProp, isCircular } = schema;

if (isCircular) {
return (
<div>
<TypeName>{schema.displayType}</TypeName>
{schema.title && <TypeTitle> {schema.title} </TypeTitle>}
<RecursiveLabel> {l('recursive')} </RecursiveLabel>
</div>
);
return <RecursiveSchema schema={schema} />;
}

if (discriminatorProp !== undefined) {
Expand All @@ -52,11 +45,14 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
);
return null;
}
return (
const activeSchema = oneOf[schema.activeOneOf];
return activeSchema.isCircular ? (
<RecursiveSchema schema={activeSchema} />
) : (
<ObjectSchema
{...rest}
level={level}
schema={oneOf![schema.activeOneOf]}
schema={activeSchema}
discriminator={{
fieldName: discriminatorProp,
parentSchema: schema,
Expand Down
10 changes: 4 additions & 6 deletions src/components/SearchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as React from 'react';

import { IMenuItem } from '../../services/MenuStore';
import { SearchStore } from '../../services/SearchStore';
import { MenuItem } from '../SideMenu/MenuItem';

import { MarkerService } from '../../services/MarkerService';
import { SearchResult } from '../../services/SearchWorker.worker';
import type { IMenuItem, SearchResult } from '../../services/types';
import type { SearchStore } from '../../services/SearchStore';
import type { MarkerService } from '../../services/MarkerService';

import { MenuItem } from '../SideMenu/MenuItem';
import { OptionsContext } from '../OptionsProvider';
import { bind, debounce } from 'decko';
import { PerfectScrollbarWrap } from '../../common-elements/perfect-scrollbar';
Expand Down
3 changes: 2 additions & 1 deletion src/components/SideMenu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { observer } from 'mobx-react';
import * as React from 'react';

import { ShelfIcon } from '../../common-elements/shelfs';
import { IMenuItem, OperationModel } from '../../services';
import { OperationModel } from '../../services';
import { shortenHTTPVerb } from '../../utils/openapi';
import { MenuItems } from './MenuItems';
import { MenuItemLabel, MenuItemLi, MenuItemTitle, OperationBadge } from './styled.elements';
import { l } from '../../services/Labels';
import { scrollIntoViewIfNeeded } from '../../utils';
import { OptionsContext } from '../OptionsProvider';
import type { IMenuItem } from '../../services';

export interface MenuItemProps {
item: IMenuItem;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SideMenu/MenuItems.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { observer } from 'mobx-react';
import * as React from 'react';

import { IMenuItem } from '../../services';
import type { IMenuItem } from '../../services';

import { MenuItem } from './MenuItem';
import { MenuItemUl } from './styled.elements';
Expand Down
3 changes: 2 additions & 1 deletion src/components/SideMenu/SideMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { observer } from 'mobx-react';
import * as React from 'react';

import { IMenuItem, MenuStore } from '../../services/MenuStore';
import { MenuStore } from '../../services';
import type { IMenuItem } from '../../services';
import { OptionsContext } from '../OptionsProvider';
import { MenuItems } from './MenuItems';

Expand Down
Loading

0 comments on commit 2970f95

Please sign in to comment.