Skip to content
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

fix: internal schema apprears as object on logout #2705

Merged
merged 13 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion packages/elements-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-core",
"version": "8.4.5",
"version": "8.4.6",
"sideEffects": [
"web-components.min.js",
"src/web-components/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,53 @@ describe('createResolvedObject', () => {

expect(resolvedObject).toEqual(originalObject);
});

it('removes object if contains an error for oneOf', () => {
const originalObject = {
SB-harshitajadhav marked this conversation as resolved.
Show resolved Hide resolved
oneOf: [
{ $ref: '#/__bundled__/0mui9s02880hl', 'x-stoplight': { id: '19c178fc05d4a' } },
{
'x-sl-error-message': 'You do not have permission to view this reference',
'x-stoplight': { 'error-message': 'You do not have permission to view this reference', id: 'nezai0hyj4yak' },
},
{ $ref: '#/__bundled__/iq2mwk8jvthd2', 'x-stoplight': { id: 'ovj32wmpxpg7p' } },
],
'x-stoplight': { id: 'b73ff5df9864f' },
};

const resolvedObject = getOriginalObject(originalObject);
const filteredObject = {
oneOf: [
{ $ref: '#/__bundled__/0mui9s02880hl', 'x-stoplight': { id: '19c178fc05d4a' } },
{ $ref: '#/__bundled__/iq2mwk8jvthd2', 'x-stoplight': { id: 'ovj32wmpxpg7p' } },
],
'x-stoplight': { id: 'b73ff5df9864f' },
};

expect(resolvedObject).toEqual(filteredObject);
});

it('removes object if contains an error for anyeOf', () => {
const originalObject = {
anyOf: [
{ $ref: '#/__bundled__/0mui9s02880hl', 'x-stoplight': { id: '19c178fc05d4a' } },
{
'x-sl-error-message': 'You do not have permission to view this reference',
'x-stoplight': { 'error-message': 'You do not have permission to view this reference', id: 'nezai0hyj4yak' },
},
{ $ref: '#/__bundled__/iq2mwk8jvthd2', 'x-stoplight': { id: 'ovj32wmpxpg7p' } },
],
'x-stoplight': { id: 'b73ff5df9864f' },
};

const resolvedObject = getOriginalObject(originalObject);
const filteredObject = {
anyOf: [
{ $ref: '#/__bundled__/0mui9s02880hl', 'x-stoplight': { id: '19c178fc05d4a' } },
{ $ref: '#/__bundled__/iq2mwk8jvthd2', 'x-stoplight': { id: 'ovj32wmpxpg7p' } },
],
'x-stoplight': { id: 'b73ff5df9864f' },
};
expect(resolvedObject).toEqual(filteredObject);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,30 @@ export const isResolvedObjectProxy = (someObject: object): boolean => {
};

export const getOriginalObject = (resolvedObject: object): object => {
return (resolvedObject as Record<symbol, object>)[originalObjectSymbol] || resolvedObject;
const originalObject: any = (resolvedObject as Record<symbol, object>)[originalObjectSymbol] || resolvedObject;
bhaskarsontakke marked this conversation as resolved.
Show resolved Hide resolved
if (!originalObject) {
return resolvedObject;
}

const hasAllSchemaErrors = (array: any[]) => {
return array.every(item => item['x-sl-error-message'] !== undefined);
};

if (originalObject.anyOf) {
if (hasAllSchemaErrors(originalObject.anyOf)) {
return { ...originalObject, anyOf: [originalObject.anyOf] };
}
const filteredArray = originalObject.anyOf.filter((item: { [x: string]: any }) => !item['x-sl-error-message']);
return { ...originalObject, anyOf: filteredArray };
} else if (originalObject.oneOf) {
if (hasAllSchemaErrors(originalObject.oneOf)) {
return { ...originalObject, oneOf: [originalObject.oneOf] };
}
const filteredArray = originalObject.oneOf.filter((item: { [x: string]: any }) => !item['x-sl-error-message']);
return { ...originalObject, oneOf: filteredArray };
}

return originalObject;
};

export const isReference = hasRef;
4 changes: 2 additions & 2 deletions packages/elements-dev-portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-dev-portal",
"version": "2.4.6",
"version": "2.4.7",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -66,7 +66,7 @@
"dependencies": {
"@stoplight/markdown-viewer": "^5.7.1",
"@stoplight/mosaic": "^1.53.4",
"@stoplight/elements-core": "^8.4.5",
"@stoplight/elements-core": "^8.4.6",
"@stoplight/path": "^1.3.2",
"@stoplight/types": "^14.0.0",
"classnames": "^2.2.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements",
"version": "8.4.5",
"version": "8.4.6",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -63,7 +63,7 @@
]
},
"dependencies": {
"@stoplight/elements-core": "^8.4.5",
"@stoplight/elements-core": "^8.4.6",
"@stoplight/http-spec": "^7.1.0",
"@stoplight/json": "^3.18.1",
"@stoplight/mosaic": "^1.53.4",
Expand Down