{"library":"oatts","title":"OpenAPI Test Templates Generator","description":"OATTS (OpenAPI Test Templates) is a utility designed to generate basic Node.js unit test scaffolding directly from an OpenAPI specification document. Currently at version 1.6.0, it provides both a command-line interface and a module API to automate the creation of boilerplate tests for your API endpoints. The generated tests are structured for the Mocha testing framework and utilize Chakram for API assertions, encouraging developers to maintain a consistent contract between their API specification and its implementation. While providing valuable scaffolding for early and continuous API contract testing, it's important to note that OATTS is described as a 'work in progress' and 'not an officially supported Google product', suggesting a less frequent release cadence and potentially limited long-term support compared to core Google projects. Its primary differentiator is its focus on generating runnable Mocha/Chakram tests specifically for Node.js environments, building on lessons learned from `swagger-test-templates`.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install oatts"],"cli":{"name":"oatts","version":null}},"imports":["const oatts = require('oatts');","const tests = oatts.generate('/path/to/openapi.yaml', options);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const oatts = require('oatts');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create a dummy OpenAPI spec for demonstration\nconst dummyOpenApiSpecPath = path.join(__dirname, 'dummy-openapi.yaml');\nconst dummyOpenApiSpecContent = `\nopenapi: 3.0.0\ninfo:\n  title: Dummy API\n  version: 1.0.0\nservers:\n  - url: http://localhost:3000\npaths:\n  /hello:\n    get:\n      summary: Greet the user\n      operationId: getHello\n      responses:\n        '200':\n          description: Successful response\n          content:\n            application/json:\n              schema:\n                type: object\n                properties:\n                  message:\n                    type: string\n  /goodbye/{name}:\n    parameters:\n      - name: name\n        in: path\n        required: true\n        schema:\n          type: string\n    get:\n      summary: Bid farewell\n      operationId: getGoodbye\n      responses:\n        '200':\n          description: Successful farewell\n          content:\n            application/json:\n              schema:\n                type: object\n                properties:\n                  farewellMessage:\n                    type: string\n`;\n\nfs.writeFileSync(dummyOpenApiSpecPath, dummyOpenApiSpecContent);\n\n// Options for test generation\nconst options = {\n  host: 'http://localhost:3000', // Target API host for generated tests\n  writeTo: path.join(__dirname, 'generated-tests'), // Directory to write tests\n  // You can specify specific paths: paths: '/hello,/goodbye/{name}'\n};\n\nconsole.log('Generating tests for dummy OpenAPI spec...');\n\n// Generate the tests\noatts.generate(dummyOpenApiSpecPath, options)\n  .then((generatedFiles) => {\n    console.log('Tests generated successfully:');\n    generatedFiles.forEach(file => console.log(`- ${file}`));\n    console.log(`\nTo run these tests, you'll need mocha and chakram installed:\n  npm install --save-dev mocha chakram\nThen, start your API server (if applicable) and run:\n  mocha --recursive ${options.writeTo}`);\n  })\n  .catch((error) => {\n    console.error('Error generating tests:', error);\n  })\n  .finally(() => {\n    // Clean up the dummy spec file and generated test directory\n    fs.unlinkSync(dummyOpenApiSpecPath);\n    // Note: Deleting the generated test directory is more complex and left out for quickstart clarity\n    // You might want to remove this for actual usage to inspect generated files.\n  });\n","lang":"javascript","description":"This quickstart demonstrates how to programmatically use `oatts` to generate unit test scaffolding for a simple OpenAPI specification, writing them to a specified directory. It includes cleanup for the dummy spec.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}