├── .all-contributorsrc ├── .asyncapi-tool ├── .eslintrc ├── .github ├── pull-request-template.md └── workflows │ ├── add-good-first-issue-labels.yml │ ├── automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml │ ├── automerge-for-humans-merging.yml │ ├── automerge-for-humans-remove-ready-to-merge-label-on-edit.yml │ ├── automerge-orphans.yml │ ├── automerge.yml │ ├── autoupdate.yml │ ├── bounty-program-commands.yml │ ├── bump.yml │ ├── help-command.yml │ ├── if-nodejs-pr-testing.yml │ ├── if-nodejs-release.yml │ ├── if-nodejs-version-bump.yml │ ├── issues-prs-notifications.yml │ ├── lint-pr-title.yml │ ├── notify-tsc-members-mention.yml │ ├── please-take-a-look-command.yml │ ├── release-announcements.yml │ ├── scripts │ ├── README.md │ └── mailchimp │ │ ├── htmlContent.js │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json │ ├── stale-issues-prs.yml │ ├── transfer-issue.yml │ ├── update-maintainers-trigger.yaml │ ├── update-pr.yml │ └── welcome-first-time-contrib.yml ├── .gitignore ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── README.md ├── filters └── all.js ├── hooks ├── post-process.js └── pre-process.js ├── lib ├── applicationModel.js ├── modelClass.js └── scsLib.js ├── package-lock.json ├── package.json ├── partials ├── all-args-constructor ├── java-class └── java-package ├── template ├── README.md ├── pom.app ├── pom.lib └── src │ └── main │ ├── java │ ├── $$everySchema$$.java │ └── Application.java │ └── resources │ └── application.yml └── test ├── __snapshots__ └── integration.test.js.snap ├── integration.test.js └── mocks ├── animals.yaml ├── avro-schema-namespace.yaml ├── avro-union-object.yaml ├── error-reporter.yaml ├── kafka-avro.yaml ├── multivariable-topic.yaml ├── nested-arrays.yaml ├── schema-with-array-of-objects.yaml ├── schemas-with-duplicate-$ids.yaml ├── scs-function-name ├── animals-same-function-name.yaml └── dynamic-topic-same-function-name.yaml ├── smarty-lighting-streetlights.yaml └── solace-test-app.yaml /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "java-spring-cloud-stream-template", 3 | "projectOwner": "asyncapi", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": false, 11 | "skipCi": true, 12 | "contributorsPerLine": 4, 13 | "contributors": [ 14 | { 15 | "login": "damaru-inc", 16 | "name": "Michael Davis", 17 | "avatar_url": "https://avatars1.githubusercontent.com/u/3926925?v=4", 18 | "profile": "http://www.damaru.com", 19 | "contributions": [ 20 | "code", 21 | "doc", 22 | "review", 23 | "question" 24 | ] 25 | }, 26 | { 27 | "login": "Mrc0113", 28 | "name": "Marc DiPasquale", 29 | "avatar_url": "https://avatars0.githubusercontent.com/u/1815312?v=4", 30 | "profile": "https://marcd.dev", 31 | "contributions": [ 32 | "doc" 33 | ] 34 | }, 35 | { 36 | "login": "fmvilas", 37 | "name": "Fran Méndez", 38 | "avatar_url": "https://avatars3.githubusercontent.com/u/242119?v=4", 39 | "profile": "http://www.fmvilas.com", 40 | "contributions": [ 41 | "code", 42 | "infra" 43 | ] 44 | }, 45 | { 46 | "login": "derberg", 47 | "name": "Lukasz Gornicki", 48 | "avatar_url": "https://avatars1.githubusercontent.com/u/6995927?v=4", 49 | "profile": "https://resume.github.io/?derberg", 50 | "contributions": [ 51 | "infra", 52 | "code" 53 | ] 54 | }, 55 | { 56 | "login": "blzsaa", 57 | "name": "blzsaa", 58 | "avatar_url": "https://avatars.githubusercontent.com/u/17824588?v=4", 59 | "profile": "https://github.com/blzsaa", 60 | "contributions": [ 61 | "code" 62 | ] 63 | } 64 | ], 65 | "commitConvention": "none" 66 | } 67 | -------------------------------------------------------------------------------- /.asyncapi-tool: -------------------------------------------------------------------------------- 1 | title: Java Spring Cloud Stream Template 2 | filters: 3 | language: 4 | - javascript 5 | technology: 6 | - Spring Cloud Streams 7 | - Maven 8 | categories: 9 | - generator-template 10 | hasCommercial: false 11 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | es6: true 4 | jest/globals: true 5 | 6 | parserOptions: 7 | ecmaVersion: 2020 8 | 9 | plugins: 10 | - jest 11 | 12 | rules: 13 | # Ignore Rules 14 | strict: 0 15 | no-underscore-dangle: 0 16 | no-mixed-requires: 0 17 | no-process-exit: 0 18 | no-warning-comments: 0 19 | curly: 0 20 | no-multi-spaces: 0 21 | no-alert: 0 22 | consistent-return: 0 23 | consistent-this: [0, self] 24 | func-style: 0 25 | max-nested-callbacks: 0 26 | 27 | # Warnings 28 | no-debugger: 1 29 | no-empty: 1 30 | no-invalid-regexp: 1 31 | no-unused-expressions: 1 32 | no-native-reassign: 1 33 | no-fallthrough: 1 34 | camelcase: 0 35 | 36 | # Errors 37 | eqeqeq: 2 38 | no-undef: 2 39 | no-dupe-keys: 2 40 | no-empty-character-class: 2 41 | no-self-compare: 2 42 | valid-typeof: 2 43 | no-unused-vars: [2, { "args": "none" }] 44 | handle-callback-err: 2 45 | no-shadow-restricted-names: 2 46 | no-new-require: 2 47 | no-mixed-spaces-and-tabs: 2 48 | block-scoped-var: 2 49 | no-else-return: 2 50 | no-throw-literal: 2 51 | no-void: 2 52 | radix: 2 53 | wrap-iife: [2, outside] 54 | no-shadow: 0 55 | no-use-before-define: [2, nofunc] 56 | no-path-concat: 2 57 | valid-jsdoc: [0, {requireReturn: false, requireParamDescription: false, requireReturnDescription: false}] 58 | 59 | # stylistic errors 60 | no-spaced-func: 2 61 | semi-spacing: 2 62 | quotes: [2, 'single'] 63 | key-spacing: [2, { beforeColon: false, afterColon: true }] 64 | indent: [2, 2] 65 | no-lonely-if: 2 66 | no-floating-decimal: 2 67 | brace-style: [2, 1tbs, { allowSingleLine: true }] 68 | comma-style: [2, last] 69 | no-multiple-empty-lines: [2, {max: 1}] 70 | no-nested-ternary: 2 71 | operator-assignment: [2, always] 72 | padded-blocks: [2, never] 73 | quote-props: [2, as-needed] 74 | keyword-spacing: [2, {'before': true, 'after': true, 'overrides': {}}] 75 | space-before-blocks: [2, always] 76 | array-bracket-spacing: [2, never] 77 | computed-property-spacing: [2, never] 78 | space-in-parens: [2, never] 79 | space-unary-ops: [2, {words: true, nonwords: false}] 80 | wrap-regex: 2 81 | linebreak-style: 0 82 | semi: [2, always] 83 | arrow-spacing: [2, {before: true, after: true}] 84 | no-class-assign: 2 85 | no-const-assign: 2 86 | no-dupe-class-members: 2 87 | no-this-before-super: 2 88 | no-var: 2 89 | object-shorthand: [2, always] 90 | prefer-arrow-callback: 2 91 | prefer-const: 2 92 | prefer-spread: 2 93 | prefer-template: 2 -------------------------------------------------------------------------------- /.github/pull-request-template.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | **Description** 8 | 9 | - ... 10 | - ... 11 | - ... 12 | 13 | **Related issue(s)** 14 | -------------------------------------------------------------------------------- /.github/workflows/add-good-first-issue-labels.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # Purpose of this workflow is to enable anyone to label issue with 'Good First Issue' and 'area/*' with a single command. 5 | name: Add 'Good First Issue' and 'area/*' labels # if proper comment added 6 | 7 | on: 8 | issue_comment: 9 | types: 10 | - created 11 | 12 | jobs: 13 | add-labels: 14 | if: ${{(!github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot') && (contains(github.event.comment.body, '/good-first-issue') || contains(github.event.comment.body, '/gfi' ))}} 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Add label 18 | uses: actions/github-script@v7 19 | with: 20 | github-token: ${{ secrets.GH_TOKEN }} 21 | script: | 22 | const areas = ['javascript', 'typescript', 'java' , 'go', 'docs', 'ci-cd', 'design']; 23 | const words = context.payload.comment.body.trim().split(" "); 24 | const areaIndex = words.findIndex((word)=> word === '/gfi' || word === '/good-first-issue') + 1 25 | let area = words[areaIndex]; 26 | switch(area){ 27 | case 'ts': 28 | area = 'typescript'; 29 | break; 30 | case 'js': 31 | area = 'javascript'; 32 | break; 33 | case 'markdown': 34 | area = 'docs'; 35 | break; 36 | } 37 | if(!areas.includes(area)){ 38 | const message = `Hey @${context.payload.sender.login}, your message doesn't follow the requirements, you can try \`/help\`.` 39 | 40 | await github.rest.issues.createComment({ 41 | issue_number: context.issue.number, 42 | owner: context.repo.owner, 43 | repo: context.repo.repo, 44 | body: message 45 | }) 46 | } else { 47 | 48 | // remove area if there is any before adding new labels. 49 | const currentLabels = (await github.rest.issues.listLabelsOnIssue({ 50 | issue_number: context.issue.number, 51 | owner: context.repo.owner, 52 | repo: context.repo.repo, 53 | })).data.map(label => label.name); 54 | 55 | const shouldBeRemoved = currentLabels.filter(label => (label.startsWith('area/') && !label.endsWith(area))); 56 | shouldBeRemoved.forEach(label => { 57 | github.rest.issues.deleteLabel({ 58 | owner: context.repo.owner, 59 | repo: context.repo.repo, 60 | name: label, 61 | }); 62 | }); 63 | 64 | // Add new labels. 65 | github.rest.issues.addLabels({ 66 | issue_number: context.issue.number, 67 | owner: context.repo.owner, 68 | repo: context.repo.repo, 69 | labels: ['good first issue', `area/${area}`] 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # Purpose of this workflow is to enable anyone to label PR with the following labels: 5 | # `ready-to-merge` and `do-not-merge` labels to get stuff merged or blocked from merging 6 | # `autoupdate` to keep a branch up-to-date with the target branch 7 | 8 | name: Label PRs # if proper comment added 9 | 10 | on: 11 | issue_comment: 12 | types: 13 | - created 14 | 15 | jobs: 16 | add-ready-to-merge-label: 17 | if: > 18 | github.event.issue.pull_request && 19 | github.event.issue.state != 'closed' && 20 | github.actor != 'asyncapi-bot' && 21 | ( 22 | contains(github.event.comment.body, '/ready-to-merge') || 23 | contains(github.event.comment.body, '/rtm' ) 24 | ) 25 | 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: Add ready-to-merge label 29 | uses: actions/github-script@v7 30 | with: 31 | github-token: ${{ secrets.GH_TOKEN }} 32 | script: | 33 | const prDetailsUrl = context.payload.issue.pull_request.url; 34 | const { data: pull } = await github.request(prDetailsUrl); 35 | const { draft: isDraft} = pull; 36 | if(!isDraft) { 37 | console.log('adding ready-to-merge label...'); 38 | github.rest.issues.addLabels({ 39 | issue_number: context.issue.number, 40 | owner: context.repo.owner, 41 | repo: context.repo.repo, 42 | labels: ['ready-to-merge'] 43 | }) 44 | } 45 | 46 | const { data: comparison } = 47 | await github.rest.repos.compareCommitsWithBasehead({ 48 | owner: pull.head.repo.owner.login, 49 | repo: pull.head.repo.name, 50 | basehead: `${pull.base.label}...${pull.head.label}`, 51 | }); 52 | if (comparison.behind_by !== 0 && pull.mergeable_state === 'behind') { 53 | console.log(`This branch is behind the target by ${comparison.behind_by} commits`) 54 | console.log('adding out-of-date comment...'); 55 | github.rest.issues.createComment({ 56 | issue_number: context.issue.number, 57 | owner: context.repo.owner, 58 | repo: context.repo.repo, 59 | body: `Hello, @${{ github.actor }}! 👋🏼 60 | This PR is not up to date with the base branch and can't be merged. 61 | Please update your branch manually with the latest version of the base branch. 62 | PRO-TIP: To request an update from the upstream branch, simply comment \`/u\` or \`/update\` and our bot will handle the update operation promptly. 63 | 64 | The only requirement for this to work is to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in your PR. Also the update will not work if your fork is located in an organization, not under your personal profile. 65 | Thanks 😄` 66 | }) 67 | } 68 | 69 | add-do-not-merge-label: 70 | if: > 71 | github.event.issue.pull_request && 72 | github.event.issue.state != 'closed' && 73 | github.actor != 'asyncapi-bot' && 74 | ( 75 | contains(github.event.comment.body, '/do-not-merge') || 76 | contains(github.event.comment.body, '/dnm' ) 77 | ) 78 | runs-on: ubuntu-latest 79 | steps: 80 | - name: Add do-not-merge label 81 | uses: actions/github-script@v7 82 | with: 83 | github-token: ${{ secrets.GH_TOKEN }} 84 | script: | 85 | github.rest.issues.addLabels({ 86 | issue_number: context.issue.number, 87 | owner: context.repo.owner, 88 | repo: context.repo.repo, 89 | labels: ['do-not-merge'] 90 | }) 91 | add-autoupdate-label: 92 | if: > 93 | github.event.issue.pull_request && 94 | github.event.issue.state != 'closed' && 95 | github.actor != 'asyncapi-bot' && 96 | ( 97 | contains(github.event.comment.body, '/autoupdate') || 98 | contains(github.event.comment.body, '/au' ) 99 | ) 100 | runs-on: ubuntu-latest 101 | steps: 102 | - name: Add autoupdate label 103 | uses: actions/github-script@v7 104 | with: 105 | github-token: ${{ secrets.GH_TOKEN }} 106 | script: | 107 | github.rest.issues.addLabels({ 108 | issue_number: context.issue.number, 109 | owner: context.repo.owner, 110 | repo: context.repo.repo, 111 | labels: ['autoupdate'] 112 | }) 113 | -------------------------------------------------------------------------------- /.github/workflows/automerge-for-humans-merging.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # Purpose of this workflow is to allow people to merge PR without a need of maintainer doing it. If all checks are in place (including maintainers approval) - JUST MERGE IT! 5 | name: Automerge For Humans 6 | 7 | on: 8 | pull_request_target: 9 | types: 10 | - labeled 11 | - unlabeled 12 | - synchronize 13 | - opened 14 | - edited 15 | - ready_for_review 16 | - reopened 17 | - unlocked 18 | 19 | jobs: 20 | automerge-for-humans: 21 | # it runs only if PR actor is not a bot, at least not a bot that we know 22 | if: | 23 | github.event.pull_request.draft == false && 24 | (github.event.pull_request.user.login != 'asyncapi-bot' || 25 | github.event.pull_request.user.login != 'dependabot[bot]' || 26 | github.event.pull_request.user.login != 'dependabot-preview[bot]') 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Get PR authors 30 | id: authors 31 | uses: actions/github-script@v7 32 | with: 33 | script: | 34 | // Get paginated list of all commits in the PR 35 | try { 36 | const commitOpts = github.rest.pulls.listCommits.endpoint.merge({ 37 | owner: context.repo.owner, 38 | repo: context.repo.repo, 39 | pull_number: context.issue.number 40 | }); 41 | 42 | const commits = await github.paginate(commitOpts); 43 | 44 | if (commits.length === 0) { 45 | core.setFailed('No commits found in the PR'); 46 | return ''; 47 | } 48 | 49 | // Get unique authors from the commits list 50 | const authors = commits.reduce((acc, commit) => { 51 | const username = commit.author?.login || commit.commit.author?.name; 52 | if (username && !acc[username]) { 53 | acc[username] = { 54 | name: commit.commit.author?.name, 55 | email: commit.commit.author?.email, 56 | } 57 | } 58 | 59 | return acc; 60 | }, {}); 61 | 62 | return authors; 63 | } catch (error) { 64 | core.setFailed(error.message); 65 | return []; 66 | } 67 | 68 | - name: Create commit message 69 | id: create-commit-message 70 | uses: actions/github-script@v7 71 | with: 72 | script: | 73 | const authors = ${{ steps.authors.outputs.result }}; 74 | 75 | if (Object.keys(authors).length === 0) { 76 | core.setFailed('No authors found in the PR'); 77 | return ''; 78 | } 79 | 80 | // Create a string of the form "Co-authored-by: Name " 81 | // ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors 82 | const coAuthors = Object.values(authors).map(author => { 83 | return `Co-authored-by: ${author.name} <${author.email}>`; 84 | }).join('\n'); 85 | 86 | core.debug(coAuthors);; 87 | 88 | return coAuthors; 89 | 90 | - name: Automerge PR 91 | uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6 92 | env: 93 | GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" 94 | MERGE_LABELS: "!do-not-merge,ready-to-merge" 95 | MERGE_METHOD: "squash" 96 | # Using the output of the previous step (`Co-authored-by: ...` lines) as commit description. 97 | # Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions 98 | MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ fromJSON(steps.create-commit-message.outputs.result) }}" 99 | MERGE_RETRIES: "20" 100 | MERGE_RETRY_SLEEP: "30000" 101 | -------------------------------------------------------------------------------- /.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # Defence from evil contributor that after adding `ready-to-merge` all suddenly makes evil commit or evil change in PR title 5 | # Label is removed once above action is detected 6 | name: Remove ready-to-merge label 7 | 8 | on: 9 | pull_request_target: 10 | types: 11 | - synchronize 12 | - edited 13 | 14 | jobs: 15 | remove-ready-label: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Remove label 19 | uses: actions/github-script@v7 20 | with: 21 | github-token: ${{ secrets.GH_TOKEN }} 22 | script: | 23 | const labelToRemove = 'ready-to-merge'; 24 | const labels = context.payload.pull_request.labels; 25 | const isLabelPresent = labels.some(label => label.name === labelToRemove) 26 | if(!isLabelPresent) return; 27 | github.rest.issues.removeLabel({ 28 | issue_number: context.issue.number, 29 | owner: context.repo.owner, 30 | repo: context.repo.repo, 31 | name: labelToRemove 32 | }) 33 | -------------------------------------------------------------------------------- /.github/workflows/automerge-orphans.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: 'Notify on failing automerge' 5 | 6 | on: 7 | schedule: 8 | - cron: "0 0 * * *" 9 | 10 | jobs: 11 | identify-orphans: 12 | if: startsWith(github.repository, 'asyncapi/') 13 | name: Find orphans and notify 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout repository 17 | uses: actions/checkout@v4 18 | - name: Get list of orphans 19 | uses: actions/github-script@v7 20 | id: orphans 21 | with: 22 | github-token: ${{ secrets.GITHUB_TOKEN }} 23 | script: | 24 | const query = `query($owner:String!, $name:String!) { 25 | repository(owner:$owner, name:$name){ 26 | pullRequests(first: 100, states: OPEN){ 27 | nodes{ 28 | title 29 | url 30 | author { 31 | resourcePath 32 | } 33 | } 34 | } 35 | } 36 | }`; 37 | const variables = { 38 | owner: context.repo.owner, 39 | name: context.repo.repo 40 | }; 41 | const { repository: { pullRequests: { nodes } } } = await github.graphql(query, variables); 42 | 43 | let orphans = nodes.filter( (pr) => pr.author.resourcePath === '/asyncapi-bot' || pr.author.resourcePath === '/apps/dependabot') 44 | 45 | if (orphans.length) { 46 | core.setOutput('found', 'true'); 47 | //Yes, this is very naive approach to assume there is just one PR causing issues, there can be a case that more PRs are affected the same day 48 | //The thing is that handling multiple PRs will increase a complexity in this PR that in my opinion we should avoid 49 | //The other PRs will be reported the next day the action runs, or person that checks first url will notice the other ones 50 | core.setOutput('url', orphans[0].url); 51 | core.setOutput('title', orphans[0].title); 52 | } 53 | - if: steps.orphans.outputs.found == 'true' 54 | name: Convert markdown to slack markdown 55 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 56 | id: issuemarkdown 57 | with: 58 | markdown: "-> [${{steps.orphans.outputs.title}}](${{steps.orphans.outputs.url}})" 59 | - if: steps.orphans.outputs.found == 'true' 60 | name: Send info about orphan to slack 61 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 62 | env: 63 | SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}} 64 | SLACK_TITLE: 🚨 Not merged PR that should be automerged 🚨 65 | SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}} 66 | MSG_MINIMAL: true -------------------------------------------------------------------------------- /.github/workflows/automerge.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo. 3 | 4 | name: Automerge PRs from bots 5 | 6 | on: 7 | pull_request_target: 8 | types: 9 | - opened 10 | - synchronize 11 | 12 | jobs: 13 | autoapprove-for-bot: 14 | name: Autoapprove PR comming from a bot 15 | if: > 16 | contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.event.pull_request.user.login) && 17 | contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.actor) && 18 | !contains(github.event.pull_request.labels.*.name, 'released') 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Autoapproving 22 | uses: hmarr/auto-approve-action@44888193675f29a83e04faf4002fa8c0b537b1e4 # v3.2.1 is used https://github.com/hmarr/auto-approve-action/releases/tag/v3.2.1 23 | with: 24 | github-token: "${{ secrets.GH_TOKEN_BOT_EVE }}" 25 | 26 | - name: Label autoapproved 27 | uses: actions/github-script@v7 28 | with: 29 | github-token: ${{ secrets.GH_TOKEN }} 30 | script: | 31 | github.rest.issues.addLabels({ 32 | issue_number: context.issue.number, 33 | owner: context.repo.owner, 34 | repo: context.repo.repo, 35 | labels: ['autoapproved', 'autoupdate'] 36 | }) 37 | 38 | automerge-for-bot: 39 | name: Automerge PR autoapproved by a bot 40 | needs: [autoapprove-for-bot] 41 | runs-on: ubuntu-latest 42 | steps: 43 | - name: Automerging 44 | uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6 45 | env: 46 | GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" 47 | GITHUB_LOGIN: asyncapi-bot 48 | MERGE_LABELS: "!do-not-merge" 49 | MERGE_METHOD: "squash" 50 | MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})" 51 | MERGE_RETRIES: "20" 52 | MERGE_RETRY_SLEEP: "30000" 53 | -------------------------------------------------------------------------------- /.github/workflows/autoupdate.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # This workflow is designed to work with: 5 | # - autoapprove and automerge workflows for dependabot and asyncapibot. 6 | # - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against 7 | 8 | # It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch. 9 | # Autoupdating to latest destination branch works only in the context of upstream repo and not forks 10 | 11 | name: autoupdate 12 | 13 | on: 14 | push: 15 | branches-ignore: 16 | - 'version-bump/**' 17 | - 'dependabot/**' 18 | - 'bot/**' 19 | - 'all-contributors/**' 20 | 21 | jobs: 22 | autoupdate-for-bot: 23 | if: startsWith(github.repository, 'asyncapi/') 24 | name: Autoupdate autoapproved PR created in the upstream 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Autoupdating 28 | uses: docker://chinthakagodawita/autoupdate-action:v1 29 | env: 30 | GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}' 31 | PR_FILTER: "labelled" 32 | PR_LABELS: "autoupdate" 33 | PR_READY_STATE: "ready_for_review" 34 | MERGE_CONFLICT_ACTION: "ignore" 35 | -------------------------------------------------------------------------------- /.github/workflows/bounty-program-commands.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed at https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repository, as they will be overwritten with 3 | # changes made to the same file in the abovementioned repository. 4 | 5 | # The purpose of this workflow is to allow Bounty Team members 6 | # (https://github.com/orgs/asyncapi/teams/bounty_team) to issue commands to the 7 | # organization's global AsyncAPI bot related to the Bounty Program, while at the 8 | # same time preventing unauthorized users from misusing them. 9 | 10 | name: Bounty Program commands 11 | 12 | on: 13 | issue_comment: 14 | types: 15 | - created 16 | 17 | env: 18 | BOUNTY_PROGRAM_LABELS_JSON: | 19 | [ 20 | {"name": "bounty", "color": "0e8a16", "description": "Participation in the Bounty Program"} 21 | ] 22 | 23 | jobs: 24 | guard-against-unauthorized-use: 25 | if: > 26 | github.actor != ('aeworxet' || 'thulieblack') && 27 | ( 28 | startsWith(github.event.comment.body, '/bounty' ) 29 | ) 30 | 31 | runs-on: ubuntu-latest 32 | 33 | steps: 34 | - name: ❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command 35 | uses: actions/github-script@v7 36 | with: 37 | github-token: ${{ secrets.GH_TOKEN }} 38 | script: | 39 | const commentText = `❌ @${{github.actor}} is not authorized to use the Bounty Program's commands. 40 | These commands can only be used by members of the [Bounty Team](https://github.com/orgs/asyncapi/teams/bounty_team).`; 41 | 42 | console.log(`❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command.`); 43 | github.rest.issues.createComment({ 44 | issue_number: context.issue.number, 45 | owner: context.repo.owner, 46 | repo: context.repo.repo, 47 | body: commentText 48 | }) 49 | 50 | add-label-bounty: 51 | if: > 52 | github.actor == ('aeworxet' || 'thulieblack') && 53 | ( 54 | startsWith(github.event.comment.body, '/bounty' ) 55 | ) 56 | 57 | runs-on: ubuntu-latest 58 | 59 | steps: 60 | - name: Add label `bounty` 61 | uses: actions/github-script@v7 62 | with: 63 | github-token: ${{ secrets.GH_TOKEN }} 64 | script: | 65 | const BOUNTY_PROGRAM_LABELS = JSON.parse(process.env.BOUNTY_PROGRAM_LABELS_JSON); 66 | let LIST_OF_LABELS_FOR_REPO = await github.rest.issues.listLabelsForRepo({ 67 | owner: context.repo.owner, 68 | repo: context.repo.repo, 69 | }); 70 | 71 | LIST_OF_LABELS_FOR_REPO = LIST_OF_LABELS_FOR_REPO.data.map(key => key.name); 72 | 73 | if (!LIST_OF_LABELS_FOR_REPO.includes(BOUNTY_PROGRAM_LABELS[0].name)) { 74 | await github.rest.issues.createLabel({ 75 | owner: context.repo.owner, 76 | repo: context.repo.repo, 77 | name: BOUNTY_PROGRAM_LABELS[0].name, 78 | color: BOUNTY_PROGRAM_LABELS[0].color, 79 | description: BOUNTY_PROGRAM_LABELS[0].description 80 | }); 81 | } 82 | 83 | console.log('Adding label `bounty`...'); 84 | github.rest.issues.addLabels({ 85 | issue_number: context.issue.number, 86 | owner: context.repo.owner, 87 | repo: context.repo.repo, 88 | labels: [BOUNTY_PROGRAM_LABELS[0].name] 89 | }) 90 | 91 | remove-label-bounty: 92 | if: > 93 | github.actor == ('aeworxet' || 'thulieblack') && 94 | ( 95 | startsWith(github.event.comment.body, '/unbounty' ) 96 | ) 97 | 98 | runs-on: ubuntu-latest 99 | 100 | steps: 101 | - name: Remove label `bounty` 102 | uses: actions/github-script@v7 103 | with: 104 | github-token: ${{ secrets.GH_TOKEN }} 105 | script: | 106 | const BOUNTY_PROGRAM_LABELS = JSON.parse(process.env.BOUNTY_PROGRAM_LABELS_JSON); 107 | let LIST_OF_LABELS_FOR_ISSUE = await github.rest.issues.listLabelsOnIssue({ 108 | owner: context.repo.owner, 109 | repo: context.repo.repo, 110 | issue_number: context.issue.number, 111 | }); 112 | 113 | LIST_OF_LABELS_FOR_ISSUE = LIST_OF_LABELS_FOR_ISSUE.data.map(key => key.name); 114 | 115 | if (LIST_OF_LABELS_FOR_ISSUE.includes(BOUNTY_PROGRAM_LABELS[0].name)) { 116 | console.log('Removing label `bounty`...'); 117 | github.rest.issues.removeLabel({ 118 | issue_number: context.issue.number, 119 | owner: context.repo.owner, 120 | repo: context.repo.repo, 121 | name: [BOUNTY_PROGRAM_LABELS[0].name] 122 | }) 123 | } 124 | -------------------------------------------------------------------------------- /.github/workflows/bump.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # Purpose of this action is to update npm package in libraries that use it. It is like dependabot for asyncapi npm modules only. 5 | # It runs in a repo after merge of release commit and searches for other packages that use released package. Every found package gets updated with lates version 6 | 7 | name: Bump package version in dependent repos - if Node project 8 | 9 | on: 10 | # It cannot run on release event as when release is created then version is not yet bumped in package.json 11 | # This means we cannot extract easily latest version and have a risk that package is not yet on npm 12 | push: 13 | branches: 14 | - master 15 | 16 | jobs: 17 | bump-in-dependent-projects: 18 | name: Bump this package in repositories that depend on it 19 | if: startsWith(github.event.commits[0].message, 'chore(release):') 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Checkout repo 23 | uses: actions/checkout@v2 24 | - name: Check if Node.js project and has package.json 25 | id: packagejson 26 | run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" 27 | - if: steps.packagejson.outputs.exists == 'true' 28 | name: Bumping latest version of this package in other repositories 29 | uses: derberg/npm-dependency-manager-for-your-github-org@v4 30 | with: 31 | github_token: ${{ secrets.GH_TOKEN }} 32 | committer_username: asyncapi-bot 33 | committer_email: info@asyncapi.io 34 | repos_to_ignore: html-template # this is temporary until react component releases 1.0, then it can be removed 35 | -------------------------------------------------------------------------------- /.github/workflows/help-command.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Create help comment 5 | 6 | on: 7 | issue_comment: 8 | types: 9 | - created 10 | 11 | jobs: 12 | create_help_comment_pr: 13 | if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/help') && github.actor != 'asyncapi-bot' }} 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Add comment to PR 17 | uses: actions/github-script@v7 18 | with: 19 | github-token: ${{ secrets.GH_TOKEN }} 20 | script: | 21 | //Yes to add comment to PR the same endpoint is use that we use to create a comment in issue 22 | //For more details http://developer.github.com/v3/issues/comments/ 23 | //Also proved by this action https://github.com/actions-ecosystem/action-create-comment/blob/main/src/main.ts 24 | github.rest.issues.createComment({ 25 | issue_number: context.issue.number, 26 | owner: context.repo.owner, 27 | repo: context.repo.repo, 28 | body: `Hello, @${{ github.actor }}! 👋🏼 29 | 30 | I'm 🧞🧞🧞 Genie 🧞🧞🧞 from the magic lamp. Looks like somebody needs a hand! 31 | 32 | At the moment the following comments are supported in pull requests: 33 | 34 | - \`/please-take-a-look\` or \`/ptal\` - This comment will add a comment to the PR asking for attention from the reviewrs who have not reviewed the PR yet. 35 | - \`/ready-to-merge\` or \`/rtm\` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added 36 | - \`/do-not-merge\` or \`/dnm\` - This comment will block automerging even if all conditions are met and ready-to-merge label is added 37 | - \`/autoupdate\` or \`/au\` - This comment will add \`autoupdate\` label to the PR and keeps your PR up-to-date to the target branch's future changes. Unless there is a merge conflict or it is a draft PR. (Currently only works for upstream branches.) 38 | - \`/update\` or \`/u\` - This comment will update the PR with the latest changes from the target branch. Unless there is a merge conflict or it is a draft PR. NOTE: this only updates the PR once, so if you need to update again, you need to call the command again.` 39 | }) 40 | 41 | create_help_comment_issue: 42 | if: ${{ !github.event.issue.pull_request && startsWith(github.event.comment.body, '/help') && github.actor != 'asyncapi-bot' }} 43 | runs-on: ubuntu-latest 44 | steps: 45 | - name: Add comment to Issue 46 | uses: actions/github-script@v7 47 | with: 48 | github-token: ${{ secrets.GH_TOKEN }} 49 | script: | 50 | github.rest.issues.createComment({ 51 | issue_number: context.issue.number, 52 | owner: context.repo.owner, 53 | repo: context.repo.repo, 54 | body: `Hello, @${{ github.actor }}! 👋🏼 55 | 56 | I'm 🧞🧞🧞 Genie 🧞🧞🧞 from the magic lamp. Looks like somebody needs a hand! 57 | 58 | At the moment the following comments are supported in issues: 59 | 60 | - \`/good-first-issue {js | ts | java | go | docs | design | ci-cd}\` or \`/gfi {js | ts | java | go | docs | design | ci-cd}\` - label an issue as a \`good first issue\`. 61 | example: \`/gfi js\` or \`/good-first-issue ci-cd\` 62 | - \`/transfer-issue {repo-name}\` or \`/ti {repo-name}\` - transfer issue from the source repository to the other repository passed by the user. example: \`/ti cli\` or \`/transfer-issue cli\`.` 63 | }) -------------------------------------------------------------------------------- /.github/workflows/if-nodejs-pr-testing.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # It does magic only if there is package.json file in the root of the project 5 | name: PR testing - if Node project 6 | 7 | on: 8 | pull_request: 9 | types: [opened, reopened, synchronize, ready_for_review] 10 | 11 | jobs: 12 | test-nodejs-pr: 13 | name: Test NodeJS PR - ${{ matrix.os }} 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | # Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner. 18 | # See: https://github.com/puppeteer/puppeteer/issues/12327 and https://github.com/asyncapi/parser-js/issues/1001 19 | os: [ubuntu-latest, macos-13, windows-latest] 20 | steps: 21 | - if: > 22 | !github.event.pull_request.draft && !( 23 | (github.actor == 'asyncapi-bot' && ( 24 | startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') || 25 | startsWith(github.event.pull_request.title, 'chore(release):') 26 | )) || 27 | (github.actor == 'asyncapi-bot-eve' && ( 28 | startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') || 29 | startsWith(github.event.pull_request.title, 'chore(release):') 30 | )) || 31 | (github.actor == 'allcontributors[bot]' && 32 | startsWith(github.event.pull_request.title, 'docs: add') 33 | ) 34 | ) 35 | id: should_run 36 | name: Should Run 37 | run: echo "shouldrun=true" >> $GITHUB_OUTPUT 38 | shell: bash 39 | - if: steps.should_run.outputs.shouldrun == 'true' 40 | name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows 41 | run: | 42 | git config --global core.autocrlf false 43 | git config --global core.eol lf 44 | shell: bash 45 | - if: steps.should_run.outputs.shouldrun == 'true' 46 | name: Checkout repository 47 | uses: actions/checkout@v4 48 | - if: steps.should_run.outputs.shouldrun == 'true' 49 | name: Check if Node.js project and has package.json 50 | id: packagejson 51 | run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT 52 | shell: bash 53 | - if: steps.packagejson.outputs.exists == 'true' 54 | name: Check package-lock version 55 | uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master 56 | id: lockversion 57 | - if: steps.packagejson.outputs.exists == 'true' 58 | name: Setup Node.js 59 | uses: actions/setup-node@v4 60 | with: 61 | node-version: "${{ steps.lockversion.outputs.version }}" 62 | - if: steps.lockversion.outputs.version == '18' && matrix.os == 'windows-latest' 63 | #npm cli 10 is buggy because of some cache issue 64 | name: Install npm cli 8 65 | shell: bash 66 | run: npm install -g npm@8.19.4 67 | - if: steps.packagejson.outputs.exists == 'true' 68 | name: Install dependencies 69 | shell: bash 70 | run: npm ci 71 | - if: steps.packagejson.outputs.exists == 'true' 72 | name: Test 73 | run: npm test --if-present 74 | - if: steps.packagejson.outputs.exists == 'true' && matrix.os == 'ubuntu-latest' 75 | #linting should run just one and not on all possible operating systems 76 | name: Run linter 77 | run: npm run lint --if-present 78 | - if: steps.packagejson.outputs.exists == 'true' 79 | name: Run release assets generation to make sure PR does not break it 80 | shell: bash 81 | run: npm run generate:assets --if-present 82 | -------------------------------------------------------------------------------- /.github/workflows/if-nodejs-release.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # It does magic only if there is package.json file in the root of the project 5 | name: Release - if Node project 6 | 7 | on: 8 | push: 9 | branches: 10 | - master 11 | # below lines are not enough to have release supported for these branches 12 | # make sure configuration of `semantic-release` package mentions these branches 13 | - next-spec 14 | - next-major 15 | - next-major-spec 16 | - beta 17 | - alpha 18 | 19 | jobs: 20 | 21 | test-nodejs: 22 | # We just check the message of first commit as there is always just one commit because we squash into one before merging 23 | # "commits" contains array of objects where one of the properties is commit "message" 24 | # Release workflow will be skipped if release conventional commits are not used 25 | if: | 26 | startsWith( github.repository, 'asyncapi/' ) && 27 | (startsWith( github.event.commits[0].message , 'fix:' ) || 28 | startsWith( github.event.commits[0].message, 'fix!:' ) || 29 | startsWith( github.event.commits[0].message, 'feat:' ) || 30 | startsWith( github.event.commits[0].message, 'feat!:' )) 31 | name: Test NodeJS release on ${{ matrix.os }} 32 | runs-on: ${{ matrix.os }} 33 | strategy: 34 | matrix: 35 | os: [ubuntu-latest, macos-latest, windows-latest] 36 | steps: 37 | - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows 38 | run: | 39 | git config --global core.autocrlf false 40 | git config --global core.eol lf 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | - name: Check if Node.js project and has package.json 44 | id: packagejson 45 | run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" 46 | shell: bash 47 | - if: steps.packagejson.outputs.exists == 'true' 48 | name: Setup Node.js 49 | uses: actions/setup-node@v2 50 | with: 51 | node-version: 14 52 | cache: 'npm' 53 | cache-dependency-path: '**/package-lock.json' 54 | - if: steps.packagejson.outputs.exists == 'true' 55 | name: Install dependencies 56 | run: npm install 57 | - if: steps.packagejson.outputs.exists == 'true' 58 | name: Run test 59 | run: npm test 60 | - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel 61 | name: Report workflow run status to Slack 62 | uses: 8398a7/action-slack@v3 63 | with: 64 | status: ${{ job.status }} 65 | fields: repo,action,workflow 66 | text: 'Release workflow failed in testing job' 67 | env: 68 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} 69 | 70 | release: 71 | needs: [test-nodejs] 72 | name: Publish to any of NPM, Github, and Docker Hub 73 | runs-on: ubuntu-latest 74 | steps: 75 | - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows 76 | run: | 77 | git config --global core.autocrlf false 78 | git config --global core.eol lf 79 | - name: Checkout repository 80 | uses: actions/checkout@v2 81 | - name: Check if Node.js project and has package.json 82 | id: packagejson 83 | run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" 84 | - if: steps.packagejson.outputs.exists == 'true' 85 | name: Setup Node.js 86 | uses: actions/setup-node@v1 87 | with: 88 | node-version: 14 89 | - if: steps.packagejson.outputs.exists == 'true' 90 | name: Install dependencies 91 | run: npm install 92 | - if: steps.packagejson.outputs.exists == 'true' 93 | name: Publish to any of NPM, Github, and Docker Hub 94 | id: release 95 | env: 96 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 97 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 98 | DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} 99 | DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} 100 | GIT_AUTHOR_NAME: asyncapi-bot 101 | GIT_AUTHOR_EMAIL: info@asyncapi.io 102 | GIT_COMMITTER_NAME: asyncapi-bot 103 | GIT_COMMITTER_EMAIL: info@asyncapi.io 104 | run: npm run release 105 | - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel 106 | name: Report workflow run status to Slack 107 | uses: 8398a7/action-slack@v3 108 | with: 109 | status: ${{ job.status }} 110 | fields: repo,action,workflow 111 | text: 'Release workflow failed in release job' 112 | env: 113 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} -------------------------------------------------------------------------------- /.github/workflows/if-nodejs-version-bump.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # It does magic only if there is package.json file in the root of the project 5 | name: Version bump - if Node.js project 6 | 7 | on: 8 | release: 9 | types: 10 | - published 11 | 12 | jobs: 13 | version_bump: 14 | name: Generate assets and bump NodeJS 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout repository 18 | uses: actions/checkout@v2 19 | with: 20 | # target branch of release. More info https://docs.github.com/en/rest/reference/repos#releases 21 | # in case release is created from release branch then we need to checkout from given branch 22 | # if @semantic-release/github is used to publish, the minimum version is 7.2.0 for proper working 23 | ref: ${{ github.event.release.target_commitish }} 24 | - name: Check if Node.js project and has package.json 25 | id: packagejson 26 | run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" 27 | - if: steps.packagejson.outputs.exists == 'true' 28 | name: Install dependencies 29 | run: npm install 30 | - if: steps.packagejson.outputs.exists == 'true' 31 | name: Assets generation 32 | run: npm run generate:assets 33 | - if: steps.packagejson.outputs.exists == 'true' 34 | name: Bump version in package.json 35 | # There is no need to substract "v" from the tag as version script handles it 36 | # When adding "bump:version" script in package.json, make sure no tags are added by default (--no-git-tag-version) as they are already added by release workflow 37 | # When adding "bump:version" script in package.json, make sure --allow-same-version is set in case someone forgot and updated package.json manually and we want to avoide this action to fail and raise confusion 38 | run: VERSION=${{github.event.release.tag_name}} npm run bump:version 39 | - if: steps.packagejson.outputs.exists == 'true' 40 | name: Create Pull Request with updated asset files including package.json 41 | uses: peter-evans/create-pull-request@v3 42 | with: 43 | token: ${{ secrets.GH_TOKEN }} 44 | commit-message: 'chore(release): ${{github.event.release.tag_name}}' 45 | committer: asyncapi-bot 46 | author: asyncapi-bot 47 | title: 'chore(release): ${{github.event.release.tag_name}}' 48 | body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})' 49 | branch: version-bump/${{github.event.release.tag_name}} -------------------------------------------------------------------------------- /.github/workflows/issues-prs-notifications.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # This action notifies community on slack whenever there is a new issue, PR or discussion started in given repository 5 | name: Notify slack 6 | 7 | on: 8 | issues: 9 | types: [opened, reopened] 10 | 11 | pull_request_target: 12 | types: [opened, reopened, ready_for_review] 13 | 14 | discussion: 15 | types: [created] 16 | 17 | jobs: 18 | issue: 19 | if: github.event_name == 'issues' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' 20 | name: Notify slack on every new issue 21 | runs-on: ubuntu-latest 22 | steps: 23 | - name: Convert markdown to slack markdown for issue 24 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 25 | id: issuemarkdown 26 | with: 27 | markdown: "[${{github.event.issue.title}}](${{github.event.issue.html_url}}) \n ${{github.event.issue.body}}" 28 | - name: Send info about issue 29 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 30 | env: 31 | SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}} 32 | SLACK_TITLE: 🐛 New Issue in ${{github.repository}} 🐛 33 | SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}} 34 | MSG_MINIMAL: true 35 | 36 | pull_request: 37 | if: github.event_name == 'pull_request_target' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' 38 | name: Notify slack on every new pull request 39 | runs-on: ubuntu-latest 40 | steps: 41 | - name: Convert markdown to slack markdown for pull request 42 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 43 | id: prmarkdown 44 | with: 45 | markdown: "[${{github.event.pull_request.title}}](${{github.event.pull_request.html_url}}) \n ${{github.event.pull_request.body}}" 46 | - name: Send info about pull request 47 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 48 | env: 49 | SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}} 50 | SLACK_TITLE: 💪 New Pull Request in ${{github.repository}} 💪 51 | SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}} 52 | MSG_MINIMAL: true 53 | 54 | discussion: 55 | if: github.event_name == 'discussion' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' 56 | name: Notify slack on every new pull request 57 | runs-on: ubuntu-latest 58 | steps: 59 | - name: Convert markdown to slack markdown for pull request 60 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 61 | id: discussionmarkdown 62 | with: 63 | markdown: "[${{github.event.discussion.title}}](${{github.event.discussion.html_url}}) \n ${{github.event.discussion.body}}" 64 | - name: Send info about pull request 65 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 66 | env: 67 | SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}} 68 | SLACK_TITLE: 💬 New Discussion in ${{github.repository}} 💬 69 | SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}} 70 | MSG_MINIMAL: true 71 | -------------------------------------------------------------------------------- /.github/workflows/lint-pr-title.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Lint PR title 5 | 6 | on: 7 | pull_request_target: 8 | types: [opened, reopened, synchronize, edited, ready_for_review] 9 | 10 | jobs: 11 | lint-pr-title: 12 | name: Lint PR title 13 | runs-on: ubuntu-latest 14 | steps: 15 | # Since this workflow is REQUIRED for a PR to be mergable, we have to have this 'if' statement in step level instead of job level. 16 | - if: ${{ !contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]", "allcontributors[bot]"]'), github.actor) }} 17 | uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54 #version 5.2.0 https://github.com/amannn/action-semantic-pull-request/releases/tag/v5.2.0 18 | id: lint_pr_title 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} 21 | with: 22 | subjectPattern: ^(?![A-Z]).+$ 23 | subjectPatternError: | 24 | The subject "{subject}" found in the pull request title "{title}" should start with a lowercase character. 25 | 26 | # Comments the error message from the above lint_pr_title action 27 | - if: ${{ always() && steps.lint_pr_title.outputs.error_message != null && !contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]", "allcontributors[bot]"]'), github.actor)}} 28 | name: Comment on PR 29 | uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd #use 2.5.0 https://github.com/marocchino/sticky-pull-request-comment/releases/tag/v2.5.0 30 | with: 31 | header: pr-title-lint-error 32 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} 33 | message: | 34 | 35 | We require all PRs to follow [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). 36 | More details 👇🏼 37 | ``` 38 | ${{ steps.lint_pr_title.outputs.error_message}} 39 | ``` 40 | # deletes the error comment if the title is correct 41 | - if: ${{ steps.lint_pr_title.outputs.error_message == null }} 42 | name: delete the comment 43 | uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd #use 2.5.0 https://github.com/marocchino/sticky-pull-request-comment/releases/tag/v2.5.0 44 | with: 45 | header: pr-title-lint-error 46 | delete: true 47 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} 48 | -------------------------------------------------------------------------------- /.github/workflows/notify-tsc-members-mention.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # This action notifies community on slack whenever there is a new issue, PR or discussion started in given repository 5 | name: Notify slack and email subscribers whenever TSC members are mentioned in GitHub 6 | 7 | on: 8 | issue_comment: 9 | types: 10 | - created 11 | 12 | discussion_comment: 13 | types: 14 | - created 15 | 16 | issues: 17 | types: 18 | - opened 19 | 20 | pull_request_target: 21 | types: 22 | - opened 23 | 24 | discussion: 25 | types: 26 | - created 27 | 28 | jobs: 29 | issue: 30 | if: github.event_name == 'issues' && contains(github.event.issue.body, '@asyncapi/tsc_members') 31 | name: TSC notification on every new issue 32 | runs-on: ubuntu-latest 33 | steps: 34 | - name: Checkout repository 35 | uses: actions/checkout@v4 36 | - name: Setup Node.js 37 | uses: actions/setup-node@v4 38 | with: 39 | node-version: 16 40 | cache: 'npm' 41 | cache-dependency-path: '**/package-lock.json' 42 | ######### 43 | # Handling Slack notifications 44 | ######### 45 | - name: Convert markdown to slack markdown 46 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 47 | id: issuemarkdown 48 | with: 49 | markdown: "[${{github.event.issue.title}}](${{github.event.issue.html_url}}) \n ${{github.event.issue.body}}" 50 | - name: Send info about issue 51 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 52 | env: 53 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 54 | SLACK_TITLE: 🆘 New issue that requires TSC Members attention 🆘 55 | SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}} 56 | MSG_MINIMAL: true 57 | ######### 58 | # Handling Mailchimp notifications 59 | ######### 60 | - name: Install deps 61 | run: npm install 62 | working-directory: ./.github/workflows/scripts/mailchimp 63 | - name: Send email with MailChimp 64 | uses: actions/github-script@v7 65 | env: 66 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 67 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 68 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 69 | with: 70 | script: | 71 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 72 | sendEmail('${{github.event.issue.html_url}}', '${{github.event.issue.title}}'); 73 | 74 | pull_request: 75 | if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.body, '@asyncapi/tsc_members') 76 | name: TSC notification on every new pull request 77 | runs-on: ubuntu-latest 78 | steps: 79 | - name: Checkout repository 80 | uses: actions/checkout@v4 81 | - name: Setup Node.js 82 | uses: actions/setup-node@v4 83 | with: 84 | node-version: 16 85 | cache: 'npm' 86 | cache-dependency-path: '**/package-lock.json' 87 | ######### 88 | # Handling Slack notifications 89 | ######### 90 | - name: Convert markdown to slack markdown 91 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 92 | id: prmarkdown 93 | with: 94 | markdown: "[${{github.event.pull_request.title}}](${{github.event.pull_request.html_url}}) \n ${{github.event.pull_request.body}}" 95 | - name: Send info about pull request 96 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 97 | env: 98 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 99 | SLACK_TITLE: 🆘 New PR that requires TSC Members attention 🆘 100 | SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}} 101 | MSG_MINIMAL: true 102 | ######### 103 | # Handling Mailchimp notifications 104 | ######### 105 | - name: Install deps 106 | run: npm install 107 | working-directory: ./.github/workflows/scripts/mailchimp 108 | - name: Send email with MailChimp 109 | uses: actions/github-script@v7 110 | env: 111 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 112 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 113 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 114 | with: 115 | script: | 116 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 117 | sendEmail('${{github.event.pull_request.html_url}}', '${{github.event.pull_request.title}}'); 118 | 119 | discussion: 120 | if: github.event_name == 'discussion' && contains(github.event.discussion.body, '@asyncapi/tsc_members') 121 | name: TSC notification on every new discussion 122 | runs-on: ubuntu-latest 123 | steps: 124 | - name: Checkout repository 125 | uses: actions/checkout@v4 126 | - name: Setup Node.js 127 | uses: actions/setup-node@v4 128 | with: 129 | node-version: 16 130 | cache: 'npm' 131 | cache-dependency-path: '**/package-lock.json' 132 | ######### 133 | # Handling Slack notifications 134 | ######### 135 | - name: Convert markdown to slack markdown 136 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 137 | id: discussionmarkdown 138 | with: 139 | markdown: "[${{github.event.discussion.title}}](${{github.event.discussion.html_url}}) \n ${{github.event.discussion.body}}" 140 | - name: Send info about pull request 141 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 142 | env: 143 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 144 | SLACK_TITLE: 🆘 New discussion that requires TSC Members attention 🆘 145 | SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}} 146 | MSG_MINIMAL: true 147 | ######### 148 | # Handling Mailchimp notifications 149 | ######### 150 | - name: Install deps 151 | run: npm install 152 | working-directory: ./.github/workflows/scripts/mailchimp 153 | - name: Send email with MailChimp 154 | uses: actions/github-script@v7 155 | env: 156 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 157 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 158 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 159 | with: 160 | script: | 161 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 162 | sendEmail('${{github.event.discussion.html_url}}', '${{github.event.discussion.title}}'); 163 | 164 | issue_comment: 165 | if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && contains(github.event.comment.body, '@asyncapi/tsc_members') }} 166 | name: TSC notification on every new comment in issue 167 | runs-on: ubuntu-latest 168 | steps: 169 | - name: Checkout repository 170 | uses: actions/checkout@v4 171 | - name: Setup Node.js 172 | uses: actions/setup-node@v4 173 | with: 174 | node-version: 16 175 | cache: 'npm' 176 | cache-dependency-path: '**/package-lock.json' 177 | ######### 178 | # Handling Slack notifications 179 | ######### 180 | - name: Convert markdown to slack markdown 181 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 182 | id: issuemarkdown 183 | with: 184 | markdown: "[${{github.event.issue.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}" 185 | - name: Send info about issue comment 186 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 187 | env: 188 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 189 | SLACK_TITLE: 🆘 New comment under existing issue that requires TSC Members attention 🆘 190 | SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}} 191 | MSG_MINIMAL: true 192 | ######### 193 | # Handling Mailchimp notifications 194 | ######### 195 | - name: Install deps 196 | run: npm install 197 | working-directory: ./.github/workflows/scripts/mailchimp 198 | - name: Send email with MailChimp 199 | uses: actions/github-script@v7 200 | env: 201 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 202 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 203 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 204 | with: 205 | script: | 206 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 207 | sendEmail('${{github.event.comment.html_url}}', '${{github.event.issue.title}}'); 208 | 209 | pr_comment: 210 | if: github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@asyncapi/tsc_members') 211 | name: TSC notification on every new comment in pr 212 | runs-on: ubuntu-latest 213 | steps: 214 | - name: Checkout repository 215 | uses: actions/checkout@v4 216 | - name: Setup Node.js 217 | uses: actions/setup-node@v4 218 | with: 219 | node-version: 16 220 | cache: 'npm' 221 | cache-dependency-path: '**/package-lock.json' 222 | ######### 223 | # Handling Slack notifications 224 | ######### 225 | - name: Convert markdown to slack markdown 226 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 227 | id: prmarkdown 228 | with: 229 | markdown: "[${{github.event.issue.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}" 230 | - name: Send info about PR comment 231 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 232 | env: 233 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 234 | SLACK_TITLE: 🆘 New comment under existing PR that requires TSC Members attention 🆘 235 | SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}} 236 | MSG_MINIMAL: true 237 | ######### 238 | # Handling Mailchimp notifications 239 | ######### 240 | - name: Install deps 241 | run: npm install 242 | working-directory: ./.github/workflows/scripts/mailchimp 243 | - name: Send email with MailChimp 244 | uses: actions/github-script@v7 245 | env: 246 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 247 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 248 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 249 | with: 250 | script: | 251 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 252 | sendEmail('${{github.event.comment.html_url}}', '${{github.event.issue.title}}'); 253 | 254 | discussion_comment: 255 | if: github.event_name == 'discussion_comment' && contains(github.event.comment.body, '@asyncapi/tsc_members') 256 | name: TSC notification on every new comment in discussion 257 | runs-on: ubuntu-latest 258 | steps: 259 | - name: Checkout repository 260 | uses: actions/checkout@v4 261 | - name: Setup Node.js 262 | uses: actions/setup-node@v4 263 | with: 264 | node-version: 16 265 | cache: 'npm' 266 | cache-dependency-path: '**/package-lock.json' 267 | ######### 268 | # Handling Slack notifications 269 | ######### 270 | - name: Convert markdown to slack markdown 271 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 272 | id: discussionmarkdown 273 | with: 274 | markdown: "[${{github.event.discussion.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}" 275 | - name: Send info about discussion comment 276 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 277 | env: 278 | SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}} 279 | SLACK_TITLE: 🆘 New comment under existing discussion that requires TSC Members attention 🆘 280 | SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}} 281 | MSG_MINIMAL: true 282 | ######### 283 | # Handling Mailchimp notifications 284 | ######### 285 | - name: Install deps 286 | run: npm install 287 | working-directory: ./.github/workflows/scripts/mailchimp 288 | - name: Send email with MailChimp 289 | uses: actions/github-script@v7 290 | env: 291 | CALENDAR_ID: ${{ secrets.CALENDAR_ID }} 292 | CALENDAR_SERVICE_ACCOUNT: ${{ secrets.CALENDAR_SERVICE_ACCOUNT }} 293 | MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} 294 | with: 295 | script: | 296 | const sendEmail = require('./.github/workflows/scripts/mailchimp/index.js'); 297 | sendEmail('${{github.event.comment.html_url}}', '${{github.event.discussion.title}}'); 298 | -------------------------------------------------------------------------------- /.github/workflows/please-take-a-look-command.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # It uses Github actions to listen for comments on issues and pull requests and 5 | # if the comment contains /please-take-a-look or /ptal it will add a comment pinging 6 | # the code-owners who are reviewers for PR 7 | 8 | name: Please take a Look 9 | 10 | on: 11 | issue_comment: 12 | types: [created] 13 | 14 | jobs: 15 | ping-for-attention: 16 | if: > 17 | github.event.issue.pull_request && 18 | github.event.issue.state != 'closed' && 19 | github.actor != 'asyncapi-bot' && 20 | ( 21 | contains(github.event.comment.body, '/please-take-a-look') || 22 | contains(github.event.comment.body, '/ptal') || 23 | contains(github.event.comment.body, '/PTAL') 24 | ) 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Check for Please Take a Look Command 28 | uses: actions/github-script@v7 29 | with: 30 | github-token: ${{ secrets.GH_TOKEN }} 31 | script: | 32 | const prDetailsUrl = context.payload.issue.pull_request.url; 33 | const { data: pull } = await github.request(prDetailsUrl); 34 | const reviewers = pull.requested_reviewers.map(reviewer => reviewer.login); 35 | 36 | const { data: reviews } = await github.rest.pulls.listReviews({ 37 | owner: context.repo.owner, 38 | repo: context.repo.repo, 39 | pull_number: context.issue.number 40 | }); 41 | 42 | const reviewersWhoHaveReviewed = reviews.map(review => review.user.login); 43 | 44 | const reviewersWhoHaveNotReviewed = reviewers.filter(reviewer => !reviewersWhoHaveReviewed.includes(reviewer)); 45 | 46 | if (reviewersWhoHaveNotReviewed.length > 0) { 47 | const comment = reviewersWhoHaveNotReviewed.filter(reviewer => reviewer !== 'asyncapi-bot-eve' ).map(reviewer => `@${reviewer}`).join(' '); 48 | await github.rest.issues.createComment({ 49 | issue_number: context.issue.number, 50 | owner: context.repo.owner, 51 | repo: context.repo.repo, 52 | body: `${comment} Please take a look at this PR. Thanks! :wave:` 53 | }); 54 | } 55 | -------------------------------------------------------------------------------- /.github/workflows/release-announcements.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: 'Announce releases in different channels' 5 | 6 | on: 7 | release: 8 | types: 9 | - published 10 | 11 | jobs: 12 | 13 | slack-announce: 14 | name: Slack - notify on every release 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout repository 18 | uses: actions/checkout@v4 19 | - name: Convert markdown to slack markdown for issue 20 | uses: asyncapi/.github/.github/actions/slackify-markdown@master 21 | id: markdown 22 | with: 23 | markdown: "[${{github.event.release.tag_name}}](${{github.event.release.html_url}}) \n ${{ github.event.release.body }}" 24 | - name: Send info about release to Slack 25 | uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # Using v2.3.2 26 | env: 27 | SLACK_WEBHOOK: ${{ secrets.SLACK_RELEASES }} 28 | SLACK_TITLE: Release ${{github.event.release.tag_name}} for ${{github.repository}} is out in the wild 😱💪🍾🎂 29 | SLACK_MESSAGE: ${{steps.markdown.outputs.text}} 30 | MSG_MINIMAL: true 31 | 32 | twitter-announce: 33 | name: Twitter - notify on minor and major releases 34 | runs-on: ubuntu-latest 35 | steps: 36 | - name: Checkout repo 37 | uses: actions/checkout@v4 38 | - name: Get version of last and previous release 39 | uses: actions/github-script@v7 40 | id: versions 41 | with: 42 | github-token: ${{ secrets.GITHUB_TOKEN }} 43 | script: | 44 | const query = `query($owner:String!, $name:String!) { 45 | repository(owner:$owner, name:$name){ 46 | releases(first: 2, orderBy: {field: CREATED_AT, direction: DESC}) { 47 | nodes { 48 | name 49 | } 50 | } 51 | } 52 | }`; 53 | const variables = { 54 | owner: context.repo.owner, 55 | name: context.repo.repo 56 | }; 57 | const { repository: { releases: { nodes } } } = await github.graphql(query, variables); 58 | core.setOutput('lastver', nodes[0].name); 59 | // In case of first release in the package, there is no such thing as previous error, so we set info about previous version only once we have it 60 | // We should tweet about the release no matter of the type as it is initial release 61 | if (nodes.length != 1) core.setOutput('previousver', nodes[1].name); 62 | - name: Identify release type 63 | id: releasetype 64 | # if previousver is not provided then this steps just logs information about missing version, no errors 65 | run: echo "type=$(npx -q -p semver-diff-cli semver-diff ${{steps.versions.outputs.previousver}} ${{steps.versions.outputs.lastver}})" >> $GITHUB_OUTPUT 66 | - name: Get name of the person that is behind the newly released version 67 | id: author 68 | run: echo "name=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT 69 | - name: Publish information about the release to Twitter # tweet only if detected version change is not a patch 70 | # tweet goes out even if the type is not major or minor but "You need provide version number to compare." 71 | # it is ok, it just means we did not identify previous version as we are tweeting out information about the release for the first time 72 | if: steps.releasetype.outputs.type != 'null' && steps.releasetype.outputs.type != 'patch' # null means that versions are the same 73 | uses: m1ner79/Github-Twittction@d1e508b6c2170145127138f93c49b7c46c6ff3a7 # using 2.0.0 https://github.com/m1ner79/Github-Twittction/releases/tag/v2.0.0 74 | with: 75 | twitter_status: "Release ${{github.event.release.tag_name}} for ${{github.repository}} is out in the wild 😱💪🍾🎂\n\nThank you for the contribution ${{ steps.author.outputs.name }} ${{github.event.release.html_url}}" 76 | twitter_consumer_key: ${{ secrets.TWITTER_CONSUMER_KEY }} 77 | twitter_consumer_secret: ${{ secrets.TWITTER_CONSUMER_SECRET }} 78 | twitter_access_token_key: ${{ secrets.TWITTER_ACCESS_TOKEN_KEY }} 79 | twitter_access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} -------------------------------------------------------------------------------- /.github/workflows/scripts/README.md: -------------------------------------------------------------------------------- 1 | The entire `scripts` directory is centrally managed in [.github](https://github.com/asyncapi/.github/) repository. Any changes in this folder should be done in central repository. -------------------------------------------------------------------------------- /.github/workflows/scripts/mailchimp/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This code is centrally managed in https://github.com/asyncapi/.github/ 3 | * Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 4 | */ 5 | const mailchimp = require('@mailchimp/mailchimp_marketing'); 6 | const core = require('@actions/core'); 7 | const htmlContent = require('./htmlContent.js'); 8 | 9 | /** 10 | * Sending API request to mailchimp to schedule email to subscribers 11 | * Input is the URL to issue/discussion or other resource 12 | */ 13 | module.exports = async (link, title) => { 14 | 15 | let newCampaign; 16 | 17 | mailchimp.setConfig({ 18 | apiKey: process.env.MAILCHIMP_API_KEY, 19 | server: 'us12' 20 | }); 21 | 22 | /* 23 | * First we create campaign 24 | */ 25 | try { 26 | newCampaign = await mailchimp.campaigns.create({ 27 | type: 'regular', 28 | recipients: { 29 | list_id: '6e3e437abe', 30 | segment_opts: { 31 | match: 'any', 32 | conditions: [{ 33 | condition_type: 'Interests', 34 | field: 'interests-2801e38b9f', 35 | op: 'interestcontains', 36 | value: ['f7204f9b90'] 37 | }] 38 | } 39 | }, 40 | settings: { 41 | subject_line: `TSC attention required: ${ title }`, 42 | preview_text: 'Check out the latest topic that TSC members have to be aware of', 43 | title: `New topic info - ${ new Date(Date.now()).toUTCString()}`, 44 | from_name: 'AsyncAPI Initiative', 45 | reply_to: 'info@asyncapi.io', 46 | } 47 | }); 48 | } catch (error) { 49 | return core.setFailed(`Failed creating campaign: ${ JSON.stringify(error) }`); 50 | } 51 | 52 | /* 53 | * Content of the email is added separately after campaign creation 54 | */ 55 | try { 56 | await mailchimp.campaigns.setContent(newCampaign.id, { html: htmlContent(link, title) }); 57 | } catch (error) { 58 | return core.setFailed(`Failed adding content to campaign: ${ JSON.stringify(error) }`); 59 | } 60 | 61 | /* 62 | * We schedule an email to send it immediately 63 | */ 64 | try { 65 | //schedule for next hour 66 | //so if this code was created by new issue creation at 9:46, the email is scheduled for 10:00 67 | //is it like this as schedule has limitiations and you cannot schedule email for 9:48 68 | const scheduleDate = new Date(Date.parse(new Date(Date.now()).toISOString()) + 1 * 1 * 60 * 60 * 1000); 69 | scheduleDate.setUTCMinutes(00); 70 | 71 | await mailchimp.campaigns.schedule(newCampaign.id, { 72 | schedule_time: scheduleDate.toISOString(), 73 | }); 74 | } catch (error) { 75 | return core.setFailed(`Failed scheduling email: ${ JSON.stringify(error) }`); 76 | } 77 | 78 | core.info(`New email campaign created`); 79 | } -------------------------------------------------------------------------------- /.github/workflows/scripts/mailchimp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "schedule-email", 3 | "description": "This code is responsible for scheduling an email campaign. This file is centrally managed in https://github.com/asyncapi/.github/", 4 | "license": "Apache 2.0", 5 | "dependencies": { 6 | "@actions/core": "1.6.0", 7 | "@mailchimp/mailchimp_marketing": "3.0.74" 8 | } 9 | } -------------------------------------------------------------------------------- /.github/workflows/stale-issues-prs.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Manage stale issues and PRs 5 | 6 | on: 7 | schedule: 8 | - cron: "0 0 * * *" 9 | 10 | jobs: 11 | stale: 12 | if: startsWith(github.repository, 'asyncapi/') 13 | name: Mark issue or PR as stale 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 #v9.1.0 but pointing to commit for security reasons 17 | with: 18 | repo-token: ${{ secrets.GITHUB_TOKEN }} 19 | stale-issue-message: | 20 | This issue has been automatically marked as stale because it has not had recent activity :sleeping: 21 | 22 | It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation. 23 | 24 | There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under [open governance model](https://github.com/asyncapi/community/blob/master/CHARTER.md). 25 | 26 | Let us figure out together how to push this issue forward. Connect with us through [one of many communication channels](https://github.com/asyncapi/community/issues/1) we established here. 27 | 28 | Thank you for your patience :heart: 29 | stale-pr-message: | 30 | This pull request has been automatically marked as stale because it has not had recent activity :sleeping: 31 | 32 | It will be closed in 120 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation. 33 | 34 | There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under [open governance model](https://github.com/asyncapi/community/blob/master/CHARTER.md). 35 | 36 | Let us figure out together how to push this pull request forward. Connect with us through [one of many communication channels](https://github.com/asyncapi/community/issues/1) we established here. 37 | 38 | Thank you for your patience :heart: 39 | days-before-stale: 120 40 | days-before-close: 120 41 | stale-issue-label: stale 42 | stale-pr-label: stale 43 | exempt-issue-labels: keep-open 44 | exempt-pr-labels: keep-open 45 | close-issue-reason: not_planned 46 | -------------------------------------------------------------------------------- /.github/workflows/transfer-issue.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Transfer Issues between repositories 5 | 6 | on: 7 | issue_comment: 8 | types: 9 | - created 10 | 11 | permissions: 12 | issues: write 13 | 14 | jobs: 15 | transfer: 16 | if: ${{(!github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot') && (startsWith(github.event.comment.body, '/transfer-issue') || startsWith(github.event.comment.body, '/ti'))}} 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout Repository 20 | uses: actions/checkout@v4 21 | - name: Extract Input 22 | id: extract_step 23 | env: 24 | COMMENT: "${{ github.event.comment.body }}" 25 | run: | 26 | REPO=$(echo $COMMENT | awk '{print $2}') 27 | echo repo=$REPO >> $GITHUB_OUTPUT 28 | - name: Check Repo 29 | uses: actions/github-script@v7 30 | with: 31 | github-token: ${{secrets.GH_TOKEN}} 32 | script: | 33 | const r = "${{github.repository}}" 34 | const [owner, repo] = r.split('/') 35 | const repoToMove = process.env.REPO_TO_MOVE 36 | const issue_number = context.issue.number 37 | try { 38 | const {data} = await github.rest.repos.get({ 39 | owner, 40 | repo: repoToMove 41 | }) 42 | }catch (e) { 43 | const body = `${repoToMove} is not a repo under ${owner}. You can only transfer issue to repos that belong to the same organization.` 44 | await github.rest.issues.createComment({ 45 | owner, 46 | repo, 47 | issue_number, 48 | body 49 | }) 50 | process.exit(1) 51 | } 52 | env: 53 | REPO_TO_MOVE: ${{steps.extract_step.outputs.repo}} 54 | - name: Transfer Issue 55 | id: transferIssue 56 | working-directory: ./ 57 | run: | 58 | gh issue transfer ${{github.event.issue.number}} asyncapi/${{steps.extract_step.outputs.repo}} 59 | env: 60 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 61 | 62 | -------------------------------------------------------------------------------- /.github/workflows/update-maintainers-trigger.yaml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Trigger MAINTAINERS.yaml file update 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | paths: 10 | # Check all valid CODEOWNERS locations: 11 | # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-location 12 | - 'CODEOWNERS' 13 | - '.github/CODEOWNERS' 14 | - '.docs/CODEOWNERS' 15 | 16 | jobs: 17 | trigger-maintainers-update: 18 | name: Trigger updating MAINTAINERS.yaml because of CODEOWNERS change 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - name: Repository Dispatch 23 | uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # https://github.com/peter-evans/repository-dispatch/releases/tag/v3.0.0 24 | with: 25 | # The PAT with the 'public_repo' scope is required 26 | token: ${{ secrets.GH_TOKEN }} 27 | repository: ${{ github.repository_owner }}/community 28 | event-type: trigger-maintainers-update 29 | -------------------------------------------------------------------------------- /.github/workflows/update-pr.yml: -------------------------------------------------------------------------------- 1 | # This workflow is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | # This workflow will run on every comment with /update or /u. And will create merge-commits for the PR. 5 | # This also works with forks, not only with branches in the same repository/organization. 6 | # Currently, does not work with forks in different organizations. 7 | 8 | # This workflow will be distributed to all repositories in the AsyncAPI organization 9 | 10 | name: Update PR branches from fork 11 | 12 | on: 13 | issue_comment: 14 | types: [created] 15 | 16 | jobs: 17 | update-pr: 18 | if: > 19 | startsWith(github.repository, 'asyncapi/') && 20 | github.event.issue.pull_request && 21 | github.event.issue.state != 'closed' && ( 22 | contains(github.event.comment.body, '/update') || 23 | contains(github.event.comment.body, '/u') 24 | ) 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Get Pull Request Details 28 | id: pr 29 | uses: actions/github-script@v7 30 | with: 31 | github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} 32 | previews: 'merge-info-preview' # https://docs.github.com/en/graphql/overview/schema-previews#merge-info-preview-more-detailed-information-about-a-pull-requests-merge-state-preview 33 | script: | 34 | const prNumber = context.payload.issue.number; 35 | core.debug(`PR Number: ${prNumber}`); 36 | const { data: pr } = await github.rest.pulls.get({ 37 | owner: context.repo.owner, 38 | repo: context.repo.repo, 39 | pull_number: prNumber 40 | }); 41 | 42 | // If the PR has conflicts, we don't want to update it 43 | const updateable = ['behind', 'blocked', 'unknown', 'draft', 'clean'].includes(pr.mergeable_state); 44 | console.log(`PR #${prNumber} is ${pr.mergeable_state} and is ${updateable ? 'updateable' : 'not updateable'}`); 45 | core.setOutput('updateable', updateable); 46 | 47 | core.debug(`Updating PR #${prNumber} with head ${pr.head.sha}`); 48 | 49 | return { 50 | id: pr.node_id, 51 | number: prNumber, 52 | head: pr.head.sha, 53 | } 54 | - name: Update the Pull Request 55 | if: steps.pr.outputs.updateable == 'true' 56 | uses: actions/github-script@v7 57 | with: 58 | github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} 59 | script: | 60 | const mutation = `mutation update($input: UpdatePullRequestBranchInput!) { 61 | updatePullRequestBranch(input: $input) { 62 | pullRequest { 63 | mergeable 64 | } 65 | } 66 | }`; 67 | 68 | const pr_details = ${{ steps.pr.outputs.result }}; 69 | 70 | try { 71 | const { data } = await github.graphql(mutation, { 72 | input: { 73 | pullRequestId: pr_details.id, 74 | expectedHeadOid: pr_details.head, 75 | } 76 | }); 77 | } catch (GraphQLError) { 78 | core.debug(GraphQLError); 79 | if ( 80 | GraphQLError.name === 'GraphqlResponseError' && 81 | GraphQLError.errors.some( 82 | error => error.type === 'FORBIDDEN' || error.type === 'UNAUTHORIZED' 83 | ) 84 | ) { 85 | // Add comment to PR if the bot doesn't have permissions to update the PR 86 | const comment = `Hi @${context.actor}. Update of PR has failed. It can be due to one of the following reasons: 87 | - I don't have permissions to update this PR. To update your fork with upstream using bot you need to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in the PR. 88 | - The fork is located in an organization, not under your personal profile. No solution for that. You are on your own with manual update. 89 | - There may be a conflict in the PR. Please resolve the conflict and try again.`; 90 | 91 | await github.rest.issues.createComment({ 92 | owner: context.repo.owner, 93 | repo: context.repo.repo, 94 | issue_number: context.issue.number, 95 | body: comment 96 | }); 97 | 98 | core.setFailed('Bot does not have permissions to update the PR'); 99 | } else { 100 | core.setFailed(GraphQLError.message); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /.github/workflows/welcome-first-time-contrib.yml: -------------------------------------------------------------------------------- 1 | # This action is centrally managed in https://github.com/asyncapi/.github/ 2 | # Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo 3 | 4 | name: Welcome first time contributors 5 | 6 | on: 7 | pull_request_target: 8 | types: 9 | - opened 10 | issues: 11 | types: 12 | - opened 13 | 14 | jobs: 15 | welcome: 16 | name: Post welcome message 17 | if: ${{ !contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]", "allcontributors[bot]"]'), github.actor) }} 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/github-script@v7 21 | with: 22 | github-token: ${{ secrets.GITHUB_TOKEN }} 23 | script: | 24 | const issueMessage = `Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) and the instructions about a [basic recommended setup](https://github.com/asyncapi/community/blob/master/git-workflow.md) useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`; 25 | const prMessage = `Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`; 26 | if (!issueMessage && !prMessage) { 27 | throw new Error('Action must have at least one of issue-message or pr-message set'); 28 | } 29 | const isIssue = !!context.payload.issue; 30 | let isFirstContribution; 31 | if (isIssue) { 32 | const query = `query($owner:String!, $name:String!, $contributer:String!) { 33 | repository(owner:$owner, name:$name){ 34 | issues(first: 1, filterBy: {createdBy:$contributer}){ 35 | totalCount 36 | } 37 | } 38 | }`; 39 | const variables = { 40 | owner: context.repo.owner, 41 | name: context.repo.repo, 42 | contributer: context.payload.sender.login 43 | }; 44 | const { repository: { issues: { totalCount } } } = await github.graphql(query, variables); 45 | isFirstContribution = totalCount === 1; 46 | } else { 47 | const query = `query($qstr: String!) { 48 | search(query: $qstr, type: ISSUE, first: 1) { 49 | issueCount 50 | } 51 | }`; 52 | const variables = { 53 | "qstr": `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${context.payload.sender.login}`, 54 | }; 55 | const { search: { issueCount } } = await github.graphql(query, variables); 56 | isFirstContribution = issueCount === 1; 57 | } 58 | 59 | if (!isFirstContribution) { 60 | console.log(`Not the users first contribution.`); 61 | return; 62 | } 63 | const message = isIssue ? issueMessage : prMessage; 64 | // Add a comment to the appropriate place 65 | if (isIssue) { 66 | const issueNumber = context.payload.issue.number; 67 | console.log(`Adding message: ${message} to issue #${issueNumber}`); 68 | await github.rest.issues.createComment({ 69 | owner: context.payload.repository.owner.login, 70 | repo: context.payload.repository.name, 71 | issue_number: issueNumber, 72 | body: message 73 | }); 74 | } 75 | else { 76 | const pullNumber = context.payload.pull_request.number; 77 | console.log(`Adding message: ${message} to pull request #${pullNumber}`); 78 | await github.rest.pulls.createReview({ 79 | owner: context.payload.repository.owner.login, 80 | repo: context.payload.repository.name, 81 | pull_number: pullNumber, 82 | body: message, 83 | event: 'COMMENT' 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test/temp 3 | coverage 4 | **/.DS_Store 5 | **/.vscode -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This file provides an overview of code owners in the "java-spring-cloud-stream-template" repository. 2 | 3 | # Each line is a file pattern followed by one or more owners. 4 | # The last matching pattern has the most precedence. 5 | # For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/. 6 | 7 | # These are the default owners for the whole content of the "@asyncapi/java-spring-cloud-stream-template" repository. The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file. 8 | * @damaru-inc @CameronRushton @asyncapi-bot-eve 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at fmvilas@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to AsyncAPI 2 | We love your input! We want to make contributing to this project as easy and transparent as possible. 3 | 4 | ## Contribution recogniton 5 | 6 | We use [All Contributors](https://allcontributors.org/docs/en/specification) specification to handle recognitions. For more details read [this](https://github.com/asyncapi/community/blob/master/recognize-contributors.md) document. 7 | 8 | ## Summary of the contribution flow 9 | 10 | The following is a summary of the ideal contribution flow. Please, note that Pull Requests can also be rejected by the maintainers when appropriate. 11 | 12 | ``` 13 | ┌───────────────────────┐ 14 | │ │ 15 | │ Open an issue │ 16 | │ (a bug report or a │ 17 | │ feature request) │ 18 | │ │ 19 | └───────────────────────┘ 20 | ⇩ 21 | ┌───────────────────────┐ 22 | │ │ 23 | │ Open a Pull Request │ 24 | │ (only after issue │ 25 | │ is approved) │ 26 | │ │ 27 | └───────────────────────┘ 28 | ⇩ 29 | ┌───────────────────────┐ 30 | │ │ 31 | │ Your changes will │ 32 | │ be merged and │ 33 | │ published on the next │ 34 | │ release │ 35 | │ │ 36 | └───────────────────────┘ 37 | ``` 38 | 39 | ## Code of Conduct 40 | AsyncAPI has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](./CODE_OF_CONDUCT.md) so that you can understand what sort of behaviour is expected. 41 | 42 | ## Our Development Process 43 | We use Github to host code, to track issues and feature requests, as well as accept pull requests. 44 | 45 | ## Issues 46 | [Open an issue](https://github.com/asyncapi/asyncapi/issues/new) **only** if you want to report a bug or a feature. Don't open issues for questions or support, instead join our [Slack workspace](https://www.asyncapi.com/slack-invite) and ask there. Don't forget to follow our [Slack Etiquette](https://github.com/asyncapi/community/blob/master/slack-etiquette.md) while interacting with community members! It's more likely you'll get help, and much faster! 47 | 48 | ## Bug Reports and Feature Requests 49 | 50 | Please use our issues templates that provide you with hints on what information we need from you to help you out. 51 | 52 | ## Pull Requests 53 | 54 | **Please, make sure you open an issue before starting with a Pull Request, unless it's a typo or a really obvious error.** Pull requests are the best way to propose changes to the specification. Get familiar with our document that explains [Git workflow](https://github.com/asyncapi/community/blob/master/git-workflow.md) used in our repositories. 55 | 56 | ## Conventional commits 57 | 58 | Our repositories follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification. Releasing to GitHub and NPM is done with the support of [semantic-release](https://semantic-release.gitbook.io/semantic-release/). 59 | 60 | Pull requests should have a title that follows the specification, otherwise, merging is blocked. If you are not familiar with the specification simply ask maintainers to modify. You can also use this cheatsheet if you want: 61 | 62 | - `fix: ` prefix in the title indicates that PR is a bug fix and PATCH release must be triggered. 63 | - `feat: ` prefix in the title indicates that PR is a feature and MINOR release must be triggered. 64 | - `docs: ` prefix in the title indicates that PR is only related to the documentation and there is no need to trigger release. 65 | - `chore: ` prefix in the title indicates that PR is only related to cleanup in the project and there is no need to trigger release. 66 | - `test: ` prefix in the title indicates that PR is only related to tests and there is no need to trigger release. 67 | - `refactor: ` prefix in the title indicates that PR is only related to refactoring and there is no need to trigger release. 68 | 69 | What about MAJOR release? just add `!` to the prefix, like `fix!: ` or `refactor!: ` 70 | 71 | Prefix that follows specification is not enough though. Remember that the title must be clear and descriptive with usage of [imperative mood](https://chris.beams.io/posts/git-commit/#imperative). 72 | 73 | Happy contributing :heart: 74 | 75 | ## License 76 | When you submit changes, your submissions are understood to be under the same [Apache 2.0 License](https://github.com/asyncapi/asyncapi/blob/master/LICENSE) that covers the project. Feel free to [contact the maintainers](https://www.asyncapi.com/slack-invite) if that's a concern. 77 | 78 | ## References 79 | This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/master/CONTRIBUTING.md). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Spring Cloud Stream Generator Template 2 | 3 | This template generates a Spring Cloud Stream (SCSt) microservice. It uses version 3 of SCSt which uses function names to configure the channels. See the [reference](https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.1.RELEASE/reference/html/spring-cloud-stream.html). The generated microservice is a Maven project so it can easily be imported into your IDE. 4 | 5 | This template has been tested with Kafka, RabbitMQ and Solace. 6 | 7 | The Spring Cloud Stream microservice generated using this template will be an _ready to run_ Spring Boot app. By default, the microservice will contain a java class, _Application.java_, which includes methods to publish or subscribe events as defined in the AsyncAPI document. These generated methods include Supplier, Consumer and Function functional interfaces from the [java.util.function](https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html) package. These methods will already be pre-configured to publish to and consume from the channels as defined in the AsyncAPI. This configuration is located in the `spring.cloud.stream` section of the generated application.yml file. 8 | 9 | Note that this template ignores the 'Servers' section of AsyncAPI documents. The main reason for this is because SCSt does not directly work with messaging protocols. Protocols are implementation details specific to binders, and SCSt applications need not know or care which protocol is being used. 10 | 11 | ## Technical requirements 12 | 13 | - 1.9.4 =< [Generator](https://github.com/asyncapi/generator/) 14 | - Generator specific [requirements](https://github.com/asyncapi/generator/#requirements) 15 | 16 | ## Specification Conformance 17 | Note that this template interprets the AsyncAPI document in conformance with the [AsyncAPI Specification](https://www.asyncapi.com/docs/specifications/2.0.0/). 18 | This means that when the template sees a subscribe operation, it will generate code to publish to that operation's channel. 19 | It is possible to override this, see the 'view' parameter in the parameters section below. 20 | 21 | ### Which Methods are created 22 | The template works as follows: 23 | * By default, for each channel in the AsyncAPI document, if there is a _subscribe_ operation a _Supplier_ method will be generated, and for a _publish_ operation a _Consumer_ method will get generated. 24 | * To customize this default behavior, you can make use of the `x-scs-function-name` extension. If one _publish_ operation and one _subscribe_ operation share a `x-scs-function-name` attribute then a _java.util.function.Function_ method will be created which uses the _subscribe_ operation's message as the input and the _publish_ operation's message as the output to the generated Function method. It will also wire up the proper channel information in the generated application.yaml file. 25 | * Note that at this time the generator does not support the creation of functions that have more than one _publish_ and/or more than one _subscribe_ operation with the same ```x-scs-function-name``` attribute. This scenario will result in error. 26 | * Additionally, if a channel has parameters and a _subscribe_ operation, a _send method_ will be generated that takes the payload and the parameters as function arguments, formats the topic from the parameters, and sends the message using the StreamBridge as described in the [Spring Cloud Steam](https://docs.spring.io/spring-cloud-stream/docs/3.1.3/reference/html/spring-cloud-stream.html#_streambridge_and_dynamic_destinations) documentation. If you use `x-scs-function-name` to combine a _subscribe_ and a _publish_ operation and the _subscribe_ operation has parameters, then this template will render a _Consumer_ method that will receive a message and then call the generated _send method_ to send out a new message through the StreamBridge. 27 | 28 | This behaviour may be modified by setting the _dynamicType_ parameter to 'header'. This is to support binders that can route messages by putting the topic into a message header. In this case, a _Supplier_ and a _Function_ will set the header on the message rather than use the StreamBridge, however _send methods_ will still be rendered for convenience. 29 | 30 | 31 | ### Method Naming 32 | The generated methods are named as follows: 33 | * For each operation (i.e., _publish_ or _subscribe_ in each channel), the template looks for the specification extension ```x-scs-function-name```. If present, it uses that to name the function. 34 | * If using the same ```x-scs-function-name``` on one _publish_ operation and one _subscribe_ operation to create a Function the name of the generated method will be the ```x-scs-function-name``` 35 | * If there is no ```x-scs-function-name``` attribute, the generator checks the operation's operationId value. If set, that is used as the function name. 36 | * If there is no ```x-scs-function-name``` or operationId available, then a name will be generated by taking the channel name, removing non-alphanumeric characters, converting to camel case, and appending 'Supplier' or 'Producer.' For example, if there is a channel called store/process with a publisher operation with a payload called Order, the following method will get generated: 37 | ``` 38 | @Bean 39 | public Supplier storeProcessSupplier () { 40 | // Add business logic here. 41 | return null; 42 | } 43 | ``` 44 | ### Property Naming 45 | 46 | When converting from property names to Java field names, the property names are first converted to camelCase, removing non-alphanumeric characters in the process. If the resulting name ends up being a Java keyword, it is prepended with an underscore. 47 | 48 | ### Application vs Library 49 | 50 | By default, this will generate a runnable Spring Boot application. If you set the ```artifactType``` parameter to ```library```, then it will generate a project without a main Application class and without the main Spring Boot dependencies. That will produce a library that can be imported into another application as a Maven artifact. It will contain the model classes and the Spring Cloud Stream configuration. 51 | 52 | Doing that allows you to have a clean separation between the generated code and your hand-written code, and ensures that regenerating the library will not overwrite your business logic. 53 | 54 | ## How to Use This Template 55 | 56 | 1. Install the AsyncAPI Generator 57 | ``` 58 | npm install -g @asyncapi/generator 59 | ``` 60 | 61 | 2. Run the Generator using the Java Spring Cloud Stream Template 62 | ``` 63 | ag ~/AsyncApiDocument.yaml @asyncapi/java-spring-cloud-stream-template 64 | ``` 65 | 66 | 3. Run the Generator using the Java Spring Cloud Stream Template with Parameters 67 | ``` 68 | ag -p binder=solace -p artifactId=ExampleArtifactId -p groupId=com.example -p javaPackage=com.example.foo -p solaceSpringCloudVersion=1.0.0 -p springCloudStreamVersion=Horsham.SR3 -p springCloudVersion=Hoxton.SR3 ~/AsyncApiDocument.yaml @asyncapi/java-spring-cloud-stream-template 69 | ``` 70 | 71 | ## Configuration Options 72 | 73 | Please note that none of the parameters or specification extensions is required. All parameters have defaults as documented below. 74 | 75 | Any parameters or specification extensions that include the name 'Solace' only have an effect when the Solace binder is specified. If and when other binder-specific parameters are added to this template, they will follow a similar naming pattern. 76 | 77 | ### Destination Overrides 78 | 79 | There are two specification extensions you can use to shape how the bindings are configured. You can add the following to a _subscribe_ operation: 80 | 81 | ```x-scs-destination``` : This overrides the destination value in a binder. This is useful when you are using the Solace binder and you are following the Solace pattern of publishing to topics and consuming from queues. In this case the x-scs-destination value would be treated as the name of the queue which your microservice will consume from. 82 | 83 | ```x-scs-group``` : This will add the group value on a binding which configures your microservice to use [Consumer Groups](https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/current/reference/html/spring-cloud-stream.html#consumer-groups) 84 | 85 | ### Limitations 86 | Currently any schemas that are used must be in the components/schemas part of the document. We do not support anonymous object-type schemas in the message/payload sections. 87 | 88 | ### Parameters 89 | 90 | Parameters can be passed to the generator using command line arguments in the form ```-p param=value -p param2=value2```. Here is a list of the parameters that can be used with this template. In some cases these can be put into the AsyncAPI documents using the specification extensions feature. In those cases, the 'info' prefix means that it belongs in the info section of the document. 91 | 92 | Parameter | Extension | Default | Description 93 | ----------|-----------|---------|--- 94 | actuator | | false | If true, it adds the dependencies for spring-boot-starter-web, spring-boot-starter-actuator and micrometer-registry-prometheus. 95 | artifactId | info.x-artifact-id | project-name | The Maven artifact id. 96 | artifactType | | application | The type of project to generate, application or library. When generating an application, the pom.xml file will contain the complete set of dependencies required to run an app, and it will contain an Application class with a main function. Otherwise the pom file will include only the dependencies required to compile a library. 97 | binder | | kafka | The name of the binder implementation, one of kafka, rabbit or solace. Default: kafka. If you need other binders to be supported, please let us know! 98 | dynamicType | | streamBridge | If you publish to a channel with parameters, i.e. a topic that can change with every message, the standard way to do this is to use StreamBridge. But some binders such as Solace can do the dynamic routing using just a message header. If you use such a binder, then you can set this value to 'header' and the generated code will set the topic on the header rather than use StreamBridge. 99 | groupId | info.x-group-id | com.company | The Maven group id. 100 | host | | tcp://localhost:55555 | The host connection property. Currently this only works with the Solace binder. When other binders are used this parameter is ignored. 101 | javaPackage | info.x-java-package | | The Java package of the generated classes. If not set then the classes will be in the default package. 102 | msgVpn | | default | The message vpn connection property. Currently this only works with the Solace binder. When other binders are used this parameter is ignored. 103 | password | | default | The client password connection property. Currently this only works with the Solace binder. When other binders are used this parameter is ignored. 104 | parametersToHeaders | | false | If true, this will create headers on the incoming messages for each channel parameter. Currently this only works with messages originating from Solace (using the solace_destination header) and RabbitMQ (using the amqp_receivedRoutingKey header.) 105 | reactive | | false | If true, the generated functions will use the Reactive style and use the Flux class. 106 | solaceSpringCloudVersion | info.x-solace-spring-cloud-version | 2.1.0 | The version of the solace-spring-cloud-bom dependency used when generating an application. 107 | springBootVersion | info.x-spring-boot-version | 2.4.7 | The version of Spring Boot used when generating an application. 108 | springCloudVersion | info.x-spring-cloud-version | 2020.0.3 | The version of the spring-cloud-dependencies BOM dependency used when generating an application. 109 | springCloudStreamVersion | info.x-spring-cloud-stream-version | 3.1.3 | The version of the spring-cloud-stream dependency specified in the Maven file, when generating a library. When generating an application, the spring-cloud-dependencies BOM is used instead 110 | username | | default | The client username connection property. Currently this only works with the Solace binder. When other binders are used this parameter is ignored. 111 | view | info.x-view | client | By default, this template generates publisher code for subscribe operations and vice versa. You can switch this by setting this parameter to 'provider'. 112 | useServers | | false | This parameter only works when the binder parameter is kafka. It takes all the urls under the server section and concatenates them to a set of brokers. 113 | 114 | ## Specification Extensions 115 | 116 | The following specification extensions are supported. In some cases, their value can be provided as a command line parameter. The 'info' prefix means that it belongs in the info section of the document. 117 | 118 | Extension | Parameter | Default | Description 119 | ----------|-----------|---------|------------- 120 | info.x-artifact-id | artifactId | project-name | The Maven artifact id. 121 | info.x-group-id | groupId | com.company | The Maven group id. 122 | info.x-java-package | javaPackage | | The Java package of the generated classes. If not set then the classes will be in the default package. 123 | info.x-solace-spring-cloud-version | solaceSpringCloudVersion | 1.0.0 | The version of the solace-spring-cloud BOM dependency used when generating an application. 124 | info.x-spring-boot-version | info.x-spring-boot-version | 2.2.6.RELEASE | The version of the Spring Boot used when generating an application. 125 | info.x-spring-cloud-version | info.x-spring-cloud-version | Hoxton.SR3 | The version of the spring-cloud-dependencies BOM dependency used when generating an application. 126 | info.x-spring-cloud-stream-version | springCloudStreamVersion | 3.0.3.RELEASE | The version of the spring-cloud-stream dependency specified in the Maven file, when generating a library. When generating an application, the spring-cloud-dependencies BOM is used instead. 127 | info.x-view | view | client | By default, this template generates publisher code for subscribe operations and vice versa. You can switch this by setting this parameter to 'provider'. 128 | operation.x-scs-function-name | | | This specifies the base function name to use on a publish or subscribe operation. If the same name is used on one subscribe operation and one publish operation, a processor function will be generated. 129 | channel.subscription.x-scs-destination | | | This overrides the destination on an incoming binding. It can be used to specify, for example, the name of a queue to subscribe to instead of a topic. 130 | channel.subscription.x-scs-group | | | This is used to specify the group property of an incoming binding. 131 | 132 | ## Development 133 | 134 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome! 135 | 136 | If you do contribute, please run ```npm run lint``` and ```npm test``` before you submit your code. 137 | 138 | 139 | ## Contributors 140 | 141 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 |

Michael Davis

💻 📖 👀 💬

Marc DiPasquale

📖

Fran Méndez

💻 🚇

Lukasz Gornicki

🚇 💻

blzsaa

💻
156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /hooks/post-process.js: -------------------------------------------------------------------------------- 1 | // vim: set ts=2 sw=2 sts=2 expandtab : 2 | const fs = require('fs'); 3 | const path = require('path'); 4 | const ApplicationModel = require('../lib/applicationModel.js'); 5 | const _ = require('lodash'); 6 | const applicationModel = new ApplicationModel('post'); 7 | // To enable debug logging, set the env var DEBUG="postProcess" with whatever things you want to see. 8 | const debugPostProcess = require('debug')('postProcess'); 9 | const sourceHead = '/src/main/java/'; 10 | 11 | module.exports = { 12 | 'generate:after': generator => { 13 | const asyncapi = generator.asyncapi; 14 | const sourcePath = generator.targetDir + sourceHead; 15 | 16 | // NEW 17 | 18 | const defaultJavaPackage = getDefaultJavaPackage(generator); 19 | const defaultJavaPackageDir = getDefaultJavaPackageDir(generator, defaultJavaPackage); 20 | 21 | asyncapi.allSchemas().forEach((schema, schemaName) => { 22 | processSchema(generator, schemaName, schema, sourcePath, defaultJavaPackageDir); 23 | }); 24 | 25 | // Rename the pom file if necessary, and only include Application.java when an app is requested. 26 | const artifactType = generator.templateParams['artifactType']; 27 | 28 | if (artifactType === 'library') { 29 | fs.renameSync(path.resolve(generator.targetDir, 'pom.lib'), path.resolve(generator.targetDir, 'pom.xml')); 30 | fs.unlinkSync(path.resolve(generator.targetDir, 'pom.app')); 31 | fs.unlinkSync(path.resolve(sourcePath, 'Application.java')); 32 | } else { 33 | fs.renameSync(path.resolve(generator.targetDir, 'pom.app'), path.resolve(generator.targetDir, 'pom.xml')); 34 | fs.unlinkSync(path.resolve(generator.targetDir, 'pom.lib')); 35 | if (defaultJavaPackageDir) { 36 | moveFile(sourcePath, defaultJavaPackageDir, 'Application.java'); 37 | } 38 | } 39 | applicationModel.reset(); // Must clear its cache for when we run the jest tests. 40 | } 41 | }; 42 | 43 | function getDefaultJavaPackage(generator) { 44 | const asyncapi = generator.asyncapi; 45 | const info = asyncapi.info(); 46 | let javaPackage = generator.templateParams['javaPackage']; 47 | const extensions = info.extensions(); 48 | 49 | if (!javaPackage && info && extensions) { 50 | javaPackage = extensions['x-java-package']; 51 | } 52 | 53 | debugPostProcess(`getDefaultJavaPackage: ${javaPackage}`); 54 | return javaPackage; 55 | } 56 | 57 | function getDefaultJavaPackageDir(generator, defaultJavaPackage) { 58 | let defaultPackageDir; 59 | 60 | if (defaultJavaPackage) { 61 | const packageDir = packageToPath(defaultJavaPackage); 62 | defaultPackageDir = `${generator.targetDir}${sourceHead}${packageDir}`; 63 | } 64 | 65 | debugPostProcess(`getDefaultJavaPackageDir: ${defaultPackageDir}`); 66 | return defaultPackageDir; 67 | } 68 | 69 | function packageToPath(javaPackage) { 70 | return javaPackage.replace(/\./g, '/'); 71 | } 72 | 73 | function processSchema(generator, schemaName, schema, sourcePath, defaultJavaPackageDir) { 74 | const fileName = getFileName(schemaName); 75 | const filePath = path.resolve(sourcePath, fileName); 76 | debugPostProcess(`processSchema ${schemaName}`); 77 | debugPostProcess(schema); 78 | const modelClass = applicationModel.getModelClass({schema, schemaName}); 79 | const javaName = modelClass.getClassName(); 80 | if ((schema.type() && schema.type() !== 'object') || _.startsWith(javaName, 'Anonymous')) { 81 | debugPostProcess(`deleting ${filePath}`); 82 | if (fs.existsSync(filePath)) { 83 | fs.unlinkSync(filePath); 84 | } 85 | } else { 86 | const packageDir = getPackageDir(generator, defaultJavaPackageDir, modelClass); 87 | debugPostProcess(`packageDir: ${packageDir}`); 88 | 89 | if (packageDir) { 90 | moveFile(sourcePath, packageDir, fileName); 91 | } 92 | 93 | debugPostProcess(`javaName: ${javaName} schemaName: ${schemaName}`); 94 | if (javaName !== schemaName) { 95 | const currentPath = packageDir || sourcePath; 96 | const newPath = path.resolve(currentPath, `${javaName}.java`); 97 | const oldPath = path.resolve(currentPath, fileName); 98 | fs.renameSync(oldPath, newPath); 99 | debugPostProcess(`Renamed class file ${schemaName} to ${javaName}`); 100 | } 101 | } 102 | } 103 | 104 | function getFileName(schemaName) { 105 | const trimmedSchemaName = trimSchemaName(schemaName); 106 | return `${trimmedSchemaName}.java`; 107 | } 108 | 109 | function trimSchemaName(schemaName) { 110 | let trimmedSchemaName = schemaName; 111 | if (schemaName.startsWith('<')) { 112 | trimmedSchemaName = schemaName.replace('<', ''); 113 | trimmedSchemaName = trimmedSchemaName.replace(/>$/, ''); 114 | } 115 | return trimmedSchemaName; 116 | } 117 | 118 | function getPackageDir(generator, defaultJavaPackageDir, modelClass) { 119 | const fileSpecificPackage = modelClass.getJavaPackage(); 120 | if (fileSpecificPackage) { 121 | const packagePath = packageToPath(fileSpecificPackage); 122 | return `${generator.targetDir}${sourceHead}${packagePath}`; 123 | } 124 | return defaultJavaPackageDir; 125 | } 126 | 127 | function moveFile(oldDirectory, newDirectory, fileName) { 128 | if (!fs.existsSync(newDirectory)) { 129 | fs.mkdirSync(newDirectory, { recursive: true }); 130 | debugPostProcess(`Made directory ${newDirectory}`); 131 | } 132 | const oldPath = path.resolve(oldDirectory, fileName); 133 | const newPath = path.resolve(newDirectory, fileName); 134 | fs.copyFileSync(oldPath, newPath); 135 | fs.unlinkSync(oldPath); 136 | debugPostProcess(`Moved ${fileName} from ${oldPath} to ${newPath}`); 137 | } 138 | -------------------------------------------------------------------------------- /hooks/pre-process.js: -------------------------------------------------------------------------------- 1 | const ApplicationModel = require('../lib/applicationModel.js'); 2 | const _ = require('lodash'); 3 | 4 | function setSchemaIdsForFileName(asyncapi) { 5 | asyncapi.allSchemas().forEach((schema, schemaName) => { 6 | // If we leave the $id the way it is, the generator will name the schema files what their $id is, which is always a bad idea. 7 | // So we leave it in, but $id is going to be changed to be the class name we want. 8 | // If we remove the $id and there's no x-parser-schema-id, then it wont be returned by allSchemas(). 9 | if (schema.$id()) { 10 | // Assuming one of x-parser-schema-id and $id must be present. 11 | let classNameForGenerator; 12 | const parserSchemaId = schema.ext('x-parser-schema-id'); 13 | classNameForGenerator = parserSchemaId ? parserSchemaId : _.camelCase(schema.$id().substring(schema.$id().lastIndexOf('/') + 1)); 14 | 15 | if (classNameForGenerator === 'items') { 16 | let parentSchema; 17 | if (schema.options) { 18 | parentSchema = schema.options.parent; 19 | } 20 | let parentSchemaItems; 21 | if (parentSchema) { 22 | parentSchemaItems = parentSchema.items(); 23 | } 24 | let parentSchemaItemsId; 25 | if (parentSchemaItems && parentSchemaItems._json) { 26 | parentSchemaItemsId = parentSchemaItems._json.$id; 27 | } 28 | if (parentSchemaItemsId === schema.$id()) { 29 | const parentParserSchemaId = parentSchema.ext('x-parser-schema-id'); 30 | classNameForGenerator = parentParserSchemaId ? parentParserSchemaId : _.camelCase(parentSchema.$id().substring(parentSchema.$id().lastIndexOf('/') + 1)); 31 | // If we come across this schema later in the code generator, we'll know to rename it to its parent because the proper settings will be set in the model class. 32 | schema._json['x-model-class-name'] = classNameForGenerator; 33 | classNameForGenerator += 'Items'; 34 | } 35 | } 36 | schema._json.$id = classNameForGenerator; 37 | } 38 | }); 39 | } 40 | 41 | function setSchemaIdsForFileNameIncludingDuplicates(asyncapi) { 42 | // We do this multiple times because allSchemas() returns a list of deduplicated schemas, so if we change the $id of a schema, 43 | // we wont change any of the duplicates. We continue until there are no more duplicates to change. 44 | let numSchemas; 45 | let newNumSchemas; 46 | do { 47 | numSchemas = asyncapi.allSchemas().size; 48 | setSchemaIdsForFileName(asyncapi); 49 | newNumSchemas = asyncapi.allSchemas().size; 50 | } while (numSchemas !== newNumSchemas); 51 | } 52 | 53 | module.exports = { 54 | 'generate:before': generator => { 55 | setSchemaIdsForFileNameIncludingDuplicates(generator.asyncapi); 56 | ApplicationModel.asyncapi = generator.asyncapi; 57 | } 58 | }; -------------------------------------------------------------------------------- /lib/applicationModel.js: -------------------------------------------------------------------------------- 1 | const ModelClass = require('./modelClass.js'); 2 | const debugApplicationModel = require('debug')('applicationModel'); 3 | const _ = require('lodash'); 4 | const ScsLib = require('./scsLib.js'); 5 | const scsLib = new ScsLib(); 6 | const instanceMap = new Map(); 7 | 8 | class ApplicationModel { 9 | constructor(caller) { 10 | this.caller = caller; 11 | debugApplicationModel(`constructor for ${caller} ++++++++++++++++++++++++++++++++++++++++++`); 12 | instanceMap.set(caller, this); 13 | debugApplicationModel(instanceMap); 14 | } 15 | 16 | getModelClass({schema, schemaName}) { 17 | debugApplicationModel(`getModelClass for caller ${this.caller} schema ${schemaName}`); 18 | this.setupSuperClassMap(); 19 | this.setupModelClassMap(); 20 | let modelClass; 21 | if (schema) { 22 | const parserSchemaName = schema.ext('x-parser-schema-id'); 23 | // Try to use x-parser-schema-id as key 24 | modelClass = this.modelClassMap[parserSchemaName]; 25 | if (modelClass && _.startsWith(modelClass.getClassName(), 'Anonymous')) { 26 | // If we translated this schema from the map using an anonymous schema key, we have no idea what the name should be, so we use the one provided directly from the source - not the generator. 27 | // Otherwise, if we translated this schema from the map using a known schema (the name of the schema was picked out correctly by the generator), use that name. 28 | modelClass.setClassName(_.upperFirst(this.isAnonymousSchema(parserSchemaName) ? schemaName : parserSchemaName)); 29 | } 30 | } 31 | // Using x-parser-schema-id didn't work for us, fall back to trying to get at least something using the provided name. 32 | if (!modelClass) { 33 | modelClass = this.modelClassMap[schemaName] || this.modelClassMap[_.camelCase(schemaName)]; 34 | } 35 | debugApplicationModel(`returning modelClass for caller ${this.caller} ${schemaName}`); 36 | debugApplicationModel(modelClass); 37 | return modelClass; 38 | } 39 | 40 | getSchema(schemaName) { 41 | return ApplicationModel.asyncapi.components().schema(schemaName); 42 | } 43 | 44 | setupSuperClassMap() { 45 | if (this.superClassMap) { 46 | return; 47 | } 48 | this.superClassMap = new Map(); 49 | this.anonymousSchemaToSubClassMap = new Map(); 50 | debugApplicationModel('-------- SCHEMAS -------------'); 51 | debugApplicationModel(ApplicationModel.asyncapi.allSchemas()); 52 | ApplicationModel.asyncapi.allSchemas().forEach((schema, schemaName) => { 53 | debugApplicationModel(`${schemaName}:`); 54 | debugApplicationModel(schema); 55 | const allOf = schema.allOf(); 56 | if (allOf) { 57 | this.handleAllOfSchema(schema, schemaName, allOf); 58 | } 59 | }); 60 | debugApplicationModel('-----------------------------'); 61 | debugApplicationModel('superclassMap:'); 62 | debugApplicationModel(this.superClassMap); 63 | debugApplicationModel('anonymousSchemaToSubClassMap:'); 64 | debugApplicationModel(this.anonymousSchemaToSubClassMap); 65 | } 66 | 67 | handleAllOfSchema(schema, schemaName, allOfSchema) { 68 | let anonymousSchema; 69 | let namedSchema; 70 | allOfSchema.forEach(innerSchema => { 71 | debugApplicationModel('=== allOf inner schema: ==='); 72 | debugApplicationModel(innerSchema); 73 | debugApplicationModel('==========================='); 74 | const name = innerSchema._json['x-parser-schema-id']; 75 | if (this.isAnonymousSchema(name)) { 76 | anonymousSchema = name; 77 | } else { 78 | namedSchema = name; 79 | } 80 | }); 81 | if (!anonymousSchema || !namedSchema) { 82 | console.log('Warning: Unable to find both an anonymous and a named schema in an allOf schema.'); 83 | console.log(schema); 84 | } else { 85 | this.superClassMap[anonymousSchema] = namedSchema; 86 | this.anonymousSchemaToSubClassMap[anonymousSchema] = schemaName; 87 | this.superClassMap[schemaName] = namedSchema; 88 | this.anonymousSchemaToSubClassMap[schemaName] = anonymousSchema; 89 | } 90 | } 91 | 92 | setupModelClassMap() { 93 | if (this.modelClassMap) { 94 | return; 95 | } 96 | this.modelClassMap = new Map(); 97 | this.nameToSchemaMap = new Map(); 98 | // Register all schemas recursively as a flat map of name -> ModelClass 99 | ApplicationModel.asyncapi.allSchemas().forEach((schema, name) => { 100 | debugApplicationModel(`setupModelClassMap ${name} type ${schema.type()}`); 101 | this.registerSchemaNameToModelClass(schema, name); 102 | this.nameToSchemaMap[name] = schema; 103 | }); 104 | debugApplicationModel('modelClassMap:'); 105 | debugApplicationModel(this.modelClassMap); 106 | } 107 | 108 | isAnonymousSchema(schemaName) { 109 | return schemaName.startsWith('<'); 110 | } 111 | 112 | registerSchemaNameToModelClass(schema, schemaName) { 113 | let modelClass = this.modelClassMap[schemaName]; 114 | if (!modelClass) { 115 | modelClass = new ModelClass(); 116 | } 117 | 118 | if (this.isAnonymousSchema(schemaName)) { 119 | this.handleAnonymousSchemaForAllOf(modelClass, schemaName); 120 | } 121 | const components = ApplicationModel.asyncapi._json.components; 122 | const nonInnerClassSchemas = Object.keys(components? components.schemas || {} : {}); 123 | if (nonInnerClassSchemas.includes(schemaName)) { 124 | modelClass.setCanBeInnerClass(false); 125 | } 126 | 127 | const classNameAndLocation = scsLib.stripPackageName(schemaName); 128 | let className = classNameAndLocation.className; 129 | const javaPackage = classNameAndLocation.javaPackage; 130 | if (schema._json['x-model-class-name']) { 131 | className = schema._json['x-model-class-name']; 132 | } 133 | modelClass.setJavaPackage(javaPackage); 134 | modelClass.setClassName(className); 135 | debugApplicationModel(`schemaName ${schemaName} className: ${modelClass.getClassName()} super: ${modelClass.getSuperClassName()} javaPackage: ${javaPackage}`); 136 | this.modelClassMap[schemaName] = modelClass; 137 | debugApplicationModel(`Added ${schemaName}`); 138 | debugApplicationModel(modelClass); 139 | } 140 | 141 | getAnonymousSchemaForRef(realSchemaName) { 142 | // During our allOf parsing, we found this real schema to anon-schema association 143 | const anonSchema = this.anonymousSchemaToSubClassMap[realSchemaName]; 144 | return anonSchema ? this.nameToSchemaMap[anonSchema] : undefined; 145 | } 146 | 147 | handleAnonymousSchemaForAllOf(modelClass, schemaName) { 148 | const subclassName = this.anonymousSchemaToSubClassMap[schemaName]; 149 | if (subclassName) { 150 | modelClass.setSuperClassName(this.superClassMap[schemaName]); 151 | // Be sure the anonymous modelClass and the named modelClass are updated with the superclass information 152 | // We dont want the anonymous schema because the class name won't be correct if it's a $ref, so if the modelClass exists, update that one, if it doesn't we'll make it 153 | const existingModelClass = this.modelClassMap[subclassName]; 154 | if (existingModelClass) { 155 | existingModelClass.setSuperClassName(this.superClassMap[schemaName]); 156 | } 157 | return subclassName; 158 | } 159 | return schemaName; 160 | } 161 | 162 | reset() { 163 | instanceMap.forEach((val) => { 164 | val.superClassMap = null; 165 | val.anonymousSchemaToSubClassMap = null; 166 | val.modelClassMap = null; 167 | val.nameToSchemaMap = null; 168 | }); 169 | } 170 | } 171 | 172 | module.exports = ApplicationModel; 173 | -------------------------------------------------------------------------------- /lib/modelClass.js: -------------------------------------------------------------------------------- 1 | const _ = require('lodash'); 2 | 3 | class ModelClass { 4 | constructor() { 5 | this.innerClass = true; 6 | } 7 | 8 | getClassName() { 9 | return this.className; 10 | } 11 | 12 | setClassName(originalName) { 13 | this.className = this.fixClassName(originalName); 14 | } 15 | 16 | getSuperClassName() { 17 | return this.superClassName; 18 | } 19 | 20 | setSuperClassName(originalName) { 21 | this.superClassName = this.fixClassName(originalName); 22 | } 23 | 24 | getJavaPackage() { 25 | return this.javaPackage; 26 | } 27 | 28 | setJavaPackage(javaPackage) { 29 | this.javaPackage = javaPackage; 30 | } 31 | 32 | isSubClass() { 33 | return this.superClassName !== undefined; 34 | } 35 | 36 | fixClassName(originalName) { 37 | return _.upperFirst(_.camelCase(originalName)); 38 | } 39 | 40 | setCanBeInnerClass(innerClass) { 41 | this.innerClass = innerClass; 42 | } 43 | 44 | canBeInnerClass() { 45 | return this.innerClass; 46 | } 47 | } 48 | 49 | module.exports = ModelClass; -------------------------------------------------------------------------------- /lib/scsLib.js: -------------------------------------------------------------------------------- 1 | // This contains functions that are common to both the all.js filter and the post-process.js hook. 2 | //const Common = require('./common.ts'); 3 | const _ = require('lodash'); 4 | 5 | class ScsLib { 6 | constructor() { 7 | if (!ScsLib.javaKeywords) { 8 | this.initReservedWords(); 9 | } 10 | } 11 | 12 | // This returns a valid Java class name. 13 | getClassName(name) { 14 | const ret = _.camelCase(name); 15 | console.log(`getClassName: ${name} ${ret}`); 16 | return _.upperFirst(ret); 17 | } 18 | 19 | // This returns a valid Java identifier name. 20 | getIdentifierName(name) { 21 | let ret = _.camelCase(name); 22 | 23 | if (ScsLib.javaKeywords.has(ret)) { 24 | ret = `_${ret}`; 25 | } 26 | 27 | return ret; 28 | } 29 | 30 | // This returns the value of a param, or specification extension if the param isn't set. 31 | // If neither is set and the required flag is true, it throws an error. 32 | getParamOrExtension(info, params, paramName, extensionName, description, example, required) { 33 | let ret = ''; 34 | if (params[paramName]) { 35 | ret = params[paramName]; 36 | } else if (info.extensions()[extensionName]) { 37 | ret = info.extensions()[extensionName]; 38 | } else if (required) { 39 | throw new Error(`Can't determine the ${description}. Please set the param ${paramName} or info.${extensionName}. Example: ${example}`); 40 | } 41 | return ret; 42 | } 43 | 44 | // This returns the value of a param, or specification extension if the param isn't set. 45 | // If neither is set it returns defaultValue. 46 | getParamOrDefault(info, params, paramName, extensionName, defaultValue) { 47 | let ret = ''; 48 | if (params[paramName]) { 49 | ret = params[paramName]; 50 | } else if (info.extensions()[extensionName]) { 51 | ret = info.extensions()[extensionName]; 52 | } else { 53 | ret = defaultValue; 54 | } 55 | return ret; 56 | } 57 | 58 | /* 59 | By default, the 'view' is 'client', which means that when the doc says subscribe, we publish. 60 | By setting the view to 'provider', when the doc says subscribe, we subscribe. 61 | */ 62 | isProvidererView(info, params) { 63 | const view = this.getParamOrDefault(info, params, 'view', 'x-view', undefined); 64 | return view === 'provider'; 65 | } 66 | 67 | /* 68 | See isProviderView above. 69 | This returns true if the operation should physically subscribe, based on the 'view' param. 70 | */ 71 | isRealSubscriber(info, params, operation) { 72 | const isProvider = this.isProvidererView(info, params); 73 | const ret = (isProvider && operation.isSubscribe()) || (!isProvider && !operation.isSubscribe()); 74 | console.log(`isRealSubscriber: isProvider: ${isProvider} isSubscribe: ${operation.isSubscribe()}`); 75 | return ret; 76 | } 77 | 78 | getRealPublisher(info, params, channel) { 79 | const isProvider = this.isProvidererView(info, params); 80 | return isProvider ? channel.publish() : channel.subscribe(); 81 | } 82 | 83 | getRealSubscriber(info, params, channel) { 84 | const isProvider = this.isProvidererView(info, params); 85 | return isProvider ? channel.subscribe() : channel.publish(); 86 | } 87 | 88 | /** 89 | * Takes a string, splits on the last instance of '.' (dot) if it exists and returns an object of the separated pieces. 90 | * 91 | * @param {String} dotSeparatedName Example: 'com.solace.api.Schema'. 92 | * @returns {Object} { javaPackage, className } Example: { javaPackage: "com.solace.api", className: "Schema" }. 93 | */ 94 | stripPackageName(dotSeparatedName) { 95 | // If there is a dot in the schema name, it's probably an Avro schema with a fully qualified name (including the namespace.) 96 | const indexOfDot = dotSeparatedName.lastIndexOf('.'); 97 | if (indexOfDot > 0) { 98 | return { javaPackage: dotSeparatedName.substring(0, indexOfDot), className: dotSeparatedName.substring(indexOfDot + 1) }; 99 | } 100 | return { className: dotSeparatedName }; 101 | } 102 | 103 | initReservedWords() { 104 | // This is the set of Java reserved words, to ensure that we don't generate any by mistake. 105 | ScsLib.javaKeywords = new Set(); 106 | ScsLib.javaKeywords.add('abstract'); 107 | ScsLib.javaKeywords.add('assert'); 108 | ScsLib.javaKeywords.add('boolean'); 109 | ScsLib.javaKeywords.add('break'); 110 | ScsLib.javaKeywords.add('byte'); 111 | ScsLib.javaKeywords.add('case'); 112 | ScsLib.javaKeywords.add('catch'); 113 | ScsLib.javaKeywords.add('char'); 114 | ScsLib.javaKeywords.add('class'); 115 | ScsLib.javaKeywords.add('const'); 116 | ScsLib.javaKeywords.add('continue'); 117 | ScsLib.javaKeywords.add('default'); 118 | ScsLib.javaKeywords.add('do'); 119 | ScsLib.javaKeywords.add('double'); 120 | ScsLib.javaKeywords.add('else'); 121 | ScsLib.javaKeywords.add('enum'); 122 | ScsLib.javaKeywords.add('extends'); 123 | ScsLib.javaKeywords.add('final'); 124 | ScsLib.javaKeywords.add('finally'); 125 | ScsLib.javaKeywords.add('float'); 126 | ScsLib.javaKeywords.add('for'); 127 | ScsLib.javaKeywords.add('if'); 128 | ScsLib.javaKeywords.add('goto'); 129 | ScsLib.javaKeywords.add('implements'); 130 | ScsLib.javaKeywords.add('import'); 131 | ScsLib.javaKeywords.add('instalceof'); 132 | ScsLib.javaKeywords.add('int'); 133 | ScsLib.javaKeywords.add('interface'); 134 | ScsLib.javaKeywords.add('long'); 135 | ScsLib.javaKeywords.add('native'); 136 | ScsLib.javaKeywords.add('new'); 137 | ScsLib.javaKeywords.add('package'); 138 | ScsLib.javaKeywords.add('private'); 139 | ScsLib.javaKeywords.add('proteccted'); 140 | ScsLib.javaKeywords.add('public'); 141 | ScsLib.javaKeywords.add('return'); 142 | ScsLib.javaKeywords.add('short'); 143 | ScsLib.javaKeywords.add('static'); 144 | ScsLib.javaKeywords.add('strictfp'); 145 | ScsLib.javaKeywords.add('super'); 146 | ScsLib.javaKeywords.add('switch'); 147 | ScsLib.javaKeywords.add('syncronized'); 148 | ScsLib.javaKeywords.add('this'); 149 | ScsLib.javaKeywords.add('throw'); 150 | ScsLib.javaKeywords.add('throws'); 151 | ScsLib.javaKeywords.add('transient'); 152 | ScsLib.javaKeywords.add('try'); 153 | ScsLib.javaKeywords.add('void'); 154 | ScsLib.javaKeywords.add('volatile'); 155 | ScsLib.javaKeywords.add('while'); 156 | } 157 | } 158 | 159 | module.exports = ScsLib; 160 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@asyncapi/java-spring-cloud-stream-template", 3 | "version": "0.13.0", 4 | "description": "Java Spring Cloud Stream template for AsyncAPI generator.", 5 | "scripts": { 6 | "lint": "eslint --config .eslintrc .", 7 | "lint:fix": "eslint --fix --config .eslintrc .", 8 | "generate:assets": "echo 'No additional assets need to be generated at the moment'", 9 | "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", 10 | "test": "jest --maxWorkers=50% --detectOpenHandles", 11 | "test:watch": "npm run test -- --watch", 12 | "test:watchAll": "npm run test -- --watchAll", 13 | "test:coverage": "npm run test -- --coverage", 14 | "test:updateSnapshots": "npm run test -- -u" 15 | }, 16 | "keywords": [ 17 | "asyncapi", 18 | "cloud", 19 | "generator", 20 | "java", 21 | "spring", 22 | "template" 23 | ], 24 | "publishConfig": { 25 | "access": "public" 26 | }, 27 | "author": "Michael Davis ", 28 | "license": "Apache-2.0", 29 | "dependencies": { 30 | "@asyncapi/generator-filters": "^2.1.0", 31 | "@types/node": "^16.7.1", 32 | "js-yaml": "^3.13.1", 33 | "lodash": "^4.17.15" 34 | }, 35 | "devDependencies": { 36 | "@asyncapi/generator": "^1.9.4", 37 | "eslint": "^7.32.0", 38 | "eslint-plugin-jest": "^24.3.6", 39 | "jest": "^27.0.4" 40 | }, 41 | "generator": { 42 | "generator": ">=1.8.6 <=2.3.0", 43 | "parameters": { 44 | "actuator": { 45 | "description": "If present, it adds the dependencies for spring-boot-starter-web, spring-boot-starter-actuator and micrometer-registry-prometheus.", 46 | "required": false, 47 | "default": false 48 | }, 49 | "artifactId": { 50 | "description": "The Maven artifact id. Alternatively you can set the specification extension info.x-artifact-id", 51 | "required": false, 52 | "default": "project-name" 53 | }, 54 | "artifactType": { 55 | "description": "The type of project to generate, application or library. The default is application. When generating an application, the pom.xml file will contain the complete set of dependencies required to run an app, and it will contain an Application class with a main function. Otherwise the pom file will include only the dependencies required to compile a library.", 56 | "required": false, 57 | "default": "application" 58 | }, 59 | "binder": { 60 | "description": "The name of the binder implementation, one of kafka, rabbit or solace. Default: kafka. If you need other binders to be supported, please let us know!", 61 | "required": false, 62 | "default": "kafka" 63 | }, 64 | "dynamicType": { 65 | "description": "When using channels with parameters, i.e. dynamic topics where the topic could be different for each message, this determines whether to use the StreamBridge or a message header. StreamBridge can be used with all binders, but some binders such as Solace can use the topic set in a header for better performance. Possible values are streamBridge and header. Default is streamBridge.", 66 | "required": false, 67 | "default": "streamBridge" 68 | }, 69 | "groupId": { 70 | "description": "The Maven group id. Alternatively you can set the specification extension info.x-group-id", 71 | "required": false, 72 | "default": "com.company" 73 | }, 74 | "host": { 75 | "description": "The host connection property. Currently this only works with the Solace binder. Example: tcp://myhost.com:55555.", 76 | "required": false, 77 | "default": "tcp://localhost:55555" 78 | }, 79 | "javaPackage": { 80 | "description": "The Java package of the generated classes. Alternatively you can set the specification extension info.x-java-package", 81 | "required": false 82 | }, 83 | "msgVpn": { 84 | "description": "The message vpn connection property. Currently this only works with the Solace binder.", 85 | "required": false, 86 | "default": "default" 87 | }, 88 | "parametersToHeaders": { 89 | "description": "If true, this will create headers on the incoming messages for each channel parameter. Currently this only works with messages originating from Solace (using the solace_destination header) and RabbitMQ (using the amqp_receivedRoutingKey header.)", 90 | "required": false, 91 | "default": false 92 | }, 93 | "password": { 94 | "description": "The client password connection property. Currently this only works with the Solace binder.", 95 | "required": false, 96 | "default": "default" 97 | }, 98 | "reactive": { 99 | "description": "If true, this will generate reactive style functions using the Flux class. Defalt: false.", 100 | "required": false, 101 | "default": false 102 | }, 103 | "solaceSpringCloudVersion": { 104 | "description": "The version of the solace-spring-cloud-bom dependency used when generating an application. Alternatively you can set the specification extension info.x-solace-spring-cloud-version.", 105 | "required": false, 106 | "default": "2.1.0" 107 | }, 108 | "springBootVersion": { 109 | "description": "The version of Spring Boot used when generating an application. Alternatively you can set the specification extension info.x-spring-booot-version. Example: 2.2.6.RELEASE.", 110 | "required": false, 111 | "default": "2.4.7" 112 | }, 113 | "springCloudVersion": { 114 | "description": "The version of the spring-cloud-dependencies BOM dependency used when generating an application. Alternatively you can set the specification extension info.x-spring-cloud-version. Example: Hoxton.RELEASE.", 115 | "required": false, 116 | "default": "2020.0.3" 117 | }, 118 | "springCloudStreamVersion": { 119 | "description": "The version of the spring-cloud-stream dependency specified in the Maven file, when generating a library. When generating an application, the spring-cloud-dependencies BOM is used instead. Example: 3.0.1.RELEASE", 120 | "required": false, 121 | "default": "3.1.3" 122 | }, 123 | "username": { 124 | "description": "The client username connection property. Currently this only works with the Solace binder", 125 | "required": false, 126 | "default": "default" 127 | }, 128 | "view": { 129 | "description": "The view that the template uses. By default it is the client view, which means that when the document says publish, we subscribe. In the case of the provider view, when the document says publish, we publish. Values are client or provider. The default is client.", 130 | "required": false, 131 | "default": "client" 132 | }, 133 | "useServers": { 134 | "description": "This option works when binder is kafka. By default it is set to false. When set to true, it will concatenate all the urls in the servers section as a list of brokers for kafka.", 135 | "required": false 136 | } 137 | }, 138 | "filters": [ 139 | "@asyncapi/generator-filters" 140 | ] 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /partials/all-args-constructor: -------------------------------------------------------------------------------- 1 | {%- macro allArgsConstructor(className, properties, indentLevel) -%} 2 | {% set indent1 = indentLevel | indent1 -%} 3 | {% set indent2 = indentLevel | indent2 -%} 4 | {% set indent3 = indentLevel | indent3 -%} 5 | {% set first = true -%} 6 | {%- set hasNoProperties = properties | isEmpty -%} 7 | {%- if not hasNoProperties -%} 8 | {{ indent2 }}public {{ className }} ( 9 | {%- for name, prop in properties -%} 10 | {%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %} 11 | {%- set realClassName = propModelClass.getClassName() %} 12 | {%- set variableName = realClassName | identifierName %} 13 | {%- set typeInfo = [name, realClassName, prop] | fixType %} 14 | {%- set type = typeInfo[0] -%} 15 | {%- if first -%} 16 | {%- set first = false -%} 17 | {%- else -%} 18 | , {% endif %} 19 | {{ indent3 }}{{ type }} {{ variableName }} 20 | {%- endfor -%} 21 | ) { 22 | {% for name, prop in properties -%} 23 | {%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %} 24 | {%- set realClassName = propModelClass.getClassName() %} 25 | {%- set variableName = realClassName | identifierName -%} 26 | {{ indent3 }}this.{{ variableName }} = {{ variableName }}; 27 | {% endfor -%} 28 | {{ indent2 }}} 29 | {%- endif -%} 30 | {% endmacro %} -------------------------------------------------------------------------------- /partials/java-class: -------------------------------------------------------------------------------- 1 | {% from "partials/all-args-constructor" import allArgsConstructor -%} 2 | {%- macro javaClass(schemaName, schema, properties, indentLevel, isStatic) %} 3 | {%- set modelClass = {schema: schema, schemaName: schemaName} | getModelClass %} 4 | {%- set schemaForRef = schemaName | getAnonymousSchemaForRef %} 5 | {% if schemaForRef %} 6 | {% set schema = schemaForRef %} 7 | {% set properties = schemaForRef.properties() %} 8 | {% endif %} 9 | {%- if modelClass %} 10 | {%- set className = modelClass.getClassName() %} 11 | {{ 'javaClass' | logJavaClass -}} 12 | {{ className | logJavaClass -}} 13 | {% set indent1 = indentLevel | indent1 -%} 14 | {% set indent2 = indentLevel | indent2 -%} 15 | {% set indent3 = indentLevel | indent3 -%} 16 | {{ indent1 }}@JsonInclude(JsonInclude.Include.NON_NULL) 17 | {{ indent1 }}public {% if isStatic %}static {% endif %}class {{ className }} 18 | {%- if modelClass.isSubClass() %} extends {{ modelClass.getSuperClassName() }}{% endif %} { 19 | {# Default constructor #} 20 | {{ indent2 }}public {{ className }} () { 21 | {{ indent2 }}} 22 | {# If the top level object is an array, we need to deal with that specially. -#} 23 | {%- if schema and schema.type() === 'array' -%} 24 | {{ allArgsConstructor(className, schema.items().properties(), indentLevel) }} 25 | {{ javaClass(type, null, schema.items().properties(), indentLevel+1, true) }} 26 | {%- else -%} {# not an array at the top level. #} 27 | {{ allArgsConstructor(className, properties, indentLevel) }} 28 | {% endif -%} 29 | {# Members #} 30 | {%- for name, prop in properties %} 31 | {%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %} 32 | {%- set realClassName = propModelClass.getClassName() %} 33 | {%- set variableName = realClassName | identifierName -%} 34 | {%- set typeInfo = [realClassName, realClassName, prop] | fixType -%} 35 | {%- set type = typeInfo[0] %} 36 | {% if variableName !== name -%} 37 | {{ indent2 }}@JsonProperty("{{name}}") 38 | {% endif -%} 39 | {{ indent2 }}private {{ type }} {{ variableName }}; 40 | {%- endfor %} 41 | 42 | {#- Getters and Setters #} 43 | {%- for name, prop in properties %} 44 | {%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %} 45 | {%- set realClassName = propModelClass.getClassName() %} 46 | {%- set variableName = realClassName | identifierName -%} 47 | {%- set typeInfo = [name, realClassName, prop] | fixType -%} 48 | {% set type = typeInfo[0] -%} 49 | {% set isArrayOfObjects = typeInfo[1] %} 50 | {{ indent2 }}public {{ type }} get{{- realClassName }}() { 51 | {{ indent3 }}return {{ variableName }}; 52 | {{ indent2 }}} 53 | 54 | {{ indent2 }}public {{ className }} set{{- realClassName }}({{ type }} {{ variableName }}) { 55 | {{ indent3 }}this.{{-variableName }} = {{ variableName }}; 56 | {{ indent3 }}return this; 57 | {{ indent2 }}} 58 | {# Inner classes #} 59 | {%- set innerModelClass = {schema: prop, schemaName: variableName} | getModelClass %} 60 | {%- if prop.type() === 'object' and innerModelClass and innerModelClass.canBeInnerClass() %} 61 | {{ javaClass(variableName, prop, prop.properties(), indentLevel+1, true) }} 62 | {%- endif %} 63 | {%- if isArrayOfObjects and innerModelClass and innerModelClass.canBeInnerClass() %} 64 | {{ javaClass(variableName, prop, prop.items().properties(), indentLevel+1, true) }} 65 | {%- endif %} 66 | {# Enums #} 67 | {%- if prop.enum() %} 68 | {{ indent2 }}public static enum {{ type }} { {{ prop.enum() }} } 69 | {%- endif %} 70 | {%- endfor -%} 71 | 72 | {{ indent2 }}public String toString() { 73 | {{ indent3 }}return "{{ className }} [" 74 | {%- for name, prop in properties %} 75 | {%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %} 76 | {%- set realClassName = propModelClass.getClassName() %} 77 | {%- set variableName = realClassName | identifierName %} 78 | {%- set typeInfo = [realClassName, realClassName, prop] | fixType -%} 79 | {%- set type = typeInfo[0] %} 80 | {{ indent3 }}+ " {{ variableName }}: " + {{ variableName }} 81 | {%- if type === 'Object' -%} 82 | .toString() 83 | {%- endif -%} 84 | {%- endfor %} 85 | {%- if modelClass.isSubClass() %} 86 | {{ indent3 }}+ " super: " + super.toString(){% endif %} 87 | {{ indent3 }}+ " ]"; 88 | {{ indent2 }}} 89 | {{ indent1 }}}{% endif -%} 90 | {%- endmacro -%} -------------------------------------------------------------------------------- /partials/java-package: -------------------------------------------------------------------------------- 1 | {%- set modelClass = {schema: schema, schemaName: schemaName} | getModelClass -%} 2 | {%- if params['javaPackage'] -%} 3 | package {{ params['javaPackage'] }}; 4 | {%- elif asyncapi.info().extensions()['x-java-package'] -%} 5 | package {{ asyncapi.info().extensions()['x-java-package'] }}; 6 | {%- elif modelClass and modelClass.getJavaPackage() -%} 7 | package {{ modelClass.getJavaPackage() }}; 8 | {% endif %} 9 | -------------------------------------------------------------------------------- /template/README.md: -------------------------------------------------------------------------------- 1 | # {{ asyncapi.info().title() }} 2 | 3 | ## Version {{ asyncapi.info().version() }} 4 | 5 | {{ asyncapi.info().description() | safe }} 6 | 7 | -------------------------------------------------------------------------------- /template/pom.app: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | {{ [asyncapi.info(), params] | groupId }} 6 | {{ [asyncapi.info(), params] | artifactId }} 7 | {{ asyncapi.info().version() }} 8 | jar 9 | {{ [asyncapi.info(), params] | artifactId }} 10 | Auto-generated Spring Cloud Stream AsyncAPI application 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | {{ [asyncapi.info(), params] | springBootVersion }} 16 | 17 | 18 | 19 | 20 | {{ [asyncapi.info(), params] | springCloudVersion }} 21 | {%- if params.binder === 'solace' %} 22 | {{ [asyncapi.info(), params] | solaceSpringCloudVersion }} 23 | {%- endif %} 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-dependencies 31 | ${spring-cloud.version} 32 | pom 33 | import 34 | 35 | {%- if params.binder === 'solace' %} 36 | 37 | com.solace.spring.cloud 38 | solace-spring-cloud-bom 39 | ${solace-spring-cloud-bom.version} 40 | pom 41 | import 42 | 43 | {%- endif %} 44 | 45 | 46 | 47 | 48 | {%- if params.binder === 'rabbit' %} 49 | 50 | org.springframework.cloud 51 | spring-cloud-stream-binder-rabbit 52 | 53 | {%- elif params.binder === 'solace' %} 54 | 55 | com.solace.spring.cloud 56 | spring-cloud-starter-stream-solace 57 | 58 | {%- else %} 59 | 60 | org.springframework.cloud 61 | spring-cloud-stream-binder-kafka 62 | 63 | {%- endif %} 64 | {%- if params.actuator === 'true' %} 65 | 66 | org.springframework.boot 67 | spring-boot-starter-web 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-actuator 72 | 73 | 74 | io.micrometer 75 | micrometer-registry-prometheus 76 | 77 | {%- endif %} 78 | 79 | 80 | 81 | 82 | 83 | org.springframework.boot 84 | spring-boot-maven-plugin 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /template/pom.lib: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | {{ [asyncapi.info(), params] | groupId }} 8 | {{ [asyncapi.info(), params] | artifactId }} 9 | {{ asyncapi.info().version() }} 10 | {{ [asyncapi.info(), params] | artifactId }} 11 | jar 12 | 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 19 | 8 20 | 8 21 | 22 | 23 | 24 | 25 | 26 | 27 | 1.8 28 | {{ [asyncapi.info(), params] | springCloudStreamVersion }} 29 | 30 | 31 | 32 | 33 | org.springframework.cloud 34 | spring-cloud-stream 35 | ${spring-cloud-stream.version} 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /template/src/main/java/$$everySchema$$.java: -------------------------------------------------------------------------------- 1 | {% include 'partials/java-package' -%} 2 | {% set extraIncludes = [schemaName, schema] | schemaExtraIncludes %} 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | {% if extraIncludes.needJsonPropertyInclude -%} 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | {% endif %} 7 | {% from "partials/java-class" import javaClass -%} 8 | {{ javaClass(schemaName, schema, schema.properties(), 0, false) }} 9 | -------------------------------------------------------------------------------- /template/src/main/java/Application.java: -------------------------------------------------------------------------------- 1 | {%- include 'partials/java-package' -%} 2 | {%- set extraIncludes = [asyncapi, params] | appExtraIncludes %} 3 | {%- set funcs = [asyncapi, params] | functionSpecs %} 4 | {%- set imports = [asyncapi, params] | extraImports %} 5 | 6 | {%- if extraIncludes.needFunction %} 7 | import java.util.function.Function; 8 | {%- endif -%} 9 | {%- if extraIncludes.needConsumer %} 10 | import java.util.function.Consumer; 11 | {%- endif -%} 12 | {%- if extraIncludes.needSupplier %} 13 | import java.util.function.Supplier; 14 | {%- endif %} 15 | 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | {%- if extraIncludes.dynamic and params.dynamicType === 'streamBridge' %} 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | {%- endif %} 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | {%- if extraIncludes.dynamic %} 24 | {%- if params.dynamicType === 'streamBridge' %} 25 | import org.springframework.cloud.stream.function.StreamBridge; 26 | {%- else %} 27 | import org.springframework.cloud.stream.binder.BinderHeaders; 28 | {%- endif %} 29 | {%- endif %} 30 | {%- if extraIncludes.needBean %} 31 | import org.springframework.context.annotation.Bean; 32 | {%- endif %} 33 | {%- if extraIncludes.needMessage %} 34 | import org.springframework.messaging.Message; 35 | {%- endif %} 36 | {%- if extraIncludes.dynamic %} 37 | import org.springframework.messaging.support.MessageBuilder; 38 | {%- endif %} 39 | {%- if params.reactive === 'true' %} 40 | import reactor.core.publisher.Flux; 41 | {%- endif %} 42 | {%- for extraImport in imports %} 43 | import {{ extraImport }}; 44 | {%- endfor %} 45 | {% set className = [asyncapi.info(), params] | mainClassName %} 46 | @SpringBootApplication 47 | public class {{ className }} { 48 | 49 | private static final Logger logger = LoggerFactory.getLogger({{ className }}.class); 50 | {%- if extraIncludes.dynamic and params.dynamicType === 'streamBridge' %} 51 | 52 | @Autowired 53 | private StreamBridge streamBridge; 54 | {%- endif %} 55 | 56 | public static void main(String[] args) { 57 | SpringApplication.run({{ className }}.class); 58 | } 59 | {% for funcName, funcSpec in funcs %} 60 | {%- if funcSpec.type === 'function' %} 61 | {%- if funcSpec.dynamic %} 62 | {%- if params.dynamicType === 'header' %} 63 | @Bean 64 | {{ funcSpec.functionSignature | safe }} { 65 | return data -> { 66 | // Add business logic here. 67 | logger.info(data.toString()); 68 | {% for param in funcSpec.channelInfo.parameters -%} 69 | {{ param.type }} {{ param.name }} = {{ param.sampleArg | safe }}; 70 | {% endfor -%} 71 | String topic = String.format("{{ funcSpec.channelInfo.publishChannel }}", 72 | {{ funcSpec.channelInfo.functionArgList }}); 73 | {{ funcSpec.publishPayload | safe }} payload = new {{ funcSpec.publishPayload | safe }}(); 74 | Message message = MessageBuilder 75 | .withPayload(payload) 76 | .setHeader(BinderHeaders.TARGET_DESTINATION, topic) 77 | .build(); 78 | 79 | return message; 80 | }; 81 | } 82 | {%- else %}{# streamBridge, we need a consumer to call our func. #} 83 | // This is a consumer that calls a send method, instead of a function, because it has a dynamic channel and we need streamBridge. 84 | @Bean 85 | {{ funcSpec.functionSignature | safe }} { 86 | return data -> { 87 | // Add business logic here. 88 | logger.info(data.toString()); 89 | {% for param in funcSpec.channelInfo.parameters -%} 90 | {{ param.type }} {{ param.name }} = {{ param.sampleArg | safe }}; 91 | {% endfor -%} 92 | {{ funcSpec.publishPayload | safe }} payload = new {{ funcSpec.publishPayload | safe }}(); 93 | {{ funcSpec.sendMethodName }}(payload, {{ funcSpec.channelInfo.functionArgList }}); 94 | }; 95 | } 96 | {%- endif %} 97 | {%- else %} 98 | @Bean 99 | {{ funcSpec.functionSignature | safe }} { 100 | return data -> { 101 | // Add business logic here. 102 | logger.info(data.toString()); 103 | return new {{ funcSpec.publishPayload | safe }}(); 104 | }; 105 | } 106 | {%- endif %} 107 | {%- elif funcSpec.type === 'consumer' %} 108 | {%- if funcSpec.multipleMessageComment %} 109 | {{ funcSpec.multipleMessageComment }} 110 | {%- endif %} 111 | @Bean 112 | {{ funcSpec.functionSignature | safe }} { 113 | return data -> { 114 | // Add business logic here. 115 | logger.info(data.toString()); 116 | }; 117 | } 118 | {%- else %}{#- it is a supplier. #} 119 | {%- if funcSpec.dynamic %} 120 | {%- if params.dynamicType === 'header' -%} 121 | @Bean 122 | {{ funcSpec.functionSignature | safe }} { 123 | return () -> { 124 | // Add business logic here. 125 | {{ funcSpec.publishPayload | safe }} payload = new {{ funcSpec.publishPayload | safe }}(); 126 | {% for param in funcSpec.channelInfo.parameters -%} 127 | {{ param.type }} {{ param.name }} = {{ param.sampleArg | safe }}; 128 | {% endfor -%} 129 | String topic = String.format("{{ funcSpec.channelInfo.publishChannel }}", 130 | {{ funcSpec.channelInfo.functionArgList }}); 131 | Message message = MessageBuilder 132 | .withPayload(payload) 133 | .setHeader(BinderHeaders.TARGET_DESTINATION, topic) 134 | .build(); 135 | 136 | return message; 137 | }; 138 | } 139 | {# else do nothing, we just use the void function below. #} 140 | {%- endif %}{# dynamic type #} 141 | {%- else -%}{# it is not dynamic. #} 142 | {%- if funcSpec.multipleMessageComment %} 143 | {{ funcSpec.multipleMessageComment }} 144 | {%- endif %} 145 | @Bean 146 | {{ funcSpec.functionSignature | safe }} { 147 | return () -> { 148 | // Add business logic here. 149 | return new {{ funcSpec.publishPayload | safe }}(); 150 | }; 151 | } 152 | {%- endif %}{# dynamic #} 153 | {%- endif %}{# supplier #} 154 | {% endfor %} 155 | {%- set dynamicFuncs = [asyncapi, params] | getDynamicFunctions -%} 156 | {%- if dynamicFuncs.size %} 157 | {%- for sendMethodName, dynFuncSpec in dynamicFuncs %} 158 | {%- if funcSpec.type === 'supplier' or params.dynamicType === 'streamBridge' %} 159 | public void {{ sendMethodName }}( 160 | {{ dynFuncSpec.payloadClass }} payload, {{ dynFuncSpec.channelInfo.functionParamList }} 161 | ) { 162 | String topic = String.format("{{ dynFuncSpec.channelInfo.publishChannel }}", 163 | {{ dynFuncSpec.channelInfo.functionArgList }}); 164 | {%- if params.dynamicType === 'header' -%} 165 | Message message = MessageBuilder 166 | .withPayload(payload) 167 | .setHeader(BinderHeaders.TARGET_DESTINATION, topic) 168 | .build(); 169 | streamBridge.send(topic, message); 170 | {%- else %} 171 | streamBridge.send(topic, payload); 172 | {%- endif %} 173 | } 174 | {%- endif %} 175 | {%- endfor %} 176 | {%- endif %} 177 | } 178 | -------------------------------------------------------------------------------- /template/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | {{ [asyncapi, params] | appProperties | safe }} 2 | -------------------------------------------------------------------------------- /test/integration.test.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const Generator = require('@asyncapi/generator'); 3 | const { readFile } = require('fs').promises; 4 | const crypto = require('crypto'); 5 | 6 | const TEST_SUITE_NAME = 'template integration tests using the generator'; 7 | // Constants not overridden per test 8 | const TEST_FOLDER_NAME = 'test'; 9 | const MAIN_TEST_RESULT_PATH = path.join(TEST_FOLDER_NAME, 'temp', 'integrationTestResult'); 10 | 11 | // Unfortunately, the test suite name must be a hard coded string 12 | describe('template integration tests using the generator', () => { 13 | jest.setTimeout(30000); 14 | 15 | // Constants that may be overridden per test 16 | const DEFAULT_PACKAGE = 'com.acme'; 17 | const DEFAULT_PACKAGE_PATH = path.join(...DEFAULT_PACKAGE.split('.')); 18 | 19 | let outputDirectory; 20 | 21 | const generateFolderName = () => { 22 | // we always want to generate to new directory to make sure test runs in clear environment 23 | const testName = expect.getState().currentTestName.substring(TEST_SUITE_NAME.length + 1); 24 | return path.resolve(MAIN_TEST_RESULT_PATH, `${testName } - ${ crypto.randomBytes(4).toString('hex')}`); 25 | }; 26 | 27 | const generate = (asyncApiFilePath, params) => { 28 | const generator = new Generator(path.normalize('./'), outputDirectory, { forceWrite: true, templateParams: params }); 29 | return generator.generateFromFile(path.resolve(TEST_FOLDER_NAME, asyncApiFilePath)); 30 | }; 31 | 32 | const assertExpectedFiles = async (expectedFiles) => { 33 | for (const index in expectedFiles) { 34 | const file = await readFile(path.join(outputDirectory, expectedFiles[index]), 'utf8'); 35 | expect(file).toMatchSnapshot(); 36 | } 37 | }; 38 | 39 | beforeEach(() => { 40 | outputDirectory = generateFolderName(); 41 | }); 42 | 43 | it('should generate application files using the solace binder', async () => { 44 | const params = { 45 | binder: 'solace', 46 | javaPackage: DEFAULT_PACKAGE, 47 | host: 'testVmrUri', 48 | username: 'user', 49 | password: 'test', //NOSONAR 50 | msgVpn: 'vpnName', 51 | artifactId: 'asyncApiFileName' 52 | }; 53 | 54 | await generate('mocks/solace-test-app.yaml', params); 55 | 56 | const validatedFiles = [ 57 | 'pom.xml', 58 | 'README.md', 59 | `src/main/java/${DEFAULT_PACKAGE_PATH}/Application.java`, 60 | `src/main/java/${DEFAULT_PACKAGE_PATH}/MySchema.java`, 61 | 'src/main/resources/application.yml' 62 | ]; 63 | await assertExpectedFiles(validatedFiles); 64 | }); 65 | 66 | it('should generate a consumer and return a payload when using x-scs-function-name and dynamic topic binding', async () => { 67 | await generate('mocks/scs-function-name/dynamic-topic-same-function-name.yaml'); 68 | 69 | const validatedFiles = [ 70 | 'src/main/java/Application.java' 71 | ]; 72 | await assertExpectedFiles(validatedFiles); 73 | }); 74 | 75 | it('should generate a function and return a payload when using x-scs-function-name and a static topic', async () => { 76 | await generate('mocks/scs-function-name/animals-same-function-name.yaml'); 77 | 78 | const validatedFiles = [ 79 | 'src/main/java/Application.java' 80 | ]; 81 | await assertExpectedFiles(validatedFiles); 82 | }); 83 | 84 | it('should generate extra config when using the paramatersToHeaders parameter', async () => { 85 | const params = { 86 | binder: 'solace', 87 | javaPackage: DEFAULT_PACKAGE, 88 | host: 'testVmrUri', 89 | username: 'user', 90 | password: 'test', //NOSONAR 91 | msgVpn: 'vpnName', 92 | artifactId: 'asyncApiFileName', 93 | parametersToHeaders: true 94 | }; 95 | 96 | await generate('mocks/solace-test-app.yaml', params); 97 | 98 | const validatedFiles = [ 99 | `src/main/java/${DEFAULT_PACKAGE_PATH}/Application.java`, 100 | 'src/main/resources/application.yml' 101 | ]; 102 | await assertExpectedFiles(validatedFiles); 103 | }); 104 | 105 | it('should generate a comment for a consumer receiving multiple messages', async () => { 106 | await generate('mocks/animals.yaml'); 107 | 108 | const validatedFiles = [ 109 | 'src/main/java/Application.java' 110 | ]; 111 | await assertExpectedFiles(validatedFiles); 112 | }); 113 | 114 | it('avro schemas should appear in a package based on their namespace, if any.', async () => { 115 | // Note that this file has 2 Avro schemas named User, but one has the namespace 'userpublisher.' 116 | const AVRO_PACKAGE_PATH = 'userpublisher'; 117 | const params = { 118 | binder: 'kafka', 119 | javaPackage: DEFAULT_PACKAGE, 120 | artifactId: 'asyncApiFileName' 121 | }; 122 | await generate('mocks/kafka-avro.yaml', params); 123 | 124 | const validatedFiles = [ 125 | `src/main/java/${DEFAULT_PACKAGE_PATH}/User.java`, 126 | `src/main/java/${AVRO_PACKAGE_PATH}/User.java`, 127 | ]; 128 | await assertExpectedFiles(validatedFiles); 129 | }); 130 | 131 | it('should generate a model subclass when it sees an allOf', async () => { 132 | const params = { 133 | javaPackage: DEFAULT_PACKAGE, 134 | artifactId: 'asyncApiFileName' 135 | }; 136 | await generate('mocks/error-reporter.yaml', params); 137 | 138 | const validatedFiles = [ 139 | `src/main/java/${DEFAULT_PACKAGE_PATH}/ExtendedErrorModel.java` 140 | ]; 141 | await assertExpectedFiles(validatedFiles); 142 | }); 143 | 144 | it('should generate schemas with nested arrays', async () => { 145 | await generate('mocks/nested-arrays.yaml'); 146 | 147 | const validatedFiles = [ 148 | 'src/main/java/Application.java', 149 | 'src/main/java/Dossier.java', 150 | 'src/main/java/Debtor.java' 151 | ]; 152 | await assertExpectedFiles(validatedFiles); 153 | }); 154 | 155 | it('should generate code from the smarty lighting streetlights example', async () => { 156 | await generate('mocks/smarty-lighting-streetlights.yaml'); 157 | 158 | const validatedFiles = [ 159 | 'src/main/java/Application.java', 160 | 'src/main/java/DimLightPayload.java', 161 | 'src/main/java/LightMeasuredPayload.java', 162 | 'src/main/java/SentAt.java', 163 | 'src/main/java/TurnOnOffPayload.java', 164 | 'src/main/java/SubObject.java' 165 | ]; 166 | await assertExpectedFiles(validatedFiles); 167 | }); 168 | 169 | it('should package and import schemas in another avro namespace', async () => { 170 | await generate('mocks/avro-schema-namespace.yaml'); 171 | 172 | const validatedFiles = [ 173 | 'src/main/java/Application.java', 174 | 'src/main/java/com/example/api/jobOrder/JobOrder.java', 175 | 'src/main/java/com/example/api/jobAck/JobAcknowledge.java' 176 | ]; 177 | await assertExpectedFiles(validatedFiles); 178 | }); 179 | 180 | it('should return object when avro union type is used specifying many possible types', async () => { 181 | await generate('mocks/avro-union-object.yaml'); 182 | 183 | const validatedFiles = [ 184 | 'src/main/java/com/example/api/jobOrder/JobOrder.java' 185 | ]; 186 | await assertExpectedFiles(validatedFiles); 187 | }); 188 | 189 | it('should place the topic variables in the correct order', async () => { 190 | // For a topic of test/{var1}/{var2}, the listed params in the asyncapi document can be in any order 191 | await generate('mocks/multivariable-topic.yaml'); 192 | 193 | const validatedFiles = [ 194 | 'src/main/java/Application.java' 195 | ]; 196 | await assertExpectedFiles(validatedFiles); 197 | }); 198 | 199 | it('should not populate application yml with functions that are not beans', async () => { 200 | // If the function is a supplier or using a stream bridge, the function isn't a bean and shouldnt be in application.yml 201 | await generate('mocks/multivariable-topic.yaml'); 202 | 203 | const validatedFiles = [ 204 | 'src/main/resources/application.yml' 205 | ]; 206 | await assertExpectedFiles(validatedFiles); 207 | }); 208 | 209 | it('should generate a class for a schema property that is an array of objects', async () => { 210 | // Tests that a schema with the items keyword correctly maps the name of the parent to the content within the items 211 | // and the anonymous schema within items doesnt have a class name derived from it. 212 | await generate('mocks/schema-with-array-of-objects.yaml'); 213 | 214 | const validatedFiles = [ 215 | 'src/main/java/Application.java', 216 | 'src/main/java/ChargeAdjustments.java', 217 | 'src/main/java/RideReceipt.java', 218 | 'src/main/java/TestObject.java' 219 | ]; 220 | await assertExpectedFiles(validatedFiles); 221 | }); 222 | 223 | it('should generate one class for a schema with multiple references to it in the asyncapi document', async () => { 224 | /* 225 | For this test, there's duplicate schemas in the asyncapi document. 226 | Calling allSchemas() yeilds unique results (deduplicated) based on either $id or x-parser-schema-id in that order. 227 | The $id needs to be changed because the generator will write file names and such based on it which will always be faulty for this code generator. 228 | Changing the $id of one schema will change the $id only for the one instance, leaving the duplicates behind with the $id they've always had. 229 | This means if we started with 10 schemas, 5 being duplicates with one other schema (15 total; 10 unique), we would end up with 15 unique and 15 total if we changed the schema's $id. 230 | This test ensures all schemas and their duplicates have their $ids renamed to generate the correct file name among other things. 231 | */ 232 | await generate('mocks/schemas-with-duplicate-$ids.yaml'); 233 | 234 | const validatedFiles = [ 235 | 'src/main/java/Application.java', 236 | 'src/main/java/Driver.java', 237 | 'src/main/java/Passenger.java', 238 | 'src/main/java/PaymentCharged.java', 239 | 'src/main/java/RideUpdated1.java' 240 | ]; 241 | await assertExpectedFiles(validatedFiles); 242 | }); 243 | }); 244 | -------------------------------------------------------------------------------- /test/mocks/animals.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | Dog: 4 | type: object 5 | properties: 6 | name: 7 | type: string 8 | Cat: 9 | type: object 10 | properties: 11 | name: 12 | type: string 13 | messages: 14 | DogMessage: 15 | payload: 16 | $ref: '#/components/schemas/Dog' 17 | CatMessage: 18 | payload: 19 | $ref: '#/components/schemas/Cat' 20 | channels: 21 | 'animals': 22 | publish: 23 | message: 24 | oneOf: 25 | - $ref: '#/components/messages/CatMessage' 26 | - $ref: '#/components/messages/DogMessage' 27 | subscribe: 28 | message: 29 | oneOf: 30 | - $ref: '#/components/messages/CatMessage' 31 | - $ref: '#/components/messages/DogMessage' 32 | asyncapi: 2.3.0 33 | info: 34 | description: Testing oneOf 35 | title: animals 36 | version: 0.0.1 37 | -------------------------------------------------------------------------------- /test/mocks/avro-schema-namespace.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | components: 3 | schemas: {} 4 | messages: 5 | JobOrder: 6 | payload: 7 | name: "JobOrder" 8 | namespace: "com.example.api.jobOrder" 9 | doc: "JobOrder" 10 | type: "record" 11 | fields: 12 | - name: "jobOrderId" 13 | doc: "JobOrderID" 14 | type: "string" 15 | - name: "jobOrderDescription" 16 | doc: "JobOrderDescription" 17 | type: "string" 18 | - name: "jobOrderLongDescription" 19 | doc: "JobOrderLongDescription" 20 | type: "string" 21 | - name: "jobOrderNumber" 22 | doc: "JobOrderNumber" 23 | type: "string" 24 | - name: "isActive" 25 | doc: "IsActive" 26 | type: "boolean" 27 | - name: "status" 28 | doc: "Status" 29 | type: "string" 30 | - name: "statuscode" 31 | doc: "StatusCode" 32 | type: "int" 33 | schemaFormat: "application/vnd.apache.avro+json;version=1.9.0" 34 | contentType: "application/vnd.apache.avro+json" 35 | JobAck: 36 | payload: 37 | name: "JobAcknowledge" 38 | namespace: "com.example.api.jobAck" 39 | doc: "JobAck" 40 | type: "record" 41 | fields: 42 | - name: "jobAckId" 43 | doc: "JobAckID" 44 | type: "string" 45 | schemaFormat: "application/vnd.apache.avro+json;version=1.9.0" 46 | contentType: "application/vnd.apache.avro+json" 47 | servers: 48 | production: 49 | protocol: "kafka" 50 | url: "pkc-ymrq7.us-east-2.aws.confluent.cloud:9092" 51 | channels: 52 | test.jobs.order: 53 | subscribe: 54 | message: 55 | $ref: "#/components/messages/JobOrder" 56 | test.jobs.ack: 57 | publish: 58 | message: 59 | $ref: "#/components/messages/JobAck" 60 | asyncapi: "2.0.0" 61 | info: 62 | x-generated-time: "2022-02-24 01:18 UTC" 63 | description: "" 64 | title: "Job Events" 65 | x-view: "provider" 66 | version: "1" 67 | -------------------------------------------------------------------------------- /test/mocks/avro-union-object.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | components: 3 | schemas: {} 4 | messages: 5 | JobOrder: 6 | payload: 7 | name: "JobOrder" 8 | namespace: "com.example.api.jobOrder" 9 | doc: "JobOrder" 10 | type: "record" 11 | fields: 12 | - name: "jobOrderId" 13 | doc: "JobOrderID" 14 | type: "string" 15 | - name: "jobOrderDescription" 16 | doc: "JobOrderDescription" 17 | type: 18 | - "null" 19 | - "string" 20 | - name: "jobOrderLongDescription" 21 | doc: "JobOrderLongDescription" 22 | type: 23 | - "null" 24 | - "string" 25 | schemaFormat: "application/vnd.apache.avro+json;version=1.9.0" 26 | contentType: "application/vnd.apache.avro+json" 27 | servers: 28 | production: 29 | protocol: "kafka" 30 | url: "xxxxx.us-east-2.aws.confluent.cloud:9092" 31 | channels: 32 | test.jobs.order: 33 | subscribe: 34 | message: 35 | $ref: "#/components/messages/JobOrder" 36 | asyncapi: "2.0.0" 37 | info: 38 | x-generated-time: "2022-02-24 01:18 UTC" 39 | description: "" 40 | title: "Union Types" 41 | x-view: "provider" 42 | version: "1" 43 | -------------------------------------------------------------------------------- /test/mocks/error-reporter.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | ErrorModel: 4 | type: object 5 | required: 6 | - message 7 | - code 8 | properties: 9 | message: 10 | type: string 11 | code: 12 | type: integer 13 | minimum: 100 14 | maximum: 600 15 | ExtendedErrorModel: 16 | allOf: 17 | - $ref: '#/components/schemas/ErrorModel' 18 | - type: object 19 | required: 20 | - rootCause 21 | properties: 22 | rootCause: 23 | type: string 24 | messages: 25 | ErrorMessage: 26 | payload: 27 | $ref: '#/components/schemas/ExtendedErrorModel' 28 | channels: 29 | 'errors': 30 | subscribe: 31 | message: 32 | $ref: '#/components/messages/ErrorMessage' 33 | asyncapi: 2.0.0 34 | info: 35 | description: Testing allOf 36 | title: ErrorReporter 37 | version: 0.0.1 38 | 39 | -------------------------------------------------------------------------------- /test/mocks/kafka-avro.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: '2.0.0' 2 | info: 3 | title: Avro Test 4 | version: '1.0.0' 5 | description: Tests Avro schema generation 6 | channels: 7 | userUpdates: 8 | publish: 9 | bindings: 10 | kafka: 11 | groupId: my-group 12 | message: 13 | schemaFormat: 'application/vnd.apache.avro;version=1.9.0' 14 | payload: 15 | name: User 16 | namespace: userpublisher 17 | type: record 18 | doc: User information 19 | fields: 20 | - name: displayName 21 | type: string 22 | - name: email 23 | type: string 24 | - name: age 25 | type: int 26 | subscribe: 27 | message: 28 | schemaFormat: 'application/vnd.apache.avro;version=1.9.0' 29 | payload: 30 | name: User 31 | type: record 32 | doc: User information 33 | fields: 34 | - name: displayName 35 | type: string 36 | - name: email 37 | type: string 38 | - name: age 39 | type: int 40 | -------------------------------------------------------------------------------- /test/mocks/multivariable-topic.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | RideReceipt: 4 | $schema: 'http://json-schema.org/draft-07/schema#' 5 | type: object 6 | title: This schema is irrelevant 7 | $id: 'http://example.com/root.json' 8 | messages: 9 | Billing Receipt Created: 10 | payload: 11 | $ref: '#/components/schemas/RideReceipt' 12 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 13 | contentType: application/json 14 | channels: 15 | 'acme/billing/receipts/{receipt_id}/created/{version}/regions/{region}/chargify/{ride_id}': 16 | subscribe: 17 | bindings: 18 | solace: 19 | bindingVersion: 0.1.0 20 | destinations: 21 | - destinationType: topic 22 | message: 23 | $ref: '#/components/messages/Billing Receipt Created' 24 | parameters: 25 | version: 26 | schema: 27 | type: string 28 | receipt_id: 29 | schema: 30 | type: string 31 | ride_id: 32 | schema: 33 | type: string 34 | region: 35 | schema: 36 | type: string 37 | enum: 38 | - US 39 | - UK 40 | - CA 41 | - MX 42 | asyncapi: 2.0.0 43 | info: 44 | title: ExpenseReportingIntegrationApplication 45 | version: 0.0.1 46 | -------------------------------------------------------------------------------- /test/mocks/nested-arrays.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.0.0 2 | info: 3 | description: '' 4 | title: IntegrationTask 5 | version: 0.0.1 6 | servers: 7 | production: 8 | url: tcp://service.messaging.solace.cloud:55555 9 | protocol: SMF 10 | description: Company Production Broker 11 | variables: 12 | port: 13 | description: Secure connection (TLS) is available through port 55443. Non SSL Compressed protocol is available through port 55003 14 | default: '55555' 15 | enum: 16 | - '55555' 17 | - '55443' 18 | - '55003' 19 | components: 20 | schemas: 21 | Debtor: 22 | description: Debtor 23 | type: object 24 | properties: 25 | emails: 26 | type: array 27 | items: 28 | type: object 29 | properties: 30 | type: 31 | type: string 32 | email: 33 | format: email 34 | type: string 35 | preferred: 36 | type: boolean 37 | birthdate: 38 | type: string 39 | address: 40 | type: object 41 | properties: 42 | country_code: 43 | minLength: 2 44 | type: string 45 | maxLength: 2 46 | city: 47 | type: string 48 | street: 49 | type: string 50 | postal_code: 51 | type: string 52 | last_name: 53 | type: string 54 | phones: 55 | type: array 56 | items: 57 | type: object 58 | properties: 59 | phone: 60 | type: string 61 | type: 62 | type: string 63 | preferred: 64 | type: boolean 65 | id: 66 | type: string 67 | first_name: 68 | type: string 69 | bank_account: 70 | type: object 71 | properties: 72 | IBAN: 73 | pattern: '[A-Z]{2}\d{2} ?\d{4} ?\d{4} ?\d{4} ?\d{4} ?[\d]{0,2}' 74 | type: string 75 | BIC: 76 | type: string 77 | Dossier: 78 | description: Contract info 79 | type: object 80 | properties: 81 | premium: 82 | type: number 83 | applied_discount: 84 | type: number 85 | product_id: 86 | type: string 87 | options: 88 | type: array 89 | items: 90 | type: object 91 | properties: 92 | name: 93 | type: string 94 | id: 95 | type: string 96 | id: 97 | type: string 98 | client_id: 99 | type: string 100 | messages: 101 | CreateDebtorCommand: 102 | payload: 103 | $ref: '#/components/schemas/Debtor' 104 | description: |- 105 | This event contains information about the debtor creation; 106 | DebtorId is expected to be null 107 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 108 | contentType: application/json 109 | DebtorCreatedEvent: 110 | payload: 111 | $ref: '#/components/schemas/Debtor' 112 | description: |- 113 | The event that notify of debtor creation. 114 | the debtorId is the only information filled in this event 115 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 116 | contentType: application/json 117 | CreateDossierCommand: 118 | payload: 119 | $ref: '#/components/schemas/Dossier' 120 | description: |- 121 | This event contains the informaiton about a dossier creation. 122 | The dossier ID is expected to be empty as it's a creation. 123 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 124 | contentType: application/json 125 | DossierCreatedEvent: 126 | payload: 127 | $ref: '#/components/schemas/Dossier' 128 | description: |- 129 | The dossier has been created. 130 | The event contains only the Dossier ID 131 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 132 | contentType: application/json 133 | channels: 134 | 'Company/{customerCompany}/debtor/{debtorId}/Dossier/{dossierId}/created': 135 | publish: 136 | message: 137 | $ref: '#/components/messages/DossierCreatedEvent' 138 | parameters: 139 | customerCompany: 140 | schema: 141 | type: string 142 | dossierId: 143 | schema: 144 | type: string 145 | debtorId: 146 | schema: 147 | type: string 148 | 'Company/{customerCompany}/debtor/{debtorId}/created': 149 | publish: 150 | message: 151 | $ref: '#/components/messages/DebtorCreatedEvent' 152 | parameters: 153 | customerCompany: 154 | schema: 155 | type: string 156 | debtorId: 157 | schema: 158 | type: string 159 | 'Company/{customerCompany}/debtor/create': 160 | subscribe: 161 | message: 162 | $ref: '#/components/messages/CreateDebtorCommand' 163 | parameters: 164 | customerCompany: 165 | schema: 166 | type: string 167 | 'Company/{customerCompany}/debtor/{debtorId}/Dossier/create': 168 | subscribe: 169 | message: 170 | $ref: '#/components/messages/CreateDossierCommand' 171 | parameters: 172 | customerCompany: 173 | schema: 174 | type: string 175 | debtorId: 176 | schema: 177 | type: string -------------------------------------------------------------------------------- /test/mocks/schema-with-array-of-objects.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | RideReceipt: 4 | $schema: 'http://json-schema.org/draft-07/schema#' 5 | type: object 6 | title: The Root Schema 7 | definitions: {} 8 | required: 9 | - request_id 10 | - subtotal 11 | - total_charged 12 | - total_owed 13 | - total_fare 14 | - currency_code 15 | - charge_adjustments 16 | - duration 17 | - distance 18 | - distance_label 19 | properties: 20 | total_owed: 21 | default: '' 22 | examples: 23 | - $12.78 24 | type: string 25 | title: The Total_owed Schema 26 | $id: '#/properties/total_owed' 27 | duration: 28 | default: '' 29 | examples: 30 | - '00:11:35' 31 | pattern: ^(.*)$ 32 | type: string 33 | title: The Duration Schema 34 | $id: '#/properties/duration' 35 | test_object: 36 | title: The test schema 37 | $id: '#/properties/test_object' 38 | type: object 39 | properties: 40 | field1: 41 | default: '' 42 | examples: 43 | - $12.78 44 | type: string 45 | title: field1 schema 46 | $id: '#/properties/test_object/properties/field1' 47 | charge_adjustments: 48 | default: [] 49 | examples: 50 | - - amount: '-2.43' 51 | name: Promotion 52 | type: promotion 53 | - amount: '1.00' 54 | name: Booking Fee 55 | type: booking_fee 56 | - amount: '0.78' 57 | name: Rounding Down 58 | type: rounding_down 59 | additionalItems: true 60 | description: An explanation about the purpose of this instance. 61 | type: array 62 | title: The Charge_adjustments Schema 63 | items: 64 | default: {} 65 | examples: 66 | - amount: '-2.43' 67 | name: Promotion 68 | type: promotion 69 | - amount: '1.00' 70 | name: Booking Fee 71 | type: booking_fee 72 | - amount: '0.78' 73 | name: Rounding Down 74 | type: rounding_down 75 | description: An explanation about the purpose of this instance. 76 | type: object 77 | title: The Items Schema 78 | required: 79 | - name 80 | - amount 81 | - type 82 | properties: 83 | amount: 84 | default: '' 85 | examples: 86 | - '-2.43' 87 | description: An explanation about the purpose of this instance. 88 | type: string 89 | title: The Amount Schema 90 | $id: '#/properties/charge_adjustments/items/properties/amount' 91 | name: 92 | default: '' 93 | examples: 94 | - Promotion 95 | description: An explanation about the purpose of this instance. 96 | type: string 97 | title: The Name Schema 98 | $id: '#/properties/charge_adjustments/items/properties/name' 99 | type: 100 | default: '' 101 | examples: 102 | - promotion 103 | description: An explanation about the purpose of this instance. 104 | type: string 105 | title: The Type Schema 106 | $id: '#/properties/charge_adjustments/items/properties/type' 107 | $id: '#/properties/charge_adjustments/items' 108 | $id: '#/properties/charge_adjustments' 109 | currency_code: 110 | default: '' 111 | examples: 112 | - USD 113 | pattern: ^(.*)$ 114 | type: string 115 | title: The Currency_code Schema 116 | $id: '#/properties/currency_code' 117 | $id: 'http://example.com/root.json' 118 | messages: 119 | Billing Receipt Created: 120 | payload: 121 | $ref: '#/components/schemas/RideReceipt' 122 | description: >- 123 | This event is generated when a trip is completed and the credit charge 124 | has occurred. 125 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 126 | contentType: application/json 127 | channels: 128 | 'acme/rideshare/billing/receipt/created/0.0.1/{region}/chargify/{ride_id}': 129 | subscribe: 130 | bindings: 131 | solace: 132 | bindingVersion: 0.1.0 133 | destinations: 134 | - destinationType: topic 135 | message: 136 | $ref: '#/components/messages/Billing Receipt Created' 137 | parameters: 138 | ride_id: 139 | schema: 140 | type: string 141 | region: 142 | schema: 143 | type: string 144 | enum: 145 | - US 146 | - UK 147 | - CA 148 | - MX 149 | asyncapi: 2.0.0 150 | info: 151 | description: >- 152 | Simplify expense, travel, and invoice management with SAP Concur partner 153 | integrations 154 | 155 | 156 | Our open platform makes it possible for partners to develop apps and 157 | services that easily integrate with SAP Concur solutions and extend the 158 | value of our products. With our partner apps you can: 159 | 160 | 161 | * Use data to make more-informed business decisions 162 | 163 | * Reduce costs, improve compliance, and increase efficiency 164 | 165 | * Give employees a better, smoother travel experience 166 | title: ExpenseReportingIntegrationApplication 167 | version: 0.0.1 168 | -------------------------------------------------------------------------------- /test/mocks/scs-function-name/animals-same-function-name.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | Dog: 4 | type: object 5 | properties: 6 | name: 7 | type: string 8 | Cat: 9 | type: object 10 | properties: 11 | name: 12 | type: string 13 | messages: 14 | DogMessage: 15 | payload: 16 | $ref: '#/components/schemas/Dog' 17 | CatMessage: 18 | payload: 19 | $ref: '#/components/schemas/Cat' 20 | channels: 21 | 'animals': 22 | publish: 23 | x-scs-function-name: sameFunctionName 24 | message: 25 | oneOf: 26 | - $ref: '#/components/messages/CatMessage' 27 | - $ref: '#/components/messages/DogMessage' 28 | subscribe: 29 | x-scs-function-name: sameFunctionName 30 | message: 31 | oneOf: 32 | - $ref: '#/components/messages/CatMessage' 33 | - $ref: '#/components/messages/DogMessage' 34 | asyncapi: 2.0.0 35 | info: 36 | description: Testing oneOf 37 | title: animals 38 | version: 0.0.1 39 | -------------------------------------------------------------------------------- /test/mocks/scs-function-name/dynamic-topic-same-function-name.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | mySchema: 4 | title: MySchema 5 | type: object 6 | properties: 7 | prop1: 8 | default: default string 9 | title: PropertyTitle 10 | type: string 11 | myOtherSchema: 12 | title: MyOtherSchema 13 | type: object 14 | properties: 15 | prop1: 16 | default: default string 17 | title: PropertyTitle 18 | type: string 19 | messages: 20 | myEvent: 21 | payload: 22 | $ref: '#/components/schemas/mySchema' 23 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 24 | contentType: application/json 25 | myOtherEvent: 26 | payload: 27 | $ref: '#/components/schemas/myOtherSchema' 28 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 29 | contentType: application/json 30 | channels: 31 | 'testLevel1/{messageId}/{operation}': 32 | subscribe: 33 | x-scs-function-name: sameFunctionName 34 | message: 35 | $ref: '#/components/messages/myOtherEvent' 36 | publish: 37 | x-scs-function-name: sameFunctionName 38 | bindings: 39 | smf: 40 | topicSubscriptions: 41 | - testLevel1/*/* 42 | channelType: clientEndpoint 43 | bindingVersion: 0.1.0 44 | message: 45 | $ref: '#/components/messages/myEvent' 46 | parameters: 47 | messageId: 48 | schema: 49 | type: string 50 | operation: 51 | schema: 52 | type: string 53 | enum: 54 | - POST 55 | - DELETE 56 | asyncapi: 2.0.0 57 | info: 58 | title: solace-test-app 59 | version: 0.0.1 60 | -------------------------------------------------------------------------------- /test/mocks/smarty-lighting-streetlights.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: '2.0.0' 2 | info: 3 | title: Streetlights API 4 | version: '1.0.0' 5 | description: | 6 | The Smartylighting Streetlights API allows you to remotely manage the city lights. 7 | 8 | ### Check out its awesome features: 9 | 10 | * Turn a specific streetlight on/off 🌃 11 | * Dim a specific streetlight 😎 12 | * Receive real-time information about environmental lighting conditions 📈 13 | license: 14 | name: Apache 2.0 15 | url: https://www.apache.org/licenses/LICENSE-2.0 16 | 17 | servers: 18 | production: 19 | url: test.mosquitto.org:{port} 20 | protocol: mqtt 21 | description: Test broker 22 | variables: 23 | port: 24 | description: Secure connection (TLS) is available through port 8883. 25 | default: '1883' 26 | enum: 27 | - '1883' 28 | - '8883' 29 | security: 30 | - apiKey: [] 31 | - supportedOauthFlows: 32 | - streetlights:on 33 | - streetlights:off 34 | - streetlights:dim 35 | - openIdConnectWellKnown: [] 36 | 37 | defaultContentType: application/json 38 | 39 | channels: 40 | smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured: 41 | description: The topic on which measured values may be produced and consumed. 42 | parameters: 43 | streetlightId: 44 | $ref: '#/components/parameters/streetlightId' 45 | publish: 46 | summary: Inform about environmental lighting conditions of a particular streetlight. 47 | operationId: receiveLightMeasurement 48 | traits: 49 | - $ref: '#/components/operationTraits/kafka' 50 | message: 51 | $ref: '#/components/messages/lightMeasured' 52 | 53 | smartylighting/streetlights/1/0/action/{streetlightId}/turn/on: 54 | parameters: 55 | streetlightId: 56 | $ref: '#/components/parameters/streetlightId' 57 | subscribe: 58 | operationId: turnOn 59 | traits: 60 | - $ref: '#/components/operationTraits/kafka' 61 | message: 62 | $ref: '#/components/messages/turnOnOff' 63 | 64 | smartylighting/streetlights/1/0/action/{streetlightId}/turn/off: 65 | parameters: 66 | streetlightId: 67 | $ref: '#/components/parameters/streetlightId' 68 | subscribe: 69 | operationId: turnOff 70 | traits: 71 | - $ref: '#/components/operationTraits/kafka' 72 | message: 73 | $ref: '#/components/messages/turnOnOff' 74 | 75 | smartylighting/streetlights/1/0/action/{streetlightId}/dim: 76 | parameters: 77 | streetlightId: 78 | $ref: '#/components/parameters/streetlightId' 79 | subscribe: 80 | operationId: dimLight 81 | traits: 82 | - $ref: '#/components/operationTraits/kafka' 83 | message: 84 | $ref: '#/components/messages/dimLight' 85 | 86 | components: 87 | messages: 88 | lightMeasured: 89 | name: lightMeasured 90 | title: Light measured 91 | summary: Inform about environmental lighting conditions of a particular streetlight. 92 | contentType: application/json 93 | traits: 94 | - $ref: '#/components/messageTraits/commonHeaders' 95 | payload: 96 | $ref: "#/components/schemas/lightMeasuredPayload" 97 | turnOnOff: 98 | name: turnOnOff 99 | title: Turn on/off 100 | summary: Command a particular streetlight to turn the lights on or off. 101 | traits: 102 | - $ref: '#/components/messageTraits/commonHeaders' 103 | payload: 104 | $ref: "#/components/schemas/turnOnOffPayload" 105 | dimLight: 106 | name: dimLight 107 | title: Dim light 108 | summary: Command a particular streetlight to dim the lights. 109 | traits: 110 | - $ref: '#/components/messageTraits/commonHeaders' 111 | payload: 112 | $ref: "#/components/schemas/dimLightPayload" 113 | 114 | schemas: 115 | lightMeasuredPayload: 116 | type: object 117 | properties: 118 | lumens: 119 | type: integer 120 | minimum: 0 121 | description: Light intensity measured in lumens. 122 | sentAt: 123 | $ref: "#/components/schemas/sentAt" 124 | turnOnOffPayload: 125 | type: object 126 | properties: 127 | command: 128 | type: string 129 | enum: 130 | - on 131 | - off 132 | description: Whether to turn on or off the light. 133 | sentAt: 134 | $ref: "#/components/schemas/sentAt" 135 | dimLightPayload: 136 | type: object 137 | properties: 138 | percentage: 139 | type: integer 140 | description: Percentage to which the light should be dimmed to. 141 | minimum: 0 142 | maximum: 100 143 | sentAt: 144 | $ref: "#/components/schemas/sentAt" 145 | sentAt: 146 | type: object 147 | properties: 148 | propertySubobject: 149 | $ref: "#/components/schemas/subObject" 150 | subObject: 151 | type: object 152 | properties: 153 | propertyA: 154 | type: string 155 | 156 | 157 | securitySchemes: 158 | apiKey: 159 | type: apiKey 160 | in: user 161 | description: Provide your API key as the user and leave the password empty. 162 | supportedOauthFlows: 163 | type: oauth2 164 | description: Flows to support OAuth 2.0 165 | flows: 166 | implicit: 167 | authorizationUrl: 'https://authserver.example/auth' 168 | scopes: 169 | 'streetlights:on': Ability to switch lights on 170 | 'streetlights:off': Ability to switch lights off 171 | 'streetlights:dim': Ability to dim the lights 172 | password: 173 | tokenUrl: 'https://authserver.example/token' 174 | scopes: 175 | 'streetlights:on': Ability to switch lights on 176 | 'streetlights:off': Ability to switch lights off 177 | 'streetlights:dim': Ability to dim the lights 178 | clientCredentials: 179 | tokenUrl: 'https://authserver.example/token' 180 | scopes: 181 | 'streetlights:on': Ability to switch lights on 182 | 'streetlights:off': Ability to switch lights off 183 | 'streetlights:dim': Ability to dim the lights 184 | authorizationCode: 185 | authorizationUrl: 'https://authserver.example/auth' 186 | tokenUrl: 'https://authserver.example/token' 187 | refreshUrl: 'https://authserver.example/refresh' 188 | scopes: 189 | 'streetlights:on': Ability to switch lights on 190 | 'streetlights:off': Ability to switch lights off 191 | 'streetlights:dim': Ability to dim the lights 192 | openIdConnectWellKnown: 193 | type: openIdConnect 194 | openIdConnectUrl: 'https://authserver.example/.well-known' 195 | 196 | parameters: 197 | streetlightId: 198 | description: The ID of the streetlight. 199 | schema: 200 | type: string 201 | 202 | messageTraits: 203 | commonHeaders: 204 | headers: 205 | type: object 206 | properties: 207 | my-app-header: 208 | type: integer 209 | minimum: 0 210 | maximum: 100 211 | 212 | operationTraits: 213 | kafka: 214 | bindings: 215 | kafka: 216 | clientId: my-app-id 217 | -------------------------------------------------------------------------------- /test/mocks/solace-test-app.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | mySchema: 4 | title: MySchema 5 | type: object 6 | properties: 7 | prop1: 8 | type: string 9 | long: 10 | description: The name of this property is a Java reserved word. 11 | type: string 12 | messages: 13 | myEvent: 14 | payload: 15 | $ref: '#/components/schemas/mySchema' 16 | schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 17 | contentType: application/json 18 | channels: 19 | 'testLevel1/{messageId}/{operation}': 20 | subscribe: 21 | message: 22 | $ref: '#/components/messages/myEvent' 23 | publish: 24 | bindings: 25 | smf: 26 | topicSubscriptions: 27 | - testLevel1/*/* 28 | channelType: clientEndpoint 29 | bindingVersion: 0.1.0 30 | message: 31 | $ref: '#/components/messages/myEvent' 32 | parameters: 33 | messageId: 34 | schema: 35 | type: string 36 | operation: 37 | schema: 38 | type: string 39 | enum: 40 | - POST 41 | - DELETE 42 | asyncapi: 2.3.0 43 | info: 44 | title: solace-test-app 45 | version: 0.0.1 46 | --------------------------------------------------------------------------------