@platformatic/runtime 0.35.3 → 0.35.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.35.0/runtime",
3
+ "entrypoint": "without-openapi",
4
+ "hotReload": false,
5
+ "services": [
6
+ {
7
+ "id": "without-openapi",
8
+ "path": "../monorepo-openapi/serviceAppWithoutOpenapi",
9
+ "config": "platformatic.service.json"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.20.0/service",
3
+ "server": {
4
+ "hostname": "127.0.0.1",
5
+ "port": 0
6
+ },
7
+ "plugins": {
8
+ "paths": [
9
+ "plugin.js"
10
+ ]
11
+ },
12
+ "watch": false
13
+ }
@@ -0,0 +1,8 @@
1
+ 'use strict'
2
+
3
+ /** @param {import('fastify').FastifyInstance} app */
4
+ module.exports = async function (app) {
5
+ app.get('/', async () => {
6
+ return { hello: 'world' }
7
+ })
8
+ }
package/lib/api-client.js CHANGED
@@ -47,6 +47,10 @@ class RuntimeApiClient extends EventEmitter {
47
47
  return this.#sendCommand('plt:get-service-config', { id })
48
48
  }
49
49
 
50
+ async getServiceOpenapiSchema (id) {
51
+ return this.#sendCommand('plt:get-service-openapi-schema', { id })
52
+ }
53
+
50
54
  async startService (id) {
51
55
  return this.#sendCommand('plt:start-service', { id })
52
56
  }
package/lib/api.js CHANGED
@@ -7,7 +7,6 @@ const { PlatformaticApp } = require('./app')
7
7
  class RuntimeApi {
8
8
  #services
9
9
  #dispatcher
10
- #loaderPort
11
10
 
12
11
  constructor (config, logger, loaderPort) {
13
12
  this.#services = new Map()
@@ -87,6 +86,8 @@ class RuntimeApi {
87
86
  return this.#getServiceDetails(params)
88
87
  case 'plt:get-service-config':
89
88
  return this.#getServiceConfig(params)
89
+ case 'plt:get-service-openapi-schema':
90
+ return this.#getServiceOpenapiSchema(params)
90
91
  case 'plt:start-service':
91
92
  return this.#startService(params)
92
93
  case 'plt:stop-service':
@@ -184,6 +185,25 @@ class RuntimeApi {
184
185
  return config.configManager.current
185
186
  }
186
187
 
188
+ async #getServiceOpenapiSchema ({ id }) {
189
+ const service = this.#getServiceById(id)
190
+
191
+ if (!service.config) {
192
+ throw new Error(`Service with id '${id}' is not started`)
193
+ }
194
+
195
+ if (typeof service.server.swagger !== 'function') {
196
+ throw new Error(`Service with id '${id}' does not expose an OpenAPI schema`)
197
+ }
198
+
199
+ try {
200
+ const openapiSchema = service.server.swagger()
201
+ return openapiSchema
202
+ } catch (err) {
203
+ throw new Error(`Failed to retrieve OpenAPI schema for service with id '${id}': ${err.message}`)
204
+ }
205
+ }
206
+
187
207
  async #startService ({ id }) {
188
208
  const service = this.#getServiceById(id)
189
209
  await service.start()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "0.35.3",
3
+ "version": "0.35.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "standard": "^17.1.0",
25
25
  "tsd": "^0.28.1",
26
26
  "typescript": "^5.1.6",
27
- "@platformatic/sql-graphql": "0.35.3",
28
- "@platformatic/sql-mapper": "0.35.3"
27
+ "@platformatic/sql-graphql": "0.35.5",
28
+ "@platformatic/sql-mapper": "0.35.5"
29
29
  },
30
30
  "dependencies": {
31
31
  "@hapi/topo": "^6.0.2",
@@ -42,12 +42,12 @@
42
42
  "pino": "^8.14.1",
43
43
  "pino-pretty": "^10.0.0",
44
44
  "undici": "^5.22.1",
45
- "@platformatic/composer": "0.35.3",
46
- "@platformatic/config": "0.35.3",
47
- "@platformatic/db": "0.35.3",
48
- "@platformatic/service": "0.35.3",
49
- "@platformatic/telemetry": "0.35.3",
50
- "@platformatic/utils": "0.35.3"
45
+ "@platformatic/composer": "0.35.5",
46
+ "@platformatic/config": "0.35.5",
47
+ "@platformatic/db": "0.35.5",
48
+ "@platformatic/service": "0.35.5",
49
+ "@platformatic/telemetry": "0.35.5",
50
+ "@platformatic/utils": "0.35.5"
51
51
  },
52
52
  "standard": {
53
53
  "ignore": [
package/test/api.test.js CHANGED
@@ -303,3 +303,55 @@ test('should handle a lot of runtime api requests', async (t) => {
303
303
 
304
304
  await Promise.all(promises)
305
305
  })
306
+
307
+ test('should get a service openapi schema', async (t) => {
308
+ const configFile = join(fixturesDir, 'configs', 'monorepo.json')
309
+ const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
310
+ const app = await buildServer(config.configManager.current)
311
+
312
+ await app.start()
313
+
314
+ t.after(async () => {
315
+ await app.close()
316
+ })
317
+
318
+ const openapiSchema = await app.getServiceOpenapiSchema('with-logger')
319
+ assert.deepStrictEqual(openapiSchema, {
320
+ openapi: '3.0.3',
321
+ info: {
322
+ title: 'Platformatic',
323
+ description: 'This is a service built on top of Platformatic',
324
+ version: '1.0.0'
325
+ },
326
+ components: { schemas: {} },
327
+ paths: {
328
+ '/': {
329
+ get: {
330
+ responses: {
331
+ 200: {
332
+ description: 'Default Response'
333
+ }
334
+ }
335
+ }
336
+ }
337
+ }
338
+ })
339
+ })
340
+
341
+ test('should fail to get a service openapi schema if service does not expose it', async (t) => {
342
+ const configFile = join(fixturesDir, 'configs', 'monorepo-openapi.json')
343
+ const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
344
+ const app = await buildServer(config.configManager.current)
345
+
346
+ await app.start()
347
+
348
+ t.after(async () => {
349
+ await app.close()
350
+ })
351
+
352
+ try {
353
+ await app.getServiceOpenapiSchema('without-openapi')
354
+ } catch (err) {
355
+ assert.strictEqual(err.message, 'Service with id \'without-openapi\' does not expose an OpenAPI schema')
356
+ }
357
+ })