Skip to content

Commit

Permalink
renamed inconsistencies to conflicts and fixed structural search
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvuka1 committed Jun 15, 2024
1 parent d2d8fb9 commit 8bd8547
Show file tree
Hide file tree
Showing 16 changed files with 1,821 additions and 396 deletions.
248 changes: 150 additions & 98 deletions dist/index.js

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions src/formatOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export type FormatOutputOptions = {
};

export const formatOutput = (
failOutput: FailOutput,
inconsistencies: FailOutput,
options: FormatOutputOptions,
) => {
if (failOutput.length === 0) {
if (inconsistencies.length === 0) {
return '### ✅No inconsistencies found between Open API specifiaction and Documentation!';
}

const oasOnly = failOutput
const oasOnly = inconsistencies
.flatMap(fail => {
if (fail.type !== 'only-in-oas') return [];
return [
Expand All @@ -40,7 +40,7 @@ export const formatOutput = (
? `- ### 🟩Found in Open API specification, 🟥Not found in Documentation\n\t${oasOnly}`
: '';

const docOnly = failOutput
const docOnly = inconsistencies
.flatMap(fail => {
if (fail.type !== 'only-in-doc') return [];
return [
Expand All @@ -54,38 +54,38 @@ export const formatOutput = (
? `- ### 🟥Not found in Open API specification, 🟩Found in Documentation\n\t${docOnly}`
: '';

const matchesWithInconsistencies = failOutput
.flatMap(fail => {
if (fail.type !== 'match-with-inconsistenties') return [];
const inconsistencies = [
`- | Inconsistency type | Open API specification <br /> [\`${fail.oasRequestConfig.method.toUpperCase()} ${oasPathSegsToPath(fail.oasRequestConfig.pathSegs)}\`](${options.oasPath}) | Documentation <br /> [\`${fail.docRequestConfig.method.toUpperCase()} ${fail.docRequestConfig.originalPath}\`](${options.docPath}?plain=1#L${fail.docRequestConfig.line}) |`,
const matchesWithConflicts = inconsistencies
.flatMap(i => {
if (i.type !== 'match-with-conflicts') return [];
const conflicts = [
`- | Conflict type | Open API specification <br /> [\`${i.oasRequestConfig.method.toUpperCase()} ${oasPathSegsToPath(i.oasRequestConfig.pathSegs)}\`](${options.oasPath}) | Documentation <br /> [\`${i.docRequestConfig.method.toUpperCase()} ${i.docRequestConfig.originalPath}\`](${options.docPath}?plain=1#L${i.docRequestConfig.line}) |`,
'| --- | --- | --- |',
...fail.inconsistencies.map(i => {
switch (i.type) {
...i.conflicts.map(c => {
switch (c.type) {
case 'method-mismatch':
return `| Method mismatch | \`${fail.oasRequestConfig.method.toUpperCase()}\` | \`${fail.docRequestConfig.method.toUpperCase()}\` |`;
case 'path-path-parameter-name-mismatch':
return `| Method mismatch | \`${i.oasRequestConfig.method.toUpperCase()}\` | \`${i.docRequestConfig.method.toUpperCase()}\` |`;
case 'path-parameter-name-mismatch':
const oasServerBasePath =
(i.oasServerIndex
? fail.oasRequestConfig.servers[i.oasServerIndex]?.basePath
(c.oasServerIndex
? i.oasRequestConfig.servers[c.oasServerIndex]?.basePath
: null) ?? [];
const oasFullPath = [
...oasServerBasePath,
...fail.oasRequestConfig.pathSegs,
...i.oasRequestConfig.pathSegs,
];
const oasMismatchedParam = oasFullPath.flatMap(p =>
p.type === 'parameter' ? [p.name] : [],
)[i.parameterIndex];
const docMismatchedParam = fail.docRequestConfig.pathSegs.flatMap(
)[c.parameterIndex];
const docMismatchedParam = i.docRequestConfig.pathSegs.flatMap(
p => (p.type === 'parameter' ? [p.name] : []),
)[i.parameterIndex];
)[c.parameterIndex];
assert(
oasMismatchedParam,
`No path parameter with index ${i.parameterIndex} in oas path`,
`No path parameter with index ${c.parameterIndex} in oas path`,
);
assert(
docMismatchedParam,
`No path parameter with index ${i.parameterIndex} in doc path`,
`No path parameter with index ${c.parameterIndex} in doc path`,
);
return `| Path parameter name mismatch | \`${oasMismatchedParam}\` | \`${docMismatchedParam}\` |`;
case 'host-mismatch':
Expand All @@ -97,21 +97,21 @@ export const formatOutput = (
}
}),
].join('\n\t\t');
return inconsistencies;
return conflicts;
})
.join('\n\t');

const matchesWithInconsistenciesSection =
matchesWithInconsistencies.length > 0
? `- ### 🟩Found in Open API specification, 🟩Found in Documentation, 🟥Have Inconsistencies\n\t${matchesWithInconsistencies}`
const matchesWithConflictsSection =
matchesWithConflicts.length > 0
? `- ### 🟩Found in Open API specification, 🟩Found in Documentation, 🟥Have Conflicts\n\t${matchesWithConflicts}`
: '';

return `\
I have identified the following possible instances of inconsistencies between [Open API specification](${options.oasPath}) and [Documentation](${options.docPath}):
${oasOnlySection}
${docOnlySection}
${matchesWithInconsistenciesSection}
${matchesWithConflictsSection}
**About**
Expand Down
Loading

0 comments on commit 8bd8547

Please sign in to comment.