Skip to content

Commit

Permalink
feat!: render bindings, extensions and circular references (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored Jan 18, 2022
1 parent 55f2ea3 commit e333440
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 659 deletions.
27 changes: 27 additions & 0 deletions components/Bindings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Schema } from "./Schema";

import { SchemaHelpers } from "../helpers/schema"
import { FormatHelpers } from "../helpers/format";

export function Bindings({ name = 'Binding specific information', item }) {
const bindings = item.bindings();
if (!bindings || !Object.keys(bindings).length) {
return null;
}

const renderBindings = Object.entries(bindings).map(
([bindingName, binding]) => {
const schema = SchemaHelpers.jsonToSchema(binding);
const schemaName = `${FormatHelpers.inlineCode(bindingName)} ${name}`;
return (
<Schema schemaName={schemaName} schema={schema} key={bindingName} />
);
},
);

return (
<>
{renderBindings}
</>
);
}
2 changes: 1 addition & 1 deletion components/Extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const Extensions = ({ name = 'Extensions', item }) => {
return (
<Schema schemaName={name} schema={schema} />
);
};
};
5 changes: 1 addition & 4 deletions components/Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ export function Info({ asyncapi, params = {} }) {
)}

{asyncapi.hasTags() && (
<>
<Header type={6}>Specification tags</Header>
<Tags tags={asyncapi.tags()} />
</>
<Tags name="Specification tags" tags={asyncapi.tags()} />
)}
</Text>
);
Expand Down
13 changes: 9 additions & 4 deletions components/Message.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IndentationTypes, Text } from "@asyncapi/generator-react-sdk";
import { generateExample, getPayloadExamples, getHeadersExamples } from "@asyncapi/generator-filters";

import { Bindings } from "./Bindings";
import { Extensions } from "./Extensions";
import { Schema } from "./Schema";
import { Tags } from "./Tags";
import { Header, ListItem, Link, BlockQuote, CodeBlock, NewLine } from "./common";
Expand Down Expand Up @@ -97,11 +99,14 @@ export function Message({ message }) {
</>
)}

<Bindings
name="Message specific information"
item={message}
/>
<Extensions name="Message extensions" item={message} />

{message.hasTags() && (
<>
<Header type={6}>Message tags</Header>
<Tags tags={message.tags()} />
</>
<Tags name="Message tags" tags={message.tags()} />
)}
</>
)
Expand Down
20 changes: 16 additions & 4 deletions components/Operations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Text } from "@asyncapi/generator-react-sdk";

import { Bindings } from "./Bindings";
import { Extensions } from "./Extensions";
import { Message } from "./Message";
import { Schema } from "./Schema";
import { Tags } from "./Tags";
Expand Down Expand Up @@ -111,13 +113,23 @@ function Operation({ type, operation, channelName, channel }) {
)}

{operation.hasTags() && (
<>
<Header type={6}>Operation tags</Header>
<Tags tags={operation.tags()} />
</>
<Tags name="Operation tags" tags={operation.tags()} />
)}

<OperationParameters channel={channel} />

<Bindings
name="Channel specific information"
item={channel}
/>
<Bindings
name="Operation specific information"
item={operation}
/>

<Extensions name="Channel extensions" item={channel} />
<Extensions name="Operation extensions" item={operation} />

<OperationMessages operation={operation} />
</Text>
);
Expand Down
6 changes: 1 addition & 5 deletions components/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function SchemaProperties({ schema, schemaName, path }) {

const required = schema.required() || [];
const patternProperties = schema.patternProperties();
const circularProps = schema.circularProps() || [];

return (
<>
Expand All @@ -87,7 +86,6 @@ function SchemaProperties({ schema, schemaName, path }) {
schemaName={propertyName}
path={buildPath(path || schemaName, propertyName)}
required={required.includes(propertyName)}
isCircular={circularProps.includes(propertyName)}
dependentRequired={SchemaHelpers.getDependentRequired(
propertyName,
schema,
Expand All @@ -100,7 +98,6 @@ function SchemaProperties({ schema, schemaName, path }) {
schema={property}
schemaName={propertyName}
path={buildPath(path || schemaName, propertyName)}
isCircular={circularProps.includes(propertyName)}
nameNote='pattern property'
key={propertyName}
/>
Expand Down Expand Up @@ -192,7 +189,6 @@ function SchemaPropRow({
required = false,
dependentRequired = [],
path = '',
isCircular = false,
nameNote = '',
tryRenderAdditionalNotes = true,
}) {
Expand All @@ -205,7 +201,7 @@ function SchemaPropRow({
return null;
}

isCircular = isCircular || schema.ext('x-parser-circular') || false;
const isCircular = schema.isCircular() || false;
const renderType = schema.ext(SchemaHelpers.extRenderType) !== false;
const rawValue = schema.ext(SchemaHelpers.extRawValue) === true;

Expand Down
13 changes: 11 additions & 2 deletions components/Servers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IndentationTypes, Text } from "@asyncapi/generator-react-sdk";

import { Bindings } from "./Bindings";
import { Extensions } from "./Extensions";
import { Header, ListItem, Link, Table, NewLine } from "./common";

import { ServerHelpers } from "../helpers/server";
import { FormatHelpers } from "../helpers/format";

Expand All @@ -24,12 +27,18 @@ export function Servers({ asyncapi }) {

function Server({ serverName, server, asyncapi }) {
return (
<>
<Text>
<Header type={3}>{`\`${serverName}\` Server`}</Header>
<ServerInfo server={server} />
<ServerVariables variables={server.variables()} />
<ServerSecurity protocol={server.protocol()} security={server.security()} asyncapi={asyncapi} />
</>

<Bindings
name="Server specific information"
item={server}
/>
<Extensions name="Server extensions" item={server} />
</Text>
);
}

Expand Down
51 changes: 17 additions & 34 deletions components/Tags.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
import { IndentationTypes, Text } from "@asyncapi/generator-react-sdk";
import { Text } from "@asyncapi/generator-react-sdk";

import { ListItem, Link } from "./common";
import { Header, Table } from "./common";

export function Tags({ tags = [] }) {
export function Tags({ name = 'Tags', tags = [] }) {
if (tags.length === 0) {
return null
}

return (
<>
{tags.map(tag => (
<Tag tag={tag} key={tag.name()} />
))}
</>
);
}

function Tag({ tag }) {
const description = tag.description();
const externalDocs = tag.externalDocs();
const tagsHeader = ['Name', 'Description', 'Documentation'];
const tagsRenderer = (tag) => {
const externalDocs = tag.externalDocs();
const externalDocsDescription = externalDocs && externalDocs.hasDescription() ? externalDocs.description() : 'Find more info here';
return [
tag.name() || '-',
tag.description() || '-',
externalDocs ? `[${externalDocsDescription}](${externalDocs.url()})` : '-',
];
}

return (
<>
<Text>
<ListItem>{tag.name()}</ListItem>
</Text>
{description && (
<Text indent={2} type={IndentationTypes.SPACES}>
{description}
</Text>
)}
{externalDocs && (
<Text indent={2} type={IndentationTypes.SPACES}>
<Link
href={externalDocs.url()}
>
{externalDocs.hasDescription() ? externalDocs.description() : 'Find more info here.'}
</Link>
</Text>
)}
</>
<Text>
<Header type={5}>{name}</Header>
<Table headers={tagsHeader} rowRenderer={tagsRenderer} data={tags} />
</Text>
);
}
Loading

0 comments on commit e333440

Please sign in to comment.