Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial schema generation for team-broker topics #4997

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions forge/ee/routes/teamBroker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const schemaApi = require('./schema')

module.exports = async function (app) {
app.addHook('preHandler', app.verifySession)

Expand Down Expand Up @@ -35,6 +37,8 @@ module.exports = async function (app) {
}
})

await schemaApi(app)

/**
* Get the Teams MQTT Clients
* @name /api/v1/teams/:teamId/broker/clients
Expand Down
42 changes: 42 additions & 0 deletions forge/ee/routes/teamBroker/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const YAML = require('yaml')
module.exports = async function (app) {
app.get('/team-broker/schema.yml', async (request, reply) => {
const list = await app.teamBroker.getUsedTopics(request.team.hashid)
const schema = {
asyncapi: '3.0.0',
info: {
version: '1.0.0',
title: `${request.team.name} Team Broker`,
description: 'An auto-generated schema of the topics being used on the team broker'
}
}
// Add the team-broker details

// Figure out the hostname for the team broker
let teamBrokerHost = app.config.broker?.teamBroker?.host
if (!teamBrokerHost) {
// No explict value set, default to broker.${domain}
if (app.config.domain) {
teamBrokerHost = `broker.${app.config.domain}`
knolleary marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (teamBrokerHost) {
schema.servers = {
'team-broker': {
host: teamBrokerHost,
protocol: 'mqtt'
}
}
}

if (list.length > 0) {
schema.channels = {}
list.forEach(topic => {
schema.channels[topic] = {
address: topic
}
})
}
reply.send(YAML.stringify(schema))
})
}
Loading