Skip to content

Commit

Permalink
fix: service tag names losing casing (#2040)
Browse files Browse the repository at this point in the history
Co-authored-by: Nauman <mnaumanali94@gmail.com>
Co-authored-by: Noah <3588798+Nezteb@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 29, 2022
1 parent ff5c192 commit b171d27
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('API component', () => {

it('navigates via table of contents', () => {
loadZoomApiPage();
cy.findByText('groups').click();
cy.findByText('Groups').click();
cy.findByText('Create a group').click();
cy.findByRole('heading', { name: /Create a group/i }).should('exist');
});
Expand Down
220 changes: 220 additions & 0 deletions packages/elements/src/components/API/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,226 @@ describe('computeTagGroups', () => {
const serviceNode = transformOasToServiceNode(apiDocument);
expect(serviceNode ? computeTagGroups(serviceNode) : null).toEqual({ groups: [], ungrouped: [] });
});

it('leaves tag casing unchanged', () => {
const apiDocument: OpenAPIObject = {
openapi: '3.0.0',
info: {
title: 'some api',
version: '1.0.0',
description: 'some description',
},
tags: [
{
name: 'Beta',
},
{
name: 'alpha',
},
],
paths: {
'/a': {
get: {
tags: ['alpha'],
},
},
'/b': {
get: {
tags: ['Beta'],
},
},
},
};

const serviceNode = transformOasToServiceNode(apiDocument);
expect(serviceNode ? computeTagGroups(serviceNode) : null).toEqual({
groups: [
{
title: 'Beta',
items: [
{
type: 'http_operation',
uri: '/paths/b/get',
data: {
id: '2b447d075652c',
method: 'get',
path: '/b',
responses: [],
servers: [],
request: {
body: {
contents: [],
id: '1b5f96cfcd9cb',
},
headers: [],
query: [],
cookie: [],
path: [],
},
tags: [
{
name: 'Beta',
id: 'c028e10befb64',
},
],
security: [],
extensions: {},
},
name: '/b',
tags: ['Beta'],
},
],
},
{
title: 'alpha',
items: [
{
type: 'http_operation',
uri: '/paths/a/get',
data: {
id: '2b547d0756761',
method: 'get',
path: '/a',
responses: [],
servers: [],
request: {
body: {
contents: [],
id: 'c9a24d63f1884',
},
headers: [],
query: [],
cookie: [],
path: [],
},
tags: [
{
id: '7d65d096f3728',
name: 'alpha',
},
],
security: [],
extensions: {},
},
name: '/a',
tags: ['alpha'],
},
],
},
],
ungrouped: [],
});
});

it('matches mixed tag casing', () => {
const apiDocument: OpenAPIObject = {
openapi: '3.0.0',
info: {
title: 'some api',
version: '1.0.0',
description: 'some description',
},
tags: [
{
name: 'Beta',
},
{
name: 'alpha',
},
],
paths: {
'/a': {
get: {
tags: ['alpha'],
},
},
'/b': {
get: {
tags: ['beta'],
},
},
},
};

const serviceNode = transformOasToServiceNode(apiDocument);
expect(serviceNode ? computeTagGroups(serviceNode) : null).toEqual({
groups: [
{
title: 'Beta',
items: [
{
type: 'http_operation',
uri: '/paths/b/get',
data: {
id: '2b447d075652c',
method: 'get',
path: '/b',
responses: [],
servers: [],
request: {
body: {
contents: [],
id: '1b5f96cfcd9cb',
},
headers: [],
query: [],
cookie: [],
path: [],
},
tags: [
{
id: 'e01820f4e85ed',
name: 'beta',
},
],
security: [],
extensions: {},
},
name: '/b',
tags: ['beta'],
},
],
},
{
title: 'alpha',
items: [
{
type: 'http_operation',
uri: '/paths/a/get',
data: {
id: '2b547d0756761',
method: 'get',
path: '/a',
responses: [],
servers: [],
request: {
body: {
contents: [],
id: 'c9a24d63f1884',
},
headers: [],
query: [],
cookie: [],
path: [],
},
tags: [
{
id: '7d65d096f3728',
name: 'alpha',
},
],
security: [],
extensions: {},
},
name: '/a',
tags: ['alpha'],
},
],
},
],
ungrouped: [],
});
});
});

describe('computeAPITree', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/elements/src/components/API/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const computeTagGroups = (serviceNode: ServiceNode) => {
if (groupsByTagId[tagId]) {
groupsByTagId[tagId].items.push(node);
} else {
const serviceTagName = lowerCaseServiceTags.find(tn => tn === tagId);
const serviceTagIndex = lowerCaseServiceTags.findIndex(tn => tn === tagId);
const serviceTagName = serviceNode.tags[serviceTagIndex];
groupsByTagId[tagId] = {
title: serviceTagName || tagName,
items: [node],
Expand Down

0 comments on commit b171d27

Please sign in to comment.