From 2f7da394cf1fc14637ef9a289c5b220bdb6971ea Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Fri, 25 Jun 2021 10:58:55 +0200 Subject: [PATCH 1/4] support 2.1.0 spec version --- components/Message.js | 21 ++++++--------- components/common.js | 9 +++++++ helpers/index.js | 1 + helpers/schema-examples.js | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 helpers/index.js create mode 100644 helpers/schema-examples.js diff --git a/components/Message.js b/components/Message.js index 0c6fb2f86..dc0ad7d75 100644 --- a/components/Message.js +++ b/components/Message.js @@ -1,7 +1,8 @@ import { Text } from "@asyncapi/generator-react-sdk"; -import { generateExample, getHeadersExamples, getPayloadExamples } from "@asyncapi/generator-filters"; +import { generateExample } from "@asyncapi/generator-filters"; -import { Header, ListItem, CodeBlock, BlockQuote } from "./common"; +import { Header, CodeBlock, BlockQuote, Tags } from "./common"; +import { getPayloadExamples, getHeadersExamples } from "./helpers"; import { Schema } from "./Schema"; export function Message({ message, title = 'Message' }) { @@ -45,16 +46,6 @@ export function Message({ message, title = 'Message' }) { ) } -function Tags({ tags = [] }) { - return ( - - {tags.map(tag => ( - {tag.name()} - ))} - - ); -} - function Example({ type = 'headers', message }) { if (type === 'headers') { const examples = getHeadersExamples(message); @@ -64,6 +55,8 @@ function Example({ type = 'headers', message }) {
Examples of headers
{examples.map(ex => ( + {ex.name && {ex.name}} + {ex.summary && {ex.summary}} {JSON.stringify(ex, null, 2)} ))} @@ -87,7 +80,9 @@ function Example({ type = 'headers', message }) {
Examples of payload
{examples.map(ex => ( - {JSON.stringify(ex, null, 2)} + {ex.name && {ex.name}} + {ex.summary && {ex.summary}} + {JSON.stringify(ex.example, null, 2)} ))} diff --git a/components/common.js b/components/common.js index 2d3509035..f4b34eed6 100644 --- a/components/common.js +++ b/components/common.js @@ -57,3 +57,12 @@ export function BlockQuote({ childrenContent = "" }) { return {`> ${childrenContent}`} } +export function Tags({ tags = [] }) { + return ( + + {tags.map(tag => ( + {tag.name()} + ))} + + ); +} diff --git a/helpers/index.js b/helpers/index.js new file mode 100644 index 000000000..1518fe59c --- /dev/null +++ b/helpers/index.js @@ -0,0 +1 @@ +export * from "./schema-examples"; \ No newline at end of file diff --git a/helpers/schema-examples.js b/helpers/schema-examples.js new file mode 100644 index 000000000..2fe9c4b2a --- /dev/null +++ b/helpers/schema-examples.js @@ -0,0 +1,53 @@ +export function getPayloadExamples(msg) { + const examples = msg.examples(); + if (Array.isArray(examples) && examples.some(e => e.payload)) { + const messageExamples = examples + .flatMap(e => { + if (!e.payload) return; + return { + name: e.name, + summary: e.summary, + example: e.payload, + }; + }) + .filter(Boolean); + + if (messageExamples.length > 0) { + return messageExamples; + } + } + + const payload = msg.payload(); + if (payload && payload.examples()) { + return payload.examples().map(example => ({ example })); + } + + return; +} + +export function getHeadersExamples(msg) { + const examples = msg.examples(); + if (Array.isArray(examples) && examples.some(e => e.headers)) { + const messageExamples = examples + .flatMap(e => { + if (!e.headers) return; + return { + name: e.name, + summary: e.summary, + example: e.headers, + }; + }) + .filter(Boolean); + + if (messageExamples.length > 0) { + return messageExamples; + } + } + + const headers = msg.headers(); + if (headers && headers.examples()) { + return headers.examples().map(example => ({ example })); + } + + return; +} From 751f88255f3e113f5c5c41cf0d4e3979fea2fb98 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Tue, 29 Jun 2021 13:46:23 +0200 Subject: [PATCH 2/4] update deps --- components/Message.js | 11 ++++---- helpers/index.js | 1 - helpers/schema-examples.js | 53 -------------------------------------- package-lock.json | 46 +++++++++++++++++++++++---------- package.json | 4 +-- 5 files changed, 39 insertions(+), 76 deletions(-) delete mode 100644 helpers/index.js delete mode 100644 helpers/schema-examples.js diff --git a/components/Message.js b/components/Message.js index dc0ad7d75..0874dc5bb 100644 --- a/components/Message.js +++ b/components/Message.js @@ -1,8 +1,7 @@ import { Text } from "@asyncapi/generator-react-sdk"; -import { generateExample } from "@asyncapi/generator-filters"; +import { generateExample, getPayloadExamples, getHeadersExamples } from "@asyncapi/generator-filters"; import { Header, CodeBlock, BlockQuote, Tags } from "./common"; -import { getPayloadExamples, getHeadersExamples } from "./helpers"; import { Schema } from "./Schema"; export function Message({ message, title = 'Message' }) { @@ -55,8 +54,8 @@ function Example({ type = 'headers', message }) {
Examples of headers
{examples.map(ex => ( - {ex.name && {ex.name}} - {ex.summary && {ex.summary}} + {ex.name && **{ex.name}**} + {ex.summary && {ex.summary}} {JSON.stringify(ex, null, 2)} ))} @@ -80,8 +79,8 @@ function Example({ type = 'headers', message }) {
Examples of payload
{examples.map(ex => ( - {ex.name && {ex.name}} - {ex.summary && {ex.summary}} + {ex.name && **{ex.name}**} + {ex.summary && {ex.summary}} {JSON.stringify(ex.example, null, 2)} ))} diff --git a/helpers/index.js b/helpers/index.js deleted file mode 100644 index 1518fe59c..000000000 --- a/helpers/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./schema-examples"; \ No newline at end of file diff --git a/helpers/schema-examples.js b/helpers/schema-examples.js deleted file mode 100644 index 2fe9c4b2a..000000000 --- a/helpers/schema-examples.js +++ /dev/null @@ -1,53 +0,0 @@ -export function getPayloadExamples(msg) { - const examples = msg.examples(); - if (Array.isArray(examples) && examples.some(e => e.payload)) { - const messageExamples = examples - .flatMap(e => { - if (!e.payload) return; - return { - name: e.name, - summary: e.summary, - example: e.payload, - }; - }) - .filter(Boolean); - - if (messageExamples.length > 0) { - return messageExamples; - } - } - - const payload = msg.payload(); - if (payload && payload.examples()) { - return payload.examples().map(example => ({ example })); - } - - return; -} - -export function getHeadersExamples(msg) { - const examples = msg.examples(); - if (Array.isArray(examples) && examples.some(e => e.headers)) { - const messageExamples = examples - .flatMap(e => { - if (!e.headers) return; - return { - name: e.name, - summary: e.summary, - example: e.headers, - }; - }) - .filter(Boolean); - - if (messageExamples.length > 0) { - return messageExamples; - } - } - - const headers = msg.headers(); - if (headers && headers.examples()) { - return headers.examples().map(example => ({ example })); - } - - return; -} diff --git a/package-lock.json b/package-lock.json index d961cd51f..d8edbcf5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,15 +21,15 @@ "dev": true }, "@asyncapi/generator": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/@asyncapi/generator/-/generator-1.7.4.tgz", - "integrity": "sha512-rGyI+gcPrFS1xLkXt/QdR5kTSwn6wPLWGkGJO1mxHyOVF6X9sCnCHKLHqQ9tzh++fi5tivi6Ybx5VM5xaRc1eg==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@asyncapi/generator/-/generator-1.8.0.tgz", + "integrity": "sha512-dFNNpev7p7JxxS8xipLzOoPdZ+Go2MuMZyJBcmLMjeYc52Lzd5AxQ8LTPEGUFZMHY0ZHCOT5c2USv5JKFNxm0A==", "dev": true, "requires": { "@asyncapi/avro-schema-parser": "^0.2.1", "@asyncapi/generator-react-sdk": "^0.2.11", "@asyncapi/openapi-schema-parser": "^2.0.1", - "@asyncapi/parser": "^1.5.2", + "@asyncapi/parser": "^1.7.0", "@asyncapi/raml-dt-schema-parser": "^2.0.1", "@npmcli/arborist": "^2.2.4", "ajv": "^6.10.2", @@ -77,9 +77,9 @@ } }, "@asyncapi/generator-filters": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@asyncapi/generator-filters/-/generator-filters-1.1.0.tgz", - "integrity": "sha512-04Z2mMi3iv1jl7RZ1U5DX+Ruet5BOHLzEMSsl0vnYx2UZCM0AIlMvS6ph5JHv2AhBTD65a4Lfnsdr8qz0ybW+g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@asyncapi/generator-filters/-/generator-filters-2.0.0.tgz", + "integrity": "sha512-KTcdPrdF2qPtiW4VCwIJmX+U0S8teeRaZ3UX1l5PIluWxc4RPNnIkQvpRMJyrdw7nJFGuX1yu1bvhCzqBoWyhA==", "requires": { "lodash": "^4.17.15", "markdown-it": "^10.0.0", @@ -131,13 +131,13 @@ } }, "@asyncapi/parser": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-1.6.0.tgz", - "integrity": "sha512-uLLoDn0Enisp7JgZV6TdK7AfbQF0dxS4j68XGjoslTew/OGfAatchpuP5ARMcxqnygYyhtEFcOd/qzKbmZy2zA==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-1.7.0.tgz", + "integrity": "sha512-ULL6k+s1zzeLLCUH2l0nsTxtCdiUdnAkMROhXD5XnEAIN+3M3tYO39w9HcbzKHngxFFhr0MsHOrGpw61rcxIsw==", "dev": true, "requires": { "@apidevtools/json-schema-ref-parser": "^9.0.6", - "@asyncapi/specs": "^2.7.8", + "@asyncapi/specs": "2.8.0", "@fmvilas/pseudo-yaml-ast": "^0.3.1", "ajv": "^6.10.1", "js-yaml": "^3.13.1", @@ -145,6 +145,14 @@ "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.6.0", "tiny-merge-patch": "^0.1.2" + }, + "dependencies": { + "@asyncapi/specs": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-2.8.0.tgz", + "integrity": "sha512-ZVyr1L0Le8Z0mvr2BPriszaDu53rZxevjqVCXt3PqJMPJuiiGMVhkslmclj474nBK0ckygSRe8jAd4smm9XOrg==", + "dev": true + } } }, "@asyncapi/raml-dt-schema-parser": { @@ -1331,9 +1339,9 @@ } }, "@npmcli/arborist": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.3.tgz", - "integrity": "sha512-R8U2dZ8+jeE7go+qNU4Mt6aiXyBu3mM75iRIugNCA4P0OWlsLOpuDPPhsaRcOVbtXheOGZXrqe36qP1g+M68KQ==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.4.tgz", + "integrity": "sha512-A/pDQ/VZpdxaqsQS5XOWrhrPuC+ER7HLq+4ZkEmnO2yo/USFCWEsiUPYKhfY+sWXK3pgKjN7B7CEFmAnSoAt3g==", "dev": true, "requires": { "@npmcli/installed-package-contents": "^1.0.7", @@ -1342,6 +1350,7 @@ "@npmcli/move-file": "^1.1.0", "@npmcli/name-from-folder": "^1.0.1", "@npmcli/node-gyp": "^1.0.1", + "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^1.8.2", "bin-links": "^2.2.1", "cacache": "^15.0.3", @@ -1437,6 +1446,15 @@ "integrity": "sha512-yrJUe6reVMpktcvagumoqD9r08fH1iRo01gn1u0zoCApa9lnZGEigVKUd2hzsCId4gdtkZZIVscLhNxMECKgRg==", "dev": true }, + "@npmcli/package-json": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-1.0.1.tgz", + "integrity": "sha512-y6jnu76E9C23osz8gEMBayZmaZ69vFOIk8vR1FJL/wbEJ54+9aVG9rLTjQKSXfgYZEr50nw1txBBFfBZZe+bYg==", + "dev": true, + "requires": { + "json-parse-even-better-errors": "^2.3.1" + } + }, "@npmcli/promise-spawn": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@npmcli/promise-spawn/-/promise-spawn-1.3.2.tgz", diff --git a/package.json b/package.json index 803420dd1..c8ec2a4dd 100644 --- a/package.json +++ b/package.json @@ -31,12 +31,12 @@ "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" }, "devDependencies": { - "@asyncapi/generator": "^1.7.4", + "@asyncapi/generator": "^1.8.0", "@semantic-release/commit-analyzer": "^8.0.1", "@semantic-release/github": "^7.0.4", "@semantic-release/npm": "^7.0.3", From 0b8d4c7ba51753ffe0a5c7f5c8652c195028b751 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Tue, 29 Jun 2021 13:53:16 +0200 Subject: [PATCH 3/4] fix bug --- components/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Message.js b/components/Message.js index 0874dc5bb..553d29ebe 100644 --- a/components/Message.js +++ b/components/Message.js @@ -56,7 +56,7 @@ function Example({ type = 'headers', message }) { {ex.name && **{ex.name}**} {ex.summary && {ex.summary}} - {JSON.stringify(ex, null, 2)} + {JSON.stringify(ex.example, null, 2)} ))} From 90e84dabb282b7e771746f00dc3a9cec670f0e2d Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Tue, 29 Jun 2021 13:59:21 +0200 Subject: [PATCH 4/4] fix duplication --- components/Message.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/components/Message.js b/components/Message.js index 553d29ebe..767a055a7 100644 --- a/components/Message.js +++ b/components/Message.js @@ -23,7 +23,7 @@ export function Message({ message, title = 'Message' }) { <>
Headers
- + )} @@ -31,7 +31,7 @@ export function Message({ message, title = 'Message' }) { <>
Payload
- + )} @@ -45,20 +45,14 @@ export function Message({ message, title = 'Message' }) { ) } -function Example({ type = 'headers', message }) { +function Examples({ type = 'headers', message }) { if (type === 'headers') { const examples = getHeadersExamples(message); if (examples) { return ( <>
Examples of headers
- {examples.map(ex => ( - - {ex.name && **{ex.name}**} - {ex.summary && {ex.summary}} - {JSON.stringify(ex.example, null, 2)} - - ))} + ); } @@ -77,13 +71,7 @@ function Example({ type = 'headers', message }) { return ( <>
Examples of payload
- {examples.map(ex => ( - - {ex.name && **{ex.name}**} - {ex.summary && {ex.summary}} - {JSON.stringify(ex.example, null, 2)} - - ))} + ); } @@ -98,3 +86,17 @@ function Example({ type = 'headers', message }) { ); } } + +function Example({ examples = [] }) { + if (examples.length === 0) { + return null; + } + + return examples.map(ex => ( + + {ex.name && **{ex.name}**} + {ex.summary && {ex.summary}} + {JSON.stringify(ex.example, null, 2)} + + )) +}