Skip to content

Commit

Permalink
use custom operation for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Oct 5, 2023
1 parent fdf3443 commit 5f66a73
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 82 deletions.
9 changes: 7 additions & 2 deletions components/Asyncapi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { Info } from './Info';
import { Servers } from './Servers';
import { Operations } from './Operations';
Expand All @@ -7,19 +6,25 @@ import { TableOfContents } from './TableOfContents';

// eslint-disable-next-line no-unused-vars
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
import { Operationsv3 } from './Operationsv3';

/**
* @param {{asyncapi: AsyncAPIDocumentInterface, params: any}} param0
*/
export function Asyncapi({ asyncapi, params }) {
const isV3 = asyncapi.version().split('.')[0] === '3';
return (
<>
{params.frontMatter && <FrontMatter asyncapi={asyncapi} params={params} />}
<Info asyncapi={asyncapi} params={params} />
{params.toc !== 'false' && <TableOfContents asyncapi={asyncapi} />}

<Servers asyncapi={asyncapi} />
<Operations asyncapi={asyncapi} />
{
isV3 ?
<Operationsv3 asyncapi={asyncapi} /> :
<Operations asyncapi={asyncapi} />
}
</>
);
}
Expand Down
81 changes: 1 addition & 80 deletions components/Operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SchemaHelpers } from '../helpers/schema';
import { FormatHelpers } from '../helpers/format';

// eslint-disable-next-line no-unused-vars
import { AsyncAPIDocumentInterface, OperationInterface, OperationReplyInterface, ChannelInterface } from '@asyncapi/parser';
import { AsyncAPIDocumentInterface, OperationInterface, ChannelInterface } from '@asyncapi/parser';

/**
* @param {{asyncapi: AsyncAPIDocumentInterface}} param0
Expand Down Expand Up @@ -78,15 +78,9 @@ function Operation({ asyncapi, type, operation, channelName, channel }) { // NOS
const security = operation.security();
let renderedType;
switch (type) {
case 'request':
renderedType = 'REQUEST';
break;
case 'publish':
renderedType = 'PUB';
break;
case 'reply':
renderedType = 'REPLY';
break;
case 'subscribe':
renderedType = 'SUB';
break;
Expand Down Expand Up @@ -161,8 +155,6 @@ function Operation({ asyncapi, type, operation, channelName, channel }) { // NOS
<Extensions name="Operation extensions" item={operation} />

<OperationMessages operation={operation} />

<OperationReply operation={operation} />
</Text>
);
}
Expand Down Expand Up @@ -204,74 +196,3 @@ function OperationMessages({ operation }) {
</>
);
}

/**
* @param {{operation: OperationInterface}} param0
*/
function OperationReply({ operation }) {
const reply = operation.reply();
if (reply === undefined) {
return null;
}
const explicitChannel = reply.channel();

let type;
if (operation.isSend()) {
type = 'Request';
} else if (operation.isReceive()) {
type = 'Response';
}

return (
<Text>
<Header type={4}>
{`${type} information`}
</Header>

{explicitChannel && <ListItem>{type} should be done to channel: `{explicitChannel.address()}`</ListItem>}

<OperationReplyAddress name="Operation reply address" reply={reply} />

<>
{reply.messages().length > 1 && (
<Text newLines={2}>
Accepts **one of** the following messages:
</Text>
)}
{reply.messages().length > 1 && reply.messages().map((msg, idx) => (
<Message message={msg} key={`message-${idx}`} />
))}
</>
<Extensions name="Operation reply extensions" item={reply} />
</Text>
);
}

/**
* @param {{reply: OperationReplyInterface}} param0
*/
function OperationReplyAddress({ reply }) {
const address = reply.address();
if (address === undefined) {
return null;
}
const location = address.location();

return (
<Text>
<Header type={4}>
{'Operation reply address information'}
</Header>

{address.hasDescription() && (
<Text newLines={2}>
{address.description()}
</Text>
)}

<ListItem>Operation reply address location: `{location}`</ListItem>

<Extensions name="Operation reply address extensions" item={address} />
</Text>
);
}
Loading

0 comments on commit 5f66a73

Please sign in to comment.