Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`diff-all diff all against a cloud tag 1`] = `
"Diffing cloud:main to spec.json

specification details:
- /x-optic-url added
- /openapi changed

GET /api/users: removed

GET /example: added

POST /example: added

PUT /example: added

PATCH /example: added

Checks

 FAIL  GET /api/users
removed rule [error]: prevent operation removal
x cannot remove an operation. This is a breaking change.
at paths > /api/users > get (empty.json:1:45)



4 operations added, 1 removed
0 passed
1 errors

"
`;

exports[`diff-all diff all not in the root of a repo 1`] = `
"Diffing HEAD~1:folder/in-folder.yml to in-folder.yml
No changes were detected
Expand Down Expand Up @@ -141,11 +174,12 @@ Checks
2 errors

✔ Uploaded results of diff to http://localhost:3001/organizations/org-id/apis/api-id/runs/run-id
Warning - the following OpenAPI specs were detected but did not have valid x-optic-url keys. \`optic diff-all\` only runs on specs that include \`x-optic-url\` keys that point to specs uploaded to optic.
Warning - the following OpenAPI specs were detected but did not have valid x-optic-url keys. 'optic diff-all --upload' can only runs on specs that have been added to optic

Run the \`optic api add\` command to add these specs to optic
../spec-with-invalid-url.yml
../specwithoutkey.json
../specwithoutkey.yml
../spec-with-invalid-url.yml (untracked)
../specwithoutkey.json (untracked)
../specwithoutkey.yml (untracked)

"
`;
Expand Down Expand Up @@ -337,11 +371,12 @@ Checks
2 errors

✔ Uploaded results of diff to http://localhost:3001/organizations/org-id/apis/api-id/runs/run-id
Warning - the following OpenAPI specs were detected but did not have valid x-optic-url keys. \`optic diff-all\` only runs on specs that include \`x-optic-url\` keys that point to specs uploaded to optic.
Warning - the following OpenAPI specs were detected but did not have valid x-optic-url keys. 'optic diff-all --upload' can only runs on specs that have been added to optic

Run the \`optic api add\` command to add these specs to optic
spec-with-invalid-url.yml
specwithoutkey.json
specwithoutkey.yml
spec-with-invalid-url.yml (untracked)
specwithoutkey.json (untracked)
specwithoutkey.yml (untracked)

"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,39 @@ Checks
"
`;

exports[`diff with mock server with --base cloud:tag 1`] = `
"Rerun this command with the --web flag to open a visual changelog your browser

specification details:
- /x-optic-url added
- /openapi changed

GET /api/users: removed

GET /example: added

POST /example: added

PUT /example: added

PATCH /example: added

Checks

 FAIL  GET /api/users
removed rule [error]: prevent operation removal
x cannot remove an operation. This is a breaking change.
at paths > /api/users > get (empty.json:1:45)



4 operations added, 1 removed
0 passed
1 errors

"
`;

exports[`diff with mock server with cloud tag ref 1`] = `
"Rerun this command with the --web flag to open a visual changelog your browser

Expand Down
26 changes: 26 additions & 0 deletions projects/optic/src/__tests__/integration/diff-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ setupTestServer(({ url, method }) => {
return JSON.stringify({
id: 'run-id',
});
} else if (method === 'GET' && /spec$/.test(url)) {
return `{"openapi":"3.1.0","paths":{ "/api/users": { "get": { "responses":{} }}},"info":{"version":"0.0.0","title":"Empty"}}`;
} else if (method === 'GET' && /sourcemap$/.test(url)) {
return `{"rootFilePath":"empty.json","files":[{"path":"empty.json","sha256":"815b8e5491a1f491765084f236c741d5073e10fcece23436f2db84a8c788db09","contents":"{'openapi':'3.1.0','paths':{ '/api/users': { 'get': { 'responses':{} }}},'info':{'version':'0.0.0','title':'Empty'}}","index":0}],"refMappings":{}}`;
} else if (method === 'GET' && /api\/apis\/.*\/specs\/.*$/.test(url)) {
return JSON.stringify({
id: 'run-id',
specUrl: `${process.env.BWTS_HOST_OVERRIDE}/spec`,
sourcemapUrl: `${process.env.BWTS_HOST_OVERRIDE}/sourcemap`,
});
}
return JSON.stringify({});
});
Expand Down Expand Up @@ -158,4 +168,20 @@ describe('diff-all', () => {
expect(normalizeWorkspace(workspace, combined)).toMatchSnapshot();
expect(code).toBe(1);
});

test('diff all against a cloud tag', async () => {
const workspace = await setupWorkspace('diff-all/cloud-diff', {
repo: true,
commit: true,
});
process.env.OPTIC_TOKEN = '123';

const { combined, code } = await runOptic(
workspace,
'diff-all --compare-from cloud:main --check'
);

expect(code).toBe(1);
expect(normalizeWorkspace(workspace, combined)).toMatchSnapshot();
});
});
15 changes: 14 additions & 1 deletion projects/optic/src/__tests__/integration/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ paths: {}`;
} else if (method === 'GET' && /spec$/.test(url)) {
return `{"openapi":"3.1.0","paths":{ "/api/users": { "get": { "responses":{} }}},"info":{"version":"0.0.0","title":"Empty"}}`;
} else if (method === 'GET' && /sourcemap$/.test(url)) {
return `{"rootFilePath":"empty.json","files":[{"path":"empty.json","index":0,"contents":{"openapi": "3.1.0","paths": {},"info": {"version": "0.0.0","title": "Empty"},"x-optic-ci-empty-spec": true},"sha256":"841ad837d9488cb03837e695fd2d7dfacacc708465ba8b4e3d2d811428915016"}],"refMappings":{}}`;
return `{"rootFilePath":"empty.json","files":[{"path":"empty.json","sha256":"815b8e5491a1f491765084f236c741d5073e10fcece23436f2db84a8c788db09","contents":"{'openapi':'3.1.0','paths':{ '/api/users': { 'get': { 'responses':{} }}},'info':{'version':'0.0.0','title':'Empty'}}","index":0}],"refMappings":{}}`;
} else if (method === 'GET' && /api\/apis\/.*\/specs\/.*$/.test(url)) {
return JSON.stringify({
id: 'run-id',
Expand Down Expand Up @@ -239,5 +239,18 @@ paths: {}`;
expect(code).toBe(0);
expect(normalizeWorkspace(workspace, combined)).toMatchSnapshot();
});

test('with --base cloud:tag', async () => {
const workspace = await setupWorkspace('diff/upload', {
repo: false,
});
const { combined, code } = await runOptic(
workspace,
`diff spec.json --base cloud:main --check`
);

expect(code).toBe(1);
expect(normalizeWorkspace(workspace, combined)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"openapi": "3.0.1",
"x-optic-url": "https://app.useoptic.com/organizations/org-id/apis/api-id",
"paths": {
"/example": {
"get": {
"operationId": "my-op",
"responses": {}
},
"post": {
"operationId": "postOriginalaa",
"responses": {}
},
"put": {
"operationId": "putOriginalaa",
"responses": {}
},
"patch": {
"operationId": "putOriginaaal",
"responses": {
"200": {
"description": "hello",
"content": {
"application/json": {
"example": "hello",
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"info": {
"version": "0.0.0",
"title": "Empty"
}
}
Loading