🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@swagger-api/apidom-reference

Package Overview
Dependencies
Maintainers
0
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swagger-api/apidom-reference

Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.

1.0.0-beta.30
Source
npm
Version published
Weekly downloads
530K
-5.1%
Maintainers
0
Weekly downloads
 
Created

What is @swagger-api/apidom-reference?

@swagger-api/apidom-reference is a package designed to facilitate the handling and manipulation of API documentation models. It provides tools for referencing, dereferencing, and resolving API documentation elements, making it easier to work with complex API specifications.

What are @swagger-api/apidom-reference's main functionalities?

Dereferencing

Dereferencing resolves all $ref pointers in the API documentation, replacing them with the actual referenced content. This is useful for working with a fully expanded version of the API documentation.

const { dereference } = require('@swagger-api/apidom-reference');

const apiDoc = {
  openapi: '3.0.0',
  info: {
    title: 'Sample API',
    version: '1.0.0'
  },
  paths: {
    '/pets': {
      get: {
        summary: 'List all pets',
        operationId: 'listPets',
        responses: {
          '200': {
            description: 'An paged array of pets',
            content: {
              'application/json': {
                schema: {
                  $ref: '#/components/schemas/Pets'
                }
              }
            }
          }
        }
      }
    }
  },
  components: {
    schemas: {
      Pets: {
        type: 'array',
        items: {
          $ref: '#/components/schemas/Pet'
        }
      },
      Pet: {
        type: 'object',
        properties: {
          id: {
            type: 'integer',
            format: 'int64'
          },
          name: {
            type: 'string'
          }
        }
      }
    }
  }
};

(async () => {
  const dereferencedDoc = await dereference(apiDoc);
  console.log(JSON.stringify(dereferencedDoc, null, 2));
})();

Resolving

Resolving processes the API documentation to identify and prepare all references for dereferencing. This step is often used before dereferencing to ensure all references are correctly identified.

const { resolve } = require('@swagger-api/apidom-reference');

const apiDoc = {
  openapi: '3.0.0',
  info: {
    title: 'Sample API',
    version: '1.0.0'
  },
  paths: {
    '/pets': {
      get: {
        summary: 'List all pets',
        operationId: 'listPets',
        responses: {
          '200': {
            description: 'An paged array of pets',
            content: {
              'application/json': {
                schema: {
                  $ref: '#/components/schemas/Pets'
                }
              }
            }
          }
        }
      }
    }
  },
  components: {
    schemas: {
      Pets: {
        type: 'array',
        items: {
          $ref: '#/components/schemas/Pet'
        }
      },
      Pet: {
        type: 'object',
        properties: {
          id: {
            type: 'integer',
            format: 'int64'
          },
          name: {
            type: 'string'
          }
        }
      }
    }
  }
};

(async () => {
  const resolvedDoc = await resolve(apiDoc);
  console.log(JSON.stringify(resolvedDoc, null, 2));
})();

Other packages similar to @swagger-api/apidom-reference

FAQs

Package last updated on 17 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts