Skip to content

Commit

Permalink
fix: prefix operation ids with parent id (#1245)
Browse files Browse the repository at this point in the history
Co-authored-by: ben.blowers <ben.blowers@imanage.com>
Co-authored-by: anastasiia-developer <anastasiia@redocly.com>
  • Loading branch information
3 people authored Apr 12, 2022
1 parent 1e80dd6 commit fd8917e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e/integration/menu.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Menu', () => {
cy.location('hash').should('equal', '#tag/pet');

cy.contains('[role=menuitem]', 'Find pet by ID').click({ force: true });
cy.location('hash').should('equal', '#operation/getPetById');
cy.location('hash').should('equal', '#tag/pet/operation/getPetById');
});

it('should deactivate tag when other is activated', () => {
Expand Down
8 changes: 4 additions & 4 deletions e2e/integration/misc.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ describe('Servers', () => {
initReDoc(win, spec, {});

// TODO add cy-data attributes
cy.get('[data-section-id="operation/addPet"]').should(
cy.get('[data-section-id="tag/pet/operation/addPet"]').should(
'contain',
'http://petstore.swagger.io/v2/pet',
);

cy.get('[data-section-id="operation/addPet"]').should(
cy.get('[data-section-id="tag/pet/operation/addPet"]').should(
'contain',
'http://petstore.swagger.io/sandbox/pet',
);
Expand All @@ -40,7 +40,7 @@ describe('Servers', () => {
initReDoc(win, spec, {});

// TODO add cy-data attributes
cy.get('[data-section-id="operation/addPet"]').should(
cy.get('[data-section-id="tag/pet/operation/addPet"]').should(
'contain',
'http://localhost:' + win.location.port + '/pet',
);
Expand All @@ -55,7 +55,7 @@ describe('Servers', () => {
initReDoc(win, spec, {});

// TODO add cy-data attributes
cy.get('[data-section-id="operation/addPet"]').should(
cy.get('[data-section-id="tag/pet/operation/addPet"]').should(
'contain',
'http://localhost:' + win.location.port + '/pet',
);
Expand Down
19 changes: 19 additions & 0 deletions e2e/integration/urls.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('Supporting both operation/* and parent/*/operation* urls', () => {
beforeEach(() => {
cy.visit('e2e/standalone.html');
});

it('should supporting operation/* url', () => {
cy.url().then(loc => {
cy.visit(loc + '#operation/updatePet');
cy.get('li[data-item-id="tag/pet/operation/updatePet"]').should('be.visible');
});
});

it('should supporting parent/*/operation url', () => {
cy.url().then(loc => {
cy.visit(loc + '#tag/pet/operation/addPet');
cy.get('li[data-item-id="tag/pet/operation/addPet"]').should('be.visible');
});
});
});
3 changes: 2 additions & 1 deletion src/components/Operation/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RequestSamples } from '../RequestSamples/RequestSamples';
import { ResponsesList } from '../Responses/ResponsesList';
import { ResponseSamples } from '../ResponseSamples/ResponseSamples';
import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement';
import { SECTION_ATTR } from '../../services';

const Description = styled.div`
margin-bottom: ${({ theme }) => theme.spacing.unit * 6}px;
Expand All @@ -37,7 +38,7 @@ export class Operation extends React.Component<OperationProps> {
return (
<OptionsContext.Consumer>
{options => (
<Row>
<Row {...{ [SECTION_ATTR]: operation.operationHash }} id={operation.operationHash}>
<MiddlePanel>
<H2>
<ShareLink to={operation.id} />
Expand Down
4 changes: 3 additions & 1 deletion src/services/models/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class OperationModel implements IMenuItem {

pointer: string;
operationId?: string;
operationHash?: string;
httpVerb: string;
deprecated: boolean;
path: string;
Expand Down Expand Up @@ -123,9 +124,10 @@ export class OperationModel implements IMenuItem {
// TODO: update getting pathInfo for overriding servers on path level
this.servers = normalizeServers('', operationSpec.servers || operationSpec.pathServers || []);
} else {
this.operationHash = operationSpec.operationId && 'operation/' + operationSpec.operationId
this.id =
operationSpec.operationId !== undefined
? 'operation/' + operationSpec.operationId
? (parent ? parent.id + '/' : '') + this.operationHash
: parent !== undefined
? parent.id + this.pointer
: this.pointer;
Expand Down

0 comments on commit fd8917e

Please sign in to comment.