OpenAPI server with WebXR client #16

Open
opened 12 months ago by utopiah · 0 comments
Owner

Can rely on 1c8faf91db of text-code-xr-engine in its https://git.benetou.fr/utopiah/text-code-xr-engine/src/branch/swagger_example branch.

For now still in fabien@fabien-CORSAIR-ONE-i160:~/Prototypes/swagger-express-test as :

const express = require('express')
const app = express()
const swaggerJsDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')

const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Offline octopus',
      version: '1.0.0',
    },
  },
  apis: ['./index.js'], // files containing annotations as above
};

/**
 * @openapi
 * /:
 *   get:
 *     description: help to better understand what offline-first octopus allows and the design philosophy behind it.
 *     responses:
 *       200:
 *         description: Documentation
 * /allpeers/exec:
 *   get:
 *     description: exec a known command on all peers found from the last scan
 * /allpeers/result:
 *   get:
 *     description: provide the results of all commands ran on other peers as an array with URL/result
 * /authtest:
 *   get:
 *     description: test authorization as bearer query parameter (still hard coded MD5)
 * /authtestviaheader:
 *   get:
 *     description: test authorization as authorization header (still hard coded MD5)
 * /available:
 *   get:
 *     description: respond true if available
 * /editor/read:
 *   get:
 *     description: return the source of the current editor for modifications
 * /editor/recover:
 *   get:
 *     description: overwrites permanently the current editor but a known working one
 * /editor/save:
 *   get:
 *     description: overwrites permanently the current editor with the one provided
 * /exec:
 *   get:
 *     description: returns the result of the execution of a locally known command
 * /foundpeers:
 *   get:
 *     description: found peers from the last scan
 * /hmdlink:
 *   get:
 *     description: redirect to a known URL
 * /hmdlink/set:
 *   get:
 *     description: set a URL for future redirection
 * /localprototypes:
 *   get:
 *     description: list prototypes on the current machine
 * /pwa:
 *   get:
 *     description: redirect to a PWA interface
 * /recentfiles:
 *   get:
 *     description: will (not implemented yet) list recent modified files in the unified workspace
 * /scan:
 *   get:
 *     description: scan peers on the current network
 * /services:
 *   get:
 *     description: returns local services
 * /services/register:
 *   get:
 *     description: will (not implemented yet) add service to the local services
 * /services/unregister:
 *   get:
 *     description: will (not implemented yet) remove service to the local services
 * /sshconfig:
 *   get:
 *     description: returns the parsed local ssh configuration for all possible machines
 * /sshconfig/live:
 *   get:
 *     description: returns the parsed local ssh configuration for online peers from the last scan
 * /unifiedworkspaces:
 *   get:
 *     description: list files and directory in the unified workspace (getUnifiedworkspaces() must be called first)
 * /updates:
 *   get:
 *     description: will (not implemented yet) update the offtopus software as a peer
 * /webxr:
 *   get:
 *     description: redirects to a WebXR interface
*/
app.get('/', (req, res) => {
  res.send('Hello World from the offline octopus test API!');
});

// Initialize swagger-jsdoc -> returns validated swagger spec in json format
const swaggerSpec = swaggerJsdoc(options);


/**
 * @openapi
 * /api-docs.json:
 *   get:
 *     description: returns the OpenAPI specifications as JSON
*/
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

app.get('/api-docs.json', function(req, res) {
  res.setHeader('Content-Type', 'application/json');
  res.send(swaggerSpec);
});

app.get('/test', (req, res) => {
        res.send('customers')
})

app.listen(12345, () => {
        console.log('listening http 12345')
})



Can rely on https://git.benetou.fr/utopiah/text-code-xr-engine/commit/1c8faf91dba0b89d7ee82be92d421a58a50b316c of `text-code-xr-engine` in its https://git.benetou.fr/utopiah/text-code-xr-engine/src/branch/swagger_example branch. For now still in `fabien@fabien-CORSAIR-ONE-i160:~/Prototypes/swagger-express-test` as : ```javascript const express = require('express') const app = express() const swaggerJsDoc = require('swagger-jsdoc') const swaggerUi = require('swagger-ui-express') const swaggerJsdoc = require('swagger-jsdoc'); const options = { definition: { openapi: '3.0.0', info: { title: 'Offline octopus', version: '1.0.0', }, }, apis: ['./index.js'], // files containing annotations as above }; /** * @openapi * /: * get: * description: help to better understand what offline-first octopus allows and the design philosophy behind it. * responses: * 200: * description: Documentation * /allpeers/exec: * get: * description: exec a known command on all peers found from the last scan * /allpeers/result: * get: * description: provide the results of all commands ran on other peers as an array with URL/result * /authtest: * get: * description: test authorization as bearer query parameter (still hard coded MD5) * /authtestviaheader: * get: * description: test authorization as authorization header (still hard coded MD5) * /available: * get: * description: respond true if available * /editor/read: * get: * description: return the source of the current editor for modifications * /editor/recover: * get: * description: overwrites permanently the current editor but a known working one * /editor/save: * get: * description: overwrites permanently the current editor with the one provided * /exec: * get: * description: returns the result of the execution of a locally known command * /foundpeers: * get: * description: found peers from the last scan * /hmdlink: * get: * description: redirect to a known URL * /hmdlink/set: * get: * description: set a URL for future redirection * /localprototypes: * get: * description: list prototypes on the current machine * /pwa: * get: * description: redirect to a PWA interface * /recentfiles: * get: * description: will (not implemented yet) list recent modified files in the unified workspace * /scan: * get: * description: scan peers on the current network * /services: * get: * description: returns local services * /services/register: * get: * description: will (not implemented yet) add service to the local services * /services/unregister: * get: * description: will (not implemented yet) remove service to the local services * /sshconfig: * get: * description: returns the parsed local ssh configuration for all possible machines * /sshconfig/live: * get: * description: returns the parsed local ssh configuration for online peers from the last scan * /unifiedworkspaces: * get: * description: list files and directory in the unified workspace (getUnifiedworkspaces() must be called first) * /updates: * get: * description: will (not implemented yet) update the offtopus software as a peer * /webxr: * get: * description: redirects to a WebXR interface */ app.get('/', (req, res) => { res.send('Hello World from the offline octopus test API!'); }); // Initialize swagger-jsdoc -> returns validated swagger spec in json format const swaggerSpec = swaggerJsdoc(options); /** * @openapi * /api-docs.json: * get: * description: returns the OpenAPI specifications as JSON */ app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); app.get('/api-docs.json', function(req, res) { res.setHeader('Content-Type', 'application/json'); res.send(swaggerSpec); }); app.get('/test', (req, res) => { res.send('customers') }) app.listen(12345, () => { console.log('listening http 12345') }) ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: utopiah/offline-octopus#16
Loading…
There is no content yet.