{"library":"openapi-merge-cli","title":"OpenAPI Merge CLI","description":"The `openapi-merge-cli` package provides a command-line interface for merging multiple OpenAPI 3.0 specification files into a single, consolidated specification. It is built upon the `openapi-merge` library, inheriting its core merging algorithm. The tool is currently at version 1.3.2 and appears to be actively maintained in sync with its underlying library. Its primary use case is consolidating specifications from various microservices for exposure behind a single API Gateway, offering features like robust conflict resolution for component names, flexible path modification (stripping or prepending segments), and granular operation selection based on tags. It also supports merging `info.description` fields with custom titles. Unlike many general-purpose OpenAPI tools, its feature set is specifically tailored for API Gateway integration scenarios.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install openapi-merge-cli"],"cli":{"name":"openapi-merge-cli","version":null}},"imports":["npx openapi-merge-cli","npm install -g openapi-merge-cli && openapi-merge-cli","openapi-merge-cli --config ./path/to/my-custom-config.json"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst path = require('path');\nconst { execSync } = require('child_process');\n\nconst configPath = path.join(__dirname, 'openapi-merge.json');\nconst outputPath = path.join(__dirname, 'output.swagger.json');\n\nconst config = {\n  \"inputs\": [\n    { \"inputFile\": \"./service-a.swagger.json\" },\n    {\n      \"inputFile\": \"./service-b.swagger.yaml\",\n      \"pathModification\": { \"prepend\": \"/api/v2\" },\n      \"operationSelection\": { \"includeTags\": [\"public\"] }\n    }\n  ],\n  \"output\": outputPath\n};\n\n// Dummy OpenAPI input files for demonstration\nconst serviceA = `{\n  \"openapi\": \"3.0.0\",\n  \"info\": { \"title\": \"Service A\", \"version\": \"1.0.0\" },\n  \"paths\": {\n    \"/health\": {\n      \"get\": {\n        \"summary\": \"Health check A\",\n        \"responses\": { \"200\": { \"description\": \"OK\" } }\n      }\n    }\n  }\n}`;\n\nconst serviceB = `\nopenapi: 3.0.0\ninfo:\n  title: Service B\n  version: 1.0.0\npaths:\n  /users:\n    get:\n      tags:\n        - public\n      summary: List users B\n      responses:\n        '200':\n          description: OK\n  /admin:\n    get:\n      tags:\n        - private\n      summary: Admin endpoint B\n      responses:\n        '200':\n          description: OK\n`;\n\ntry {\n  // Create dummy input files and configuration file\n  fs.writeFileSync(path.join(__dirname, 'service-a.swagger.json'), serviceA);\n  fs.writeFileSync(path.join(__dirname, 'service-b.swagger.yaml'), serviceB);\n  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));\n\n  console.log('Created openapi-merge.json and dummy input files.');\n  console.log('Running openapi-merge-cli...');\n\n  // Execute the CLI tool using npx\n  execSync(`npx openapi-merge-cli --config ${configPath}`, { stdio: 'inherit' });\n\n  console.log(`OpenAPI specification merged to ${outputPath}`);\n  console.log('You can now inspect output.swagger.json');\n\n  // Optional: Clean up generated files\n  // fs.unlinkSync(configPath);\n  // fs.unlinkSync(path.join(__dirname, 'service-a.swagger.json'));\n  // fs.unlinkSync(path.join(__dirname, 'service-b.swagger.yaml'));\n} catch (error) {\n  console.error('Failed to merge OpenAPI files:', error.message);\n  process.exit(1);\n}","lang":"javascript","description":"This quickstart demonstrates how to programmatically set up an 'openapi-merge.json' configuration and input files, then execute the 'openapi-merge-cli' tool using Node.js to merge them.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}