Separate swagger into files

Viewed 43

Hi guys i'm works with swagger ui v2, and has a problem with organization.

The current structure of my project is like this.

const swaggerDocument = {
  swagger: "2.0",
  info: {
    version: "1.0.0",
    title: "Hello",
    description: "hello",
  },
  basePath: "/api",
  tags: [
    {
      name: "Users",
      description: "API for users in the system",
    },
  ],
  schemes: [
    "https",
    "http",
  ],
  consumes: [
    "application/json",
  ],
  produces: [
    "application/json",
  ],
  paths: {
    "/users": {
      // ...
    },
  },
  definitions: {
    User: {
      // ...
    },
  },
};

In my path there are several routes (many actually) that reference my definitions, example: " $ref: "#/definitions/Users"," and my swagger.ts file is gigantic, I would like a better solution to organize, I tried something below but it didn't work.

swagger.ts

import { user, userDefinitions } from './user';

const swaggerDocument = {
  paths: {
    "/users": {
       ...user,
    },
  },
  definitions: {
    User: {
       ...userDefinitions,
    },
  },
};

Can someone help me?

User.ts

const user = {
  "/users": {
   ...
  },
};

const userDefinitions = {
  User: {
    properties: {
     ...
    },
  },
};

export { user, userDefinitions };
0 Answers
Related