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: support 2.1.0 spec version #129

Merged
merged 5 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 21 additions & 25 deletions components/Message.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Text } from "@asyncapi/generator-react-sdk";
import { generateExample, getHeadersExamples, getPayloadExamples } from "@asyncapi/generator-filters";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this change to a custom functions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHeadersExamples or getPayloadExamples only return the examples[*].headers or examples[*].payload, so we don't have corresponding name or summary for appropriate example. If we will have change from PR in @asyncapi/generator-filters we must know that then it's a breaking change and we must update check all templates where we use the getHeadersExamples and getPayloadExamples. Making changes only here is safe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHeadersExamples or getPayloadExamples are more than what you wrote, if examples are not in examples object, they are taken from payload or headers schema (if provided of course).

we can release generator-filters 2.0 🤷🏼 unless you already have your own versions of these functions in react component. Then we are just looking an effort we did in the past to move generic functions to @asyncapi/generator-filters

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHeadersExamples or getPayloadExamples are more than what you wrote, if examples are not in examples object, they are taken from payload or headers schema (if provided of course).

Functions in PR also are looking for that :)

we can release generator-filters 2.0 🤷🏼 unless you already have your own versions of these functions in react component. Then we are just looking an effort we did in the past to move generic functions to @asyncapi/generator-filters

So I will create PR in generator-filters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { generateExample, getPayloadExamples, getHeadersExamples } from "@asyncapi/generator-filters";

import { Header, ListItem, CodeBlock, BlockQuote } from "./common";
import { Header, CodeBlock, BlockQuote, Tags } from "./common";
import { Schema } from "./Schema";

export function Message({ message, title = 'Message' }) {
Expand All @@ -23,15 +23,15 @@ export function Message({ message, title = 'Message' }) {
<>
<Header type={6}>Headers</Header>
<Schema schema={message.headers()} schemaName='Message Headers' hideTitle={true} />
<Example type='headers' message={message} />
<Examples type='headers' message={message} />
</>
)}

{message.payload() && (
<>
<Header type={6}>Payload</Header>
<Schema schema={message.payload()} schemaName='Message Payload' hideTitle={true} />
<Example type='payload' message={message} />
<Examples type='payload' message={message} />
</>
)}

Expand All @@ -45,28 +45,14 @@ export function Message({ message, title = 'Message' }) {
)
}

function Tags({ tags = [] }) {
return (
<Text>
{tags.map(tag => (
<ListItem>{tag.name()}</ListItem>
))}
</Text>
);
}

function Example({ type = 'headers', message }) {
function Examples({ type = 'headers', message }) {
if (type === 'headers') {
const examples = getHeadersExamples(message);
if (examples) {
return (
<>
<BlockQuote>Examples of headers</BlockQuote>
{examples.map(ex => (
<Text newLines={2}>
<CodeBlock language='json'>{JSON.stringify(ex, null, 2)}</CodeBlock>
</Text>
))}
<Example examples={examples} />
</>
);
}
Expand All @@ -85,11 +71,7 @@ function Example({ type = 'headers', message }) {
return (
<>
<BlockQuote>Examples of payload</BlockQuote>
{examples.map(ex => (
<Text newLines={2}>
<CodeBlock language='json'>{JSON.stringify(ex, null, 2)}</CodeBlock>
</Text>
))}
<Example examples={examples} />
</>
);
}
Expand All @@ -104,3 +86,17 @@ function Example({ type = 'headers', message }) {
);
}
}

function Example({ examples = [] }) {
if (examples.length === 0) {
return null;
}

return examples.map(ex => (
<Text newLines={2}>
{ex.name && <Text newLines={2}>**{ex.name}**</Text>}
{ex.summary && <Text newLines={2}>{ex.summary}</Text>}
<CodeBlock language='json'>{JSON.stringify(ex.example, null, 2)}</CodeBlock>
</Text>
))
}
9 changes: 9 additions & 0 deletions components/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ export function BlockQuote({ childrenContent = "" }) {
return <Text newLines={2}>{`> ${childrenContent}`}</Text>
}

export function Tags({ tags = [] }) {
return (
<Text>
{tags.map(tag => (
<ListItem>{tag.name()}</ListItem>
))}
</Text>
);
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"access": "public"
},
"dependencies": {
"@asyncapi/generator-filters": "^1.1.0",
"@asyncapi/generator-filters": "^2.0.0",
"@asyncapi/generator-react-sdk": "^0.2.11",
"yaml": "^1.10.0"
},
Expand Down