Socket
Socket
Sign inDemoInstall

@swagger-api/apidom-reference

Package Overview
Dependencies
Maintainers
1
Versions
59
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.


Version published
Weekly downloads
449K
increased by10.3%
Maintainers
1
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 14 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc