-
Notifications
You must be signed in to change notification settings - Fork 174
fix: improve join command servers handling #2133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: b49d76d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
packages/cli/tsconfig.json
Outdated
@@ -5,6 +5,6 @@ | |||
"outDir": "lib" | |||
}, | |||
"references": [{ "path": "../core" }, { "path": "../respect-core" }], | |||
"include": ["src/**/*.ts"], | |||
"include": ["src/**/*.ts", "src/__tests__/fixtures/join/documents.ts1"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documents.ts1
looks wrong.
@@ -51,6 +61,10 @@ describe('handleJoin', () => { | |||
); | |||
}); | |||
|
|||
afterEach(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you need this? We've configured Vitest to restore all mocks: https://github.com/Redocly/redocly-cli/blob/main/vitest.config.ts#L49. Isn't that enough?
const firstDocServers = documents[0]?.parsed.servers; | ||
const serversAreTheSame = | ||
firstDocServers && | ||
documents.slice(1).every((doc) => { | ||
// include only documents with paths | ||
if (Object.keys(doc.parsed.paths || {}).length === 0) { | ||
return true; | ||
} | ||
return doc.parsed.servers?.every((server: Oas3Server) => | ||
firstDocServers?.find((firstDocServer: Oas3Server) => firstDocServer.url === server.url) | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit easier to read for me (no magic numbers like 0 or 1 🙂):
const firstDocServers = documents[0]?.parsed.servers; | |
const serversAreTheSame = | |
firstDocServers && | |
documents.slice(1).every((doc) => { | |
// include only documents with paths | |
if (Object.keys(doc.parsed.paths || {}).length === 0) { | |
return true; | |
} | |
return doc.parsed.servers?.every((server: Oas3Server) => | |
firstDocServers?.find((firstDocServer: Oas3Server) => firstDocServer.url === server.url) | |
); | |
}); | |
const [first, ...others] = documents ?? []; | |
const serversAreTheSame = others.every(({ parsed: { paths, servers } }) => { | |
// include only documents with paths | |
if (!paths || isEmptyObject(paths || {})) { | |
return true; | |
} | |
return servers?.every((server: Oas3Server) => | |
first.parsed.servers?.find(({ url }: Oas3Server) => url === server.url) | |
); | |
}) |
@@ -335,7 +336,10 @@ describe('E2E', () => { | |||
|
|||
test.each(testDirNames)('test: %s', async (dir) => { | |||
const testPath = join(__dirname, `join/${dir}`); | |||
const args = getParams(indexEntryPoint, ['join', ...entrypoints]); | |||
let args = getParams(indexEntryPoint, ['join', ...entrypoints]); | |||
if (dir === 'three-files-one-without-servers') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this to a separate describe
/test
? Or put a FIXME so I'll do that later. I try to avoid conditions in tests so they are easier to debug and maintain.
What/Why/How?
This pull request resolves an issue with the join command where it would incorrectly merge OpenAPI documents with different servers configurations, leading to a semantically invalid result.
The updated logic now handles server merging based on whether the input files share the same server definitions.
Reference
Resolves #2118
Testing
Check yourself
Security