From 44e3e1068512b4236b838e2dc6c1befed3283dc7 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Fri, 27 Oct 2023 17:51:55 +0300 Subject: [PATCH 1/4] chore: move `remove-unused-components` decorator to `decorators` folder --- packages/core/src/bundle.ts | 4 +-- .../remove-unused-components.test.ts | 0 packages/core/src/decorators/oas2/index.ts | 3 +++ .../oas2/remove-unused-components.ts | 5 ++-- .../remove-unused-components.test.ts | 0 packages/core/src/decorators/oas3/index.ts | 2 ++ .../oas3/remove-unused-components.ts | 4 +-- packages/core/src/visitors.ts | 25 ++++++------------- 8 files changed, 19 insertions(+), 24 deletions(-) rename packages/core/src/{rules => decorators}/oas2/__tests__/remove-unused-components.test.ts (100%) rename packages/core/src/{rules => decorators}/oas2/remove-unused-components.ts (95%) rename packages/core/src/{rules => decorators}/oas3/__tests__/remove-unused-components.test.ts (100%) rename packages/core/src/{rules => decorators}/oas3/remove-unused-components.ts (96%) diff --git a/packages/core/src/bundle.ts b/packages/core/src/bundle.ts index 1eed2bdf2b..57e29913fa 100755 --- a/packages/core/src/bundle.ts +++ b/packages/core/src/bundle.ts @@ -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'; diff --git a/packages/core/src/rules/oas2/__tests__/remove-unused-components.test.ts b/packages/core/src/decorators/oas2/__tests__/remove-unused-components.test.ts similarity index 100% rename from packages/core/src/rules/oas2/__tests__/remove-unused-components.test.ts rename to packages/core/src/decorators/oas2/__tests__/remove-unused-components.test.ts diff --git a/packages/core/src/decorators/oas2/index.ts b/packages/core/src/decorators/oas2/index.ts index 7727e09fa4..77399eadfd 100644 --- a/packages/core/src/decorators/oas2/index.ts +++ b/packages/core/src/decorators/oas2/index.ts @@ -7,6 +7,7 @@ import { InfoOverride } from '../common/info-override'; import { RemoveXInternal } from '../common/remove-x-internal'; import { FilterIn } from '../common/filters/filter-in'; import { FilterOut } from '../common/filters/filter-out'; +import { RemoveUnusedComponents } from './remove-unused-components'; export const decorators = { 'registry-dependencies': RegistryDependencies as Oas2Decorator, @@ -17,4 +18,6 @@ export const decorators = { 'remove-x-internal': RemoveXInternal as Oas2Decorator, 'filter-in': FilterIn as Oas2Decorator, 'filter-out': FilterOut as Oas2Decorator, + 'remove-unused-components': RemoveUnusedComponents + }; diff --git a/packages/core/src/rules/oas2/remove-unused-components.ts b/packages/core/src/decorators/oas2/remove-unused-components.ts similarity index 95% rename from packages/core/src/rules/oas2/remove-unused-components.ts rename to packages/core/src/decorators/oas2/remove-unused-components.ts index d569724104..32ecb5d52c 100644 --- a/packages/core/src/rules/oas2/remove-unused-components.ts +++ b/packages/core/src/decorators/oas2/remove-unused-components.ts @@ -1,9 +1,10 @@ -import { Oas2Rule } from '../../visitors'; +import type { Oas2Decorator } from '../../visitors'; import { Location } from '../../ref-utils'; import { 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 } diff --git a/packages/core/src/rules/oas3/__tests__/remove-unused-components.test.ts b/packages/core/src/decorators/oas3/__tests__/remove-unused-components.test.ts similarity index 100% rename from packages/core/src/rules/oas3/__tests__/remove-unused-components.test.ts rename to packages/core/src/decorators/oas3/__tests__/remove-unused-components.test.ts diff --git a/packages/core/src/decorators/oas3/index.ts b/packages/core/src/decorators/oas3/index.ts index 29381ad8c4..dc962c0209 100644 --- a/packages/core/src/decorators/oas3/index.ts +++ b/packages/core/src/decorators/oas3/index.ts @@ -8,6 +8,7 @@ import { RemoveXInternal } from '../common/remove-x-internal'; import { FilterIn } from '../common/filters/filter-in'; import { FilterOut } from '../common/filters/filter-out'; import { MediaTypeExamplesOverride } from '../common/media-type-examples-override'; +import { RemoveUnusedComponents } from './remove-unused-components'; export const decorators = { 'registry-dependencies': RegistryDependencies as Oas3Decorator, @@ -19,4 +20,5 @@ export const decorators = { 'filter-in': FilterIn as Oas3Decorator, 'filter-out': FilterOut as Oas3Decorator, 'media-type-examples-override': MediaTypeExamplesOverride as Oas3Decorator, + 'remove-unused-components': RemoveUnusedComponents, }; diff --git a/packages/core/src/rules/oas3/remove-unused-components.ts b/packages/core/src/decorators/oas3/remove-unused-components.ts similarity index 96% rename from packages/core/src/rules/oas3/remove-unused-components.ts rename to packages/core/src/decorators/oas3/remove-unused-components.ts index eaddda383c..541e117c9b 100644 --- a/packages/core/src/rules/oas3/remove-unused-components.ts +++ b/packages/core/src/decorators/oas3/remove-unused-components.ts @@ -1,9 +1,9 @@ -import { Oas3Rule } from '../../visitors'; +import { Oas3Decorator } from '../../visitors'; import { Location } from '../../ref-utils'; import { 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 } diff --git a/packages/core/src/visitors.ts b/packages/core/src/visitors.ts index 53e12390a7..3cd7a54ab9 100644 --- a/packages/core/src/visitors.ts +++ b/packages/core/src/visitors.ts @@ -204,6 +204,7 @@ type Oas2FlatVisitor = { NamedResponses?: VisitFunctionOrObject>; NamedParameters?: VisitFunctionOrObject>; SecurityScheme?: VisitFunctionOrObject; + NamedSecuritySchemes?: VisitFunctionOrObject>; SpecExtension?: VisitFunctionOrObject; }; @@ -255,18 +256,6 @@ export type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record | NestedVisitObject>; -export type Oas3TransformVisitor = BaseVisitor & - Oas3FlatVisitor & - Record | VisitObject>; - -export type Oas2TransformVisitor = BaseVisitor & - Oas2FlatVisitor & - Record | VisitObject>; - -export type Async2TransformVisitor = BaseVisitor & - Async2FlatVisitor & - Record | VisitObject>; - export type NestedVisitor = Exclude; export type NormalizedOasVisitors = { @@ -289,12 +278,12 @@ export type NormalizedOasVisitors = { export type Oas3Rule = (options: Record) => Oas3Visitor | Oas3Visitor[]; export type Oas2Rule = (options: Record) => Oas2Visitor | Oas2Visitor[]; export type Async2Rule = (options: Record) => Async2Visitor | Async2Visitor[]; -export type Oas3Preprocessor = (options: Record) => Oas3TransformVisitor; -export type Oas2Preprocessor = (options: Record) => Oas2TransformVisitor; -export type Async2Preprocessor = (options: Record) => Async2TransformVisitor; -export type Oas3Decorator = (options: Record) => Oas3TransformVisitor; -export type Oas2Decorator = (options: Record) => Oas2TransformVisitor; -export type Async2Decorator = (options: Record) => Async2TransformVisitor; +export type Oas3Preprocessor = (options: Record) => Oas3Visitor; +export type Oas2Preprocessor = (options: Record) => Oas2Visitor; +export type Async2Preprocessor = (options: Record) => Async2Visitor; +export type Oas3Decorator = (options: Record) => Oas3Visitor; +export type Oas2Decorator = (options: Record) => Oas2Visitor; +export type Async2Decorator = (options: Record) => Async2Visitor; // alias for the latest version supported // every time we update it - consider semver From 5e77a6705a297189d09c9fac9aebba76eb33c439 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Tue, 31 Oct 2023 10:23:33 +0200 Subject: [PATCH 2/4] chore: update exports --- packages/core/src/bundle.ts | 4 ++-- packages/core/src/decorators/oas2/index.ts | 3 --- packages/core/src/decorators/oas2/remove-unused-components.ts | 1 - packages/core/src/decorators/oas3/index.ts | 2 -- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/core/src/bundle.ts b/packages/core/src/bundle.ts index 57e29913fa..b6d02cb588 100755 --- a/packages/core/src/bundle.ts +++ b/packages/core/src/bundle.ts @@ -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: [], diff --git a/packages/core/src/decorators/oas2/index.ts b/packages/core/src/decorators/oas2/index.ts index 77399eadfd..7727e09fa4 100644 --- a/packages/core/src/decorators/oas2/index.ts +++ b/packages/core/src/decorators/oas2/index.ts @@ -7,7 +7,6 @@ import { InfoOverride } from '../common/info-override'; import { RemoveXInternal } from '../common/remove-x-internal'; import { FilterIn } from '../common/filters/filter-in'; import { FilterOut } from '../common/filters/filter-out'; -import { RemoveUnusedComponents } from './remove-unused-components'; export const decorators = { 'registry-dependencies': RegistryDependencies as Oas2Decorator, @@ -18,6 +17,4 @@ export const decorators = { 'remove-x-internal': RemoveXInternal as Oas2Decorator, 'filter-in': FilterIn as Oas2Decorator, 'filter-out': FilterOut as Oas2Decorator, - 'remove-unused-components': RemoveUnusedComponents - }; diff --git a/packages/core/src/decorators/oas2/remove-unused-components.ts b/packages/core/src/decorators/oas2/remove-unused-components.ts index 32ecb5d52c..8d7e54a5a4 100644 --- a/packages/core/src/decorators/oas2/remove-unused-components.ts +++ b/packages/core/src/decorators/oas2/remove-unused-components.ts @@ -3,7 +3,6 @@ import { Location } from '../../ref-utils'; import { Oas2Components } from '../../typings/swagger'; import { isEmptyObject } from '../../utils'; - export const RemoveUnusedComponents: Oas2Decorator = () => { const components = new Map< string, diff --git a/packages/core/src/decorators/oas3/index.ts b/packages/core/src/decorators/oas3/index.ts index dc962c0209..29381ad8c4 100644 --- a/packages/core/src/decorators/oas3/index.ts +++ b/packages/core/src/decorators/oas3/index.ts @@ -8,7 +8,6 @@ import { RemoveXInternal } from '../common/remove-x-internal'; import { FilterIn } from '../common/filters/filter-in'; import { FilterOut } from '../common/filters/filter-out'; import { MediaTypeExamplesOverride } from '../common/media-type-examples-override'; -import { RemoveUnusedComponents } from './remove-unused-components'; export const decorators = { 'registry-dependencies': RegistryDependencies as Oas3Decorator, @@ -20,5 +19,4 @@ export const decorators = { 'filter-in': FilterIn as Oas3Decorator, 'filter-out': FilterOut as Oas3Decorator, 'media-type-examples-override': MediaTypeExamplesOverride as Oas3Decorator, - 'remove-unused-components': RemoveUnusedComponents, }; From fbad9874cb8262c26044f753d9a8cb6054f9c75a Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Thu, 2 Nov 2023 10:47:51 +0200 Subject: [PATCH 3/4] chore: import types --- packages/core/src/decorators/oas2/remove-unused-components.ts | 2 +- packages/core/src/decorators/oas3/remove-unused-components.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/decorators/oas2/remove-unused-components.ts b/packages/core/src/decorators/oas2/remove-unused-components.ts index 8d7e54a5a4..406a29668d 100644 --- a/packages/core/src/decorators/oas2/remove-unused-components.ts +++ b/packages/core/src/decorators/oas2/remove-unused-components.ts @@ -1,6 +1,6 @@ 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: Oas2Decorator = () => { diff --git a/packages/core/src/decorators/oas3/remove-unused-components.ts b/packages/core/src/decorators/oas3/remove-unused-components.ts index 541e117c9b..8fc9cfef50 100644 --- a/packages/core/src/decorators/oas3/remove-unused-components.ts +++ b/packages/core/src/decorators/oas3/remove-unused-components.ts @@ -1,6 +1,6 @@ -import { Oas3Decorator } 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: Oas3Decorator = () => { From 60316518c9577e53eea093d64d97246c5528d7e0 Mon Sep 17 00:00:00 2001 From: Andrew Tatomyr Date: Thu, 9 Nov 2023 10:10:16 +0200 Subject: [PATCH 4/4] chore: apply prettier --- docs/sidebars.yaml | 102 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/sidebars.yaml b/docs/sidebars.yaml index 22dbb3207d..d56ac5c9e4 100644 --- a/docs/sidebars.yaml +++ b/docs/sidebars.yaml @@ -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