JSPM

swagger-orm

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q10110F
  • License MIT

Swagger-ORM is a runtime-driven, object-oriented mapping tool for describing routes and routers without the need for a separate JSON configuration, streamlining the process during startup.

Package Exports

  • swagger-orm
  • swagger-orm/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (swagger-orm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

swagger-orm

Swagger-ORM is a runtime-driven, object-oriented mapping tool for describing routes and routers without the need for a separate JSON configuration, streamlining the process during startup.

The available functionalities are limited, and if you wish to incorporate additional features, you have the option to implement them yourself or submit an issue for consideration.

definitions

  • describing a server
import { Router } from 'express'
import { serve, setup } from 'swagger-ui-express';
import { Documentation } from 'swagger-orm';

import { path as auth } from 'routes/auth.js';
import { path as users } from 'routes/users/index.js';

const router = Router();

const documentation = new Documentation({
    openapi: '3.0.3',
    info: {
        title: '...',
        description: '...',
        version: '1.0.11'
    },
    servers: [
        {
            url: 'https://auth.domain.tdl'
        }
    ],
    tags: [
        {
            name: 'Authentication'
        }
    ],
    components: {
        securitySchemes: {
            Authorization: {
                type: 'http',
                scheme: 'bearer',
                bearerFormat: 'JWT'
            }
        }
    }
});

router.use('/', serve, setup(
    documentation.compile({
        ...auth,
        ...users
    })
));

export default router;

  • describing a router
import { Swagger } from 'swagger-orm';

export const path = Swagger.ToPath('auth', 'domain.tdl', {
  '/sign-in': signIn.define
    
  /*
  '/multiple-http-methods': [
    get.define,
    post.define,
    put.define,
    delete.define
  ]
  */
});

  • describing a route
import { Swagger } from 'swagger-orm';

export const route = ...;

export const define = new Swagger('post', 'auth-sign-up')
  .tags('Authorization', 'Authentication')
  .requestBody({
    username: 'john_doe',
    password: 'my-password',
    email: 'john_doe@domain.tdl'
  })
  .responses([
    new Swagger.Response(200),
    new Swagger.Response(400),
    new Swagger.Response(409, {
      message: 'This username or email is already taken',
      data: {
        // any additional data?
      }
    }),
    new Swagger.Response(500)
  ]);
  // security(); <- only supports header authorization jwt, i dont mind adding more supports just hit me up with an issue