-
Notifications
You must be signed in to change notification settings - Fork 223
fix(cli): fix join dropping non-string x-* path extension properties #2949
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?
Changes from all commits
8a20526
9c2f824
489b31e
bc76fd1
310638c
229f223
c3edfd1
5b7a1cc
c3fc9fb
b593d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@redocly/cli': patch | ||
| --- | ||
|
|
||
| Fixed an issue where the `join` command silently dropped path-level `x-*` extensions with non-string values. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { | |
| detectSpec, | ||
| getTotals, | ||
| loadConfig, | ||
| logger, | ||
| type Document, | ||
| BaseResolver, | ||
| } from '@redocly/openapi-core'; | ||
|
|
@@ -24,6 +25,10 @@ import { | |
| thirdDocument, | ||
| serverAndPaths, | ||
| anotherServerAndPaths, | ||
| pathWithObjectExtension, | ||
| anotherPathWithSameObjectExtension, | ||
| anotherPathWithDifferentObjectExtension, | ||
| anotherPathWithDifferentKeyObjectExtension, | ||
| } from '../fixtures/join/documents.js'; | ||
|
|
||
| describe('handleJoin', () => { | ||
|
|
@@ -466,6 +471,103 @@ describe('handleJoin', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('path extensions', () => { | ||
| it('should merge non-string x-* path extension when values are the same', async () => { | ||
| vi.mocked(detectSpec).mockReturnValue('oas3_0'); | ||
| const warnSpy = vi.spyOn(logger, 'warn'); | ||
| vi.spyOn(BaseResolver.prototype, 'resolveDocument') | ||
| .mockReset() | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-a' }, | ||
| parsed: pathWithObjectExtension, | ||
| } as Document) | ||
| ) | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-b' }, | ||
| parsed: anotherPathWithSameObjectExtension, | ||
| } as Document) | ||
| ); | ||
|
|
||
| await handleJoin({ | ||
| argv: { | ||
| apis: ['a.yaml', 'b.yaml'], | ||
| }, | ||
| config: configFixture, | ||
| version: 'cli-version', | ||
| }); | ||
|
|
||
| const joinedDef = writeToFileByExtensionSpy.mock.calls[0][0]; | ||
| expect(joinedDef.paths['/foo']['x-metadata']).toEqual({ owner: 'team-a' }); | ||
| expect(warnSpy).not.toHaveBeenCalledWith( | ||
| expect.stringContaining('different x-metadata values') | ||
| ); | ||
| }); | ||
|
|
||
| it('should warn when non-string x-* path extension values differ', async () => { | ||
| vi.mocked(detectSpec).mockReturnValue('oas3_0'); | ||
| const warnSpy = vi.spyOn(logger, 'warn'); | ||
| vi.spyOn(BaseResolver.prototype, 'resolveDocument') | ||
| .mockReset() | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-a' }, | ||
| parsed: pathWithObjectExtension, | ||
| } as Document) | ||
| ) | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-b' }, | ||
| parsed: anotherPathWithDifferentObjectExtension, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the object had different keys though? Like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A warning log is being output. If this part overlaps, it means the paths also overlap.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nonchan7720 Please add a test for this case |
||
| } as Document) | ||
| ); | ||
|
|
||
| await handleJoin({ | ||
| argv: { | ||
| apis: ['a.yaml', 'b.yaml'], | ||
| }, | ||
| config: configFixture, | ||
| version: 'cli-version', | ||
| }); | ||
|
|
||
| const joinedDef = writeToFileByExtensionSpy.mock.calls[0][0]; | ||
| expect(joinedDef.paths['/foo']['x-metadata']).toEqual({ owner: 'team-a' }); | ||
| expect(warnSpy).toHaveBeenCalledWith('warning: different x-metadata values in /foo\n'); | ||
| }); | ||
|
|
||
| it('should warn when non-string x-* path extension objects have different keys', async () => { | ||
| vi.mocked(detectSpec).mockReturnValue('oas3_0'); | ||
| const warnSpy = vi.spyOn(logger, 'warn'); | ||
| vi.spyOn(BaseResolver.prototype, 'resolveDocument') | ||
| .mockReset() | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-a' }, | ||
| parsed: pathWithObjectExtension, | ||
| } as Document) | ||
| ) | ||
| .mockImplementationOnce(() => | ||
| Promise.resolve({ | ||
| source: { absoluteRef: 'ref-b' }, | ||
| parsed: anotherPathWithDifferentKeyObjectExtension, | ||
| } as Document) | ||
| ); | ||
|
|
||
| await handleJoin({ | ||
| argv: { | ||
| apis: ['a.yaml', 'b.yaml'], | ||
| }, | ||
| config: configFixture, | ||
| version: 'cli-version', | ||
| }); | ||
|
|
||
| const joinedDef = writeToFileByExtensionSpy.mock.calls[0][0]; | ||
| expect(joinedDef.paths['/foo']['x-metadata']).toEqual({ owner: 'team-a' }); | ||
| expect(warnSpy).toHaveBeenCalledWith('warning: different x-metadata values in /foo\n'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('replace$Refs', () => { | ||
| it('should prefix discriminator mapping refs when schema name contains prefix substring', () => { | ||
| const doc = { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.