Skip to content

Commit

Permalink
chore: move remove-unused-components decorator to decorators fold…
Browse files Browse the repository at this point in the history
…er (#1316)
  • Loading branch information
tatomyr authored Nov 9, 2023
1 parent 828290e commit 3f13cb9
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 79 deletions.
102 changes: 51 additions & 51 deletions docs/sidebars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,57 +62,57 @@
- group: Built-in rules
page: rules/built-in-rules.md
items:
- page: rules/boolean-parameter-prefixes.md
- page: rules/component-name-unique.md
- page: rules/info-contact.md
- page: rules/info-license.md
- page: rules/info-license-url.md
- page: rules/no-ambiguous-paths.md
- page: rules/no-empty-servers.md
- page: rules/no-enum-type-mismatch.md
- page: rules/no-example-value-and-externalValue.md
- page: rules/no-http-verbs-in-paths.md
- page: rules/no-identical-paths.md
- page: rules/no-invalid-media-type-examples.md
- page: rules/no-invalid-parameter-examples.md
- page: rules/no-invalid-schema-examples.md
- page: rules/no-path-trailing-slash.md
- page: rules/no-server-example-com.md
- page: rules/no-server-trailing-slash.md
- page: rules/no-server-variables-empty-enum.md
- page: rules/no-undefined-server-variable.md
- page: rules/no-unresolved-refs.md
- page: rules/no-unused-components.md
- page: rules/operation-2xx-response.md
- page: rules/operation-4xx-problem-details-rfc7807.md
- page: rules/operation-4xx-response.md
- page: rules/operation-description.md
- page: rules/operation-operationId.md
- page: rules/operation-operationId-unique.md
- page: rules/operation-operationId-url-safe.md
- page: rules/operation-parameters-unique.md
- page: rules/operation-singular-tag.md
- page: rules/operation-summary.md
- page: rules/operation-tag-defined.md
- page: rules/parameter-description.md
- page: rules/path-declaration-must-exist.md
- page: rules/path-excludes-patterns.md
- page: rules/path-not-include-query.md
- page: rules/path-parameters-defined.md
- page: rules/path-segment-plural.md
- page: rules/paths-kebab-case.md
- page: rules/request-mime-type.md
- page: rules/required-string-property-missing-min-length.md
- page: rules/response-contains-header.md
- page: rules/response-contains-property.md
- page: rules/response-mime-type.md
- page: rules/scalar-property-missing-example.md
- page: rules/security-defined.md
- page: rules/spec-components-invalid-map-name.md
- page: rules/spec.md
- page: rules/spec-strict-refs.md
- page: rules/tag-description.md
- page: rules/tags-alphabetical.md
- page: rules/boolean-parameter-prefixes.md
- page: rules/component-name-unique.md
- page: rules/info-contact.md
- page: rules/info-license.md
- page: rules/info-license-url.md
- page: rules/no-ambiguous-paths.md
- page: rules/no-empty-servers.md
- page: rules/no-enum-type-mismatch.md
- page: rules/no-example-value-and-externalValue.md
- page: rules/no-http-verbs-in-paths.md
- page: rules/no-identical-paths.md
- page: rules/no-invalid-media-type-examples.md
- page: rules/no-invalid-parameter-examples.md
- page: rules/no-invalid-schema-examples.md
- page: rules/no-path-trailing-slash.md
- page: rules/no-server-example-com.md
- page: rules/no-server-trailing-slash.md
- page: rules/no-server-variables-empty-enum.md
- page: rules/no-undefined-server-variable.md
- page: rules/no-unresolved-refs.md
- page: rules/no-unused-components.md
- page: rules/operation-2xx-response.md
- page: rules/operation-4xx-problem-details-rfc7807.md
- page: rules/operation-4xx-response.md
- page: rules/operation-description.md
- page: rules/operation-operationId.md
- page: rules/operation-operationId-unique.md
- page: rules/operation-operationId-url-safe.md
- page: rules/operation-parameters-unique.md
- page: rules/operation-singular-tag.md
- page: rules/operation-summary.md
- page: rules/operation-tag-defined.md
- page: rules/parameter-description.md
- page: rules/path-declaration-must-exist.md
- page: rules/path-excludes-patterns.md
- page: rules/path-not-include-query.md
- page: rules/path-parameters-defined.md
- page: rules/path-segment-plural.md
- page: rules/paths-kebab-case.md
- page: rules/request-mime-type.md
- page: rules/required-string-property-missing-min-length.md
- page: rules/response-contains-header.md
- page: rules/response-contains-property.md
- page: rules/response-mime-type.md
- page: rules/scalar-property-missing-example.md
- page: rules/security-defined.md
- page: rules/spec-components-invalid-map-name.md
- page: rules/spec.md
- page: rules/spec-strict-refs.md
- page: rules/tag-description.md
- page: rules/tags-alphabetical.md
- page: rules/configurable-rules.md
- group: Decorators
page: decorators.md
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { reportUnresolvedRef } from './rules/no-unresolved-refs';
import { isPlainObject, isTruthy } from './utils';
import { OasRef } from './typings/openapi';
import { isRedoclyRegistryURL } from './redocly';
import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './rules/oas2/remove-unused-components';
import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './rules/oas3/remove-unused-components';
import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './decorators/oas2/remove-unused-components';
import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './decorators/oas3/remove-unused-components';

import type { Config, StyleguideConfig } from './config';

Expand Down Expand Up @@ -126,8 +126,8 @@ export async function bundleDocument(opts: {
config
);

const preprocessors = initRules(rules as any, config, 'preprocessors', specVersion);
const decorators = initRules(rules as any, config, 'decorators', specVersion);
const preprocessors = initRules(rules, config, 'preprocessors', specVersion);
const decorators = initRules(rules, config, 'decorators', specVersion);

const ctx: BundleContext = {
problems: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Oas2Rule } from '../../visitors';
import type { Oas2Decorator } from '../../visitors';
import { Location } from '../../ref-utils';
import { Oas2Components } from '../../typings/swagger';
import type { Oas2Components } from '../../typings/swagger';
import { isEmptyObject } from '../../utils';

export const RemoveUnusedComponents: Oas2Rule = () => {
export const RemoveUnusedComponents: Oas2Decorator = () => {
const components = new Map<
string,
{ used: boolean; componentType?: keyof Oas2Components; name: string }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Oas3Rule } from '../../visitors';
import type { Oas3Decorator } from '../../visitors';
import { Location } from '../../ref-utils';
import { Oas3Components } from '../../typings/openapi';
import type { Oas3Components } from '../../typings/openapi';
import { isEmptyObject } from '../../utils';

export const RemoveUnusedComponents: Oas3Rule = () => {
export const RemoveUnusedComponents: Oas3Decorator = () => {
const components = new Map<
string,
{ used: boolean; componentType?: keyof Oas3Components; name: string }
Expand Down
25 changes: 7 additions & 18 deletions packages/core/src/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type Oas2FlatVisitor = {
NamedResponses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
NamedParameters?: VisitFunctionOrObject<Record<string, Oas2Parameter>>;
SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
NamedSecuritySchemes?: VisitFunctionOrObject<Record<string, Oas2SecurityScheme>>;
SpecExtension?: VisitFunctionOrObject<unknown>;
};

Expand Down Expand Up @@ -255,18 +256,6 @@ export type Async2Visitor = BaseVisitor &
Async2NestedVisitor &
Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;

export type Oas3TransformVisitor = BaseVisitor &
Oas3FlatVisitor &
Record<string, VisitFunction<any> | VisitObject<any>>;

export type Oas2TransformVisitor = BaseVisitor &
Oas2FlatVisitor &
Record<string, VisitFunction<any> | VisitObject<any>>;

export type Async2TransformVisitor = BaseVisitor &
Async2FlatVisitor &
Record<string, VisitFunction<any> | VisitObject<any>>;

export type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;

export type NormalizedOasVisitors<T extends BaseVisitor> = {
Expand All @@ -289,12 +278,12 @@ export type NormalizedOasVisitors<T extends BaseVisitor> = {
export type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
export type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
export type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
export type Oas3Preprocessor = (options: Record<string, any>) => Oas3TransformVisitor;
export type Oas2Preprocessor = (options: Record<string, any>) => Oas2TransformVisitor;
export type Async2Preprocessor = (options: Record<string, any>) => Async2TransformVisitor;
export type Oas3Decorator = (options: Record<string, any>) => Oas3TransformVisitor;
export type Oas2Decorator = (options: Record<string, any>) => Oas2TransformVisitor;
export type Async2Decorator = (options: Record<string, any>) => Async2TransformVisitor;
export type Oas3Preprocessor = (options: Record<string, any>) => Oas3Visitor;
export type Oas2Preprocessor = (options: Record<string, any>) => Oas2Visitor;
export type Async2Preprocessor = (options: Record<string, any>) => Async2Visitor;
export type Oas3Decorator = (options: Record<string, any>) => Oas3Visitor;
export type Oas2Decorator = (options: Record<string, any>) => Oas2Visitor;
export type Async2Decorator = (options: Record<string, any>) => Async2Visitor;

// alias for the latest version supported
// every time we update it - consider semver
Expand Down

1 comment on commit 3f13cb9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 76.12% 4057/5330
🟡 Branches 65.95% 2152/3263
🟡 Functions 68.3% 657/962
🟡 Lines 76.31% 3805/4986

Test suite run success

646 tests passing in 93 suites.

Report generated by 🧪jest coverage report action from 3f13cb9

Please sign in to comment.