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

feat: enable v3 support #360

Merged
merged 30 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
22c2195
add request/reply
jonaslagoni Aug 3, 2023
82dea58
bunch of changes
jonaslagoni Aug 11, 2023
f8bc91f
Merge branch 'master' into v3_update
jonaslagoni Aug 11, 2023
e2f0bc7
additional change
jonaslagoni Aug 11, 2023
1db9ad4
fix code smells
jonaslagoni Aug 11, 2023
8f67957
update dependency
jonaslagoni Aug 11, 2023
165c81a
update react sdk version
jonaslagoni Aug 11, 2023
981481a
update react-sdk dependency
jonaslagoni Aug 11, 2023
83a70f4
update dependency
jonaslagoni Aug 11, 2023
0ca3c9d
Merge branch 'upstream-master' into v3_update
jonaslagoni Aug 11, 2023
3e73a9c
update template
jonaslagoni Sep 11, 2023
34a96d5
switch generator dependency
jonaslagoni Sep 14, 2023
e83cfb4
Merge branch 'upstream-master' into v3_update
jonaslagoni Sep 14, 2023
9b75faf
add better testing
jonaslagoni Sep 28, 2023
a9d9508
add workflow to test with generator
jonaslagoni Sep 28, 2023
16aba7f
update cli
jonaslagoni Sep 28, 2023
792bdc2
Merge branch 'master' into v3_update
jonaslagoni Sep 28, 2023
dd12d90
update generator requirement
jonaslagoni Sep 28, 2023
de08455
Merge branch 'upstream-master' into v3_update
jonaslagoni Oct 4, 2023
fdf3443
update dependency
jonaslagoni Oct 4, 2023
5f66a73
use custom operation for v3
jonaslagoni Oct 5, 2023
d77b5c6
refactor operations
jonaslagoni Oct 6, 2023
b97e8da
refactor test setup
jonaslagoni Oct 6, 2023
6c482df
ignore missing props validation
jonaslagoni Oct 6, 2023
8546ce3
ignore missing props validation
jonaslagoni Oct 6, 2023
e61cc54
ignore missing props validation
jonaslagoni Oct 6, 2023
ddd9eaa
ignore missing props validation
jonaslagoni Oct 6, 2023
a46a7ea
ignore missing props validation
jonaslagoni Oct 6, 2023
d4b7a5b
ignore missing props validation
jonaslagoni Oct 6, 2023
507774b
ignore missing props validation
jonaslagoni Oct 6, 2023
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
26 changes: 26 additions & 0 deletions components/Asyncapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import { Info } from './Info';
import { Servers } from './Servers';
import { Operations } from './Operations';
import { FrontMatter } from './FrontMatter';
import { TableOfContents } from './TableOfContents';

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

/**
* @param {{asyncapi: AsyncAPIDocumentInterface, params: any}} param0
*/
export function Asyncapi({ asyncapi, params }) {
jonaslagoni marked this conversation as resolved.
Show resolved Hide resolved
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} />
</>
);
}

168 changes: 136 additions & 32 deletions components/Operations.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,57 @@
import { Text } from '@asyncapi/generator-react-sdk';

import { Bindings } from './Bindings';
import { Extensions } from './Extensions';
import { Message } from './Message';
import { Schema } from './Schema';
import { Security } from './Security';
import { Tags } from './Tags';
import { Header, ListItem, Link } from './common';

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';

/**
* @param {{asyncapi: AsyncAPIDocumentInterface}} param0
*/
export function Operations({ asyncapi }) {
const channels = asyncapi.channels();
if (channels.isEmpty()) {
return null;
}

const operationsList = [];
channels.all().map(channel => {
for (const channel of channels.all()) {
const channelName = channel.address();
channel.operations().all().forEach(operation => {
if (operation.action() === 'publish') {
operationsList.push(
<Operation
key={`pub-${channelName}`}
type='publish'
asyncapi={asyncapi}
operation={operation}
channelName={channelName}
channel={channel}
/>
);
}
if (operation.action() === 'subscribe') {
operationsList.push(
<Operation
key={`sub-${channelName}`}
type='subscribe'
asyncapi={asyncapi}
operation={operation}
channelName={channelName}
channel={channel}
/>
);
const operations = channel.operations().all();
operations.map(operation => {
let type;
if (operation.isSend()) {
if (operation.reply() !== undefined) {
type = 'request';
} else {
type = 'publish';
}
} else if (operation.isReceive()) {
if (operation.reply() !== undefined) {
type = 'response';
} else {
type = 'subscribe';
}
}
operationsList.push(
<Operation
key={`${operation.action()}-${channelName}`}
type={type}
asyncapi={asyncapi}
operation={operation}
channelName={channelName}
channel={channel}
/>
);
});
});
}

return (
<>
Expand All @@ -58,7 +63,10 @@ export function Operations({ asyncapi }) {
);
}

function Operation({ type, asyncapi, operation, channelName, channel }) { // NOSONAR
/**
* @param {{asyncapi: AsyncAPIDocumentInterface, type: string, operation: OperationInterface, channelName: string, channel: ChannelInterface}} param0
*/
function Operation({ asyncapi, type, operation, channelName, channel }) { // NOSONAR
if (!operation || !channel) {
return null;
}
Expand All @@ -68,7 +76,21 @@ function Operation({ type, asyncapi, operation, channelName, channel }) { // NOS
const applyToAllServers = asyncapi.servers().all().length === channel.servers().all().length;
const servers = applyToAllServers ? [] : channel.servers().all();
const security = operation.security();
const renderedType = type === 'publish' ? 'PUB' : 'SUB';
let renderedType;
switch (type) {
case 'request':
renderedType = 'REQUEST';
break;
case 'publish':
renderedType = 'PUB';
break;
case 'response':
renderedType = 'RESPONSE';
break;
case 'subscribe':
renderedType = 'SUB';
break;
}
const showInfoList = operationId || (servers && servers.length);

return (
Expand Down Expand Up @@ -139,10 +161,14 @@ function Operation({ type, asyncapi, operation, channelName, channel }) { // NOS
<Extensions name="Operation extensions" item={operation} />

<OperationMessages operation={operation} />

<OperationReply operation={operation} />
</Text>
);
}

/**
* @param {{channel: ChannelInterface}} param0
*/
function OperationParameters({ channel }) {
const parameters = SchemaHelpers.parametersToSchema(channel.parameters().all());
if (!parameters) {
Expand All @@ -156,7 +182,9 @@ function OperationParameters({ channel }) {
</Text>
);
}

/**
* @param {{operation: OperationInterface}} param0
*/
function OperationMessages({ operation }) {
const messages = operation.messages().all();
if (messages.length === 0) {
Expand All @@ -176,3 +204,79 @@ function OperationMessages({ operation }) {
</>
);
}

/**
* @param {{operation: OperationInterface}} param0
*/
function OperationReply({ operation }) {
const reply = operation.reply();
if (reply === undefined) {
return null;
}
const replyId = reply.id();
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>

{replyId && <ListItem>Operation reply ID: `{replyId}`</ListItem>}

{explicitChannel && <ListItem>{type} should be done to channel: `{reply.channel().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 addressId = address.id();
const location = address.location();

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

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

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

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