Skip to content

Commit 48484fe

Browse files
CountRedClawJayLim2b41ex
authored
feat: use mask (*) instead of parameter names while matching rest operations during comparison (#15)
* feat: use mask (*) instead of parameter names while matching rest operations during comparison * fix: slugify removes * symbol * fix: resolvers * refactor: mapping types * fix: resolved locally operations * fix: version resolver cache key * feat: add comparison.previousOperationId * fix: remove includeSummary flag to avoid direct dashboards comparison * fix: remove unnecessary fields * fix: restore includeOperations flag to fix playwright tests * fix: error messages * feat: add comparison.previousOperationId * refactor: move normalized id creation to apiBuilder method * fix: small issues * feat(ignore param name): Set dist tag * feat(ignore param name): Added npm script to update dev deps. Skipped test suite * fix: add missing apiType filtration * refactor: align previousOperationMetadata * fix(types): Updated type in accordance to implementation * chore: remove unnecessary prerelease suffixes --------- Co-authored-by: Sergei Komarov <[email protected]> Co-authored-by: b41ex <[email protected]>
1 parent 217c4b7 commit 48484fe

File tree

21 files changed

+226
-130
lines changed

21 files changed

+226
-130
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": "./dist/cjs/src/index.js"
1616
}
1717
},
18-
"scripts": {
18+
"scripts": {
1919
"build": "tsc --module commonjs --outDir dist/cjs && vite build",
2020
"build:web": "vite build",
2121
"performance:build": "vite build --sourcemap=inline -c=vite.performance.config.ts",

src/apitypes/rest/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { OpenAPIV3 } from 'openapi-types'
1919
import { buildRestDocument, dumpRestDocument } from './rest.document'
2020
import { REST_API_TYPE, REST_DOCUMENT_TYPE } from './rest.consts'
2121
import { compareRestOperationsData } from './rest.changes'
22-
import { buildRestOperations } from './rest.operations'
22+
import { buildRestOperations, createNormalizedOperationId } from './rest.operations'
2323
import { parseRestFile } from './rest.parser'
2424

2525
import { ApiBuilder } from '../../types'
@@ -34,4 +34,5 @@ export const restApiBuilder: ApiBuilder<OpenAPIV3.Document> = {
3434
buildOperations: buildRestOperations,
3535
dumpDocument: dumpRestDocument,
3636
compareOperationsData: compareRestOperationsData,
37+
createNormalizedOperationId: createNormalizedOperationId,
3738
}

src/apitypes/rest/rest.operations.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
import { OpenAPIV3 } from 'openapi-types'
1818

1919
import { buildRestOperation } from './rest.operation'
20-
import { OperationsBuilder } from '../../types'
21-
import { createBundlingErrorHandler, removeComponents, removeFirstSlash, slugify } from '../../utils'
20+
import { OperationIdNormalizer, OperationsBuilder } from '../../types'
21+
import {
22+
createBundlingErrorHandler,
23+
IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER,
24+
removeComponents,
25+
removeFirstSlash,
26+
slugify,
27+
} from '../../utils'
2228
import { getOperationBasePath } from './rest.utils'
2329
import type * as TYPE from './rest.types'
2430
import { HASH_FLAG, INLINE_REFS_FLAG, MESSAGE_SEVERITY, NORMALIZE_OPTIONS, ORIGINS_SYMBOL } from '../../consts'
@@ -106,3 +112,8 @@ export const buildRestOperations: OperationsBuilder<OpenAPIV3.Document> = async
106112
}
107113
return operations
108114
}
115+
116+
export const createNormalizedOperationId: OperationIdNormalizer = (operation) => {
117+
const { metadata: { path, method } } = operation
118+
return slugify(`${path}-${method}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
119+
}

src/apitypes/rest/rest.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import type { OpenAPIV3 } from 'openapi-types'
1818

1919
import type { ApiOperation, NotificationMessage, VersionDocument } from '../../types'
2020
import { REST_DOCUMENT_TYPE, REST_KIND_KEY, REST_SCOPES } from './rest.consts'
21+
import { NormalizedPath } from '../../utils'
2122

2223
export type RestScopeType = keyof typeof REST_SCOPES
2324
export type RestDocumentType = (typeof REST_DOCUMENT_TYPE)[keyof typeof REST_DOCUMENT_TYPE]
2425
export type CustomTags = Record<string, unknown>
2526

2627
export interface RestOperationMeta {
27-
path: string // `/packages/*/version/*`
28+
path: NormalizedPath // `/packages/*/version/*`
2829
originalPath: string // `/packages/{packageId}/version/{version}`
2930
method: OpenAPIV3.HttpMethods // `get` | `post` | ...
3031
tags?: string[] // operations tags

src/builder.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
ResolvedDeprecatedOperations,
2828
ResolvedDocuments,
2929
ResolvedOperations,
30-
ResolvedVersionOperationsHashMap,
31-
VALIDATION_RULES_SEVERITY_LEVEL_WARNING,
3230
VersionId,
3331
VersionsComparison,
3432
} from './types'
@@ -288,7 +286,10 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
288286
packageId = packageId ?? this.config.packageId
289287

290288
if (this.canBeResolvedLocally(version, packageId)) {
291-
const currentOperations = operationIds ? this.operationList.filter(({ operationId }) => operationIds.includes(operationId)) : this.operationList
289+
const currentApiTypeOperations = this.operationList.filter((operation) => operation.apiType === apiType)
290+
const currentOperations = operationIds
291+
? currentApiTypeOperations.filter(({ operationId }) => operationIds.includes(operationId))
292+
: currentApiTypeOperations
292293
return { operations: currentOperations }
293294
}
294295

@@ -417,6 +418,8 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
417418
throw new Error('No versionResolver provided')
418419
}
419420

421+
// includeOperations=true is only used to extract unique apiTypes (see getUniqueApiTypesFromVersions)
422+
// the operations map itself is no longer used in processor
420423
const versionContent = await versionResolver(packageId, version, true)
421424

422425
if (!versionContent) {
@@ -495,10 +498,9 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
495498
const operationsTypes: OperationTypes[] = []
496499

497500
for (const apiType of this.existingOperationsApiTypes) {
498-
const operationsHashMap = this.operationsHashMapByApiType(apiType)
499501
operationsTypes.push({
500502
apiType: apiType,
501-
operations: operationsHashMap,
503+
operationsCount: this.operations.size,
502504
})
503505
}
504506

@@ -511,18 +513,6 @@ export class PackageVersionBuilder implements IPackageVersionBuilder {
511513
return new Set(apiTypes)
512514
}
513515

514-
private operationsHashMapByApiType(operationsApiType: OperationsApiType): ResolvedVersionOperationsHashMap {
515-
const hashMap: ResolvedVersionOperationsHashMap = {}
516-
517-
for (const { apiType, operationId, dataHash } of this.operations.values()) {
518-
if (apiType === operationsApiType) {
519-
hashMap[operationId] = dataHash
520-
}
521-
}
522-
523-
return hashMap
524-
}
525-
526516
async parseFile(fileId: string, source: Blob): Promise<File | null> {
527517
if (this.parsedFiles.has(fileId)) {
528518
return this.parsedFiles.get(fileId) ?? null

0 commit comments

Comments
 (0)