{"id":13464759,"url":"https://github.com/krakenjs/hapi-openapi","last_synced_at":"2025-10-15T23:30:55.754Z","repository":{"id":21994882,"uuid":"25319913","full_name":"krakenjs/hapi-openapi","owner":"krakenjs","description":"Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.","archived":true,"fork":false,"pushed_at":"2022-02-18T16:53:27.000Z","size":347,"stargazers_count":212,"open_issues_count":0,"forks_count":75,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-09-24T04:54:27.702Z","etag":null,"topics":["api","hapi","openapi","rest","swagger"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"neerajnj10/AnalyticVidhya_BigMartSalesPrediction","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakenjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-16T20:17:54.000Z","updated_at":"2025-08-27T12:06:29.000Z","dependencies_parsed_at":"2022-08-18T16:50:52.255Z","dependency_job_id":null,"html_url":"https://github.com/krakenjs/hapi-openapi","commit_stats":null,"previous_names":["krakenjs/swaggerize-hapi"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/krakenjs/hapi-openapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fhapi-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fhapi-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fhapi-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fhapi-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakenjs","download_url":"https://codeload.github.com/krakenjs/hapi-openapi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakenjs%2Fhapi-openapi/sbom","scorecard":{"id":569333,"data":{"date":"2025-08-11","repo":{"name":"github.com/krakenjs/hapi-openapi","commit":"bf41135d7ad279995b3f3146fdc88d293f8d1e7a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.3,"checks":[{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":6,"reason":"Found 19/30 approved changesets -- score normalized to 6","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 19 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T15:52:50.195Z","repository_id":21994882,"created_at":"2025-08-20T15:52:50.195Z","updated_at":"2025-08-20T15:52:50.195Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020647,"owners_count":26086895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","hapi","openapi","rest","swagger"],"created_at":"2024-07-31T14:00:49.903Z","updated_at":"2025-10-15T23:30:55.450Z","avatar_url":"https://github.com/krakenjs.png","language":"JavaScript","readme":"# hapi-openapi\n\n[![Build Status](https://travis-ci.org/krakenjs/hapi-openapi.svg?branch=master)](https://travis-ci.org/krakenjs/hapi-openapi)\n[![NPM version](https://badge.fury.io/js/hapi-openapi.png)](http://badge.fury.io/js/hapi-openapi)\n\n### Note: this project was renamed from 'swaggerize-hapi' to 'hapi-openapi'.\n\n`hapi-openapi` is a design-driven approach to building RESTful services with [OpenAPI (Swagger)](http://openapis.org) and [Hapi](http://hapijs.com).\n\n`hapi-openapi` provides the following features:\n\n- API schema validation.\n- Routes based on the OpenAPI document.\n- API documentation route.\n- Input validation.\n\n### Why \"Design Driven\"\n\nThere are already a number of modules that help build RESTful APIs for node with OpenAPI. However,\nthese modules tend to focus on building the documentation or specification as a side effect of writing\nthe application business logic.\n\n`hapi-openapi` begins with the OpenAPI document first. This facilitates writing APIs that are easier to design, review, and test.\n\nAt runtime, `hapi-openapi` uses the API specification to build routes from previously defined paths. This ensures that everything specified is what is implemented.\n\n### Quick Start with a Generator\n\nThis guide will let you go from an `api.json` to a service project in no time flat.\n\nFirst install `generator-swaggerize` (and `yo` if you haven't already):\n\n```bash\n$ npm install -g yo\n$ npm install -g generator-swaggerize\n```\n\nNow run the generator.\n\n```bash\n$ mkdir petstore \u0026\u0026 cd $_\n$ yo swaggerize\n```\n\nFollow the prompts (note: make sure to choose `hapi` as your framework choice).\n\nYou now have a working api and can use something like [SwaggerHub](https://swaggerhub.com/?_ga=2.118604234.2143392684.1515431456-1673703125.1481054263) to explore it.\n\n### Manual Usage\n\n```javascript\nconst Hapi = require('@hapi/hapi');\nconst Path = require(\"path\");\n\nconst server = new Hapi.Server( { port: 3000 } );\n\nasync function init () {\n  await server.register({\n    plugin: require('hapi-openapi'),\n    options: {\n        api: Path.join(__dirname, './config/pets.json'),\n        handlers: Path.join(__dirname, './handlers')\n    }\n  });\n  await server.start();\n  console.log( server.info.uri );\n}\n\ninit();\n```\n\n### Hapi Plugin\n\nThe plugin will be registered as `openapi` on `server.plugins` with the following exposed:\n\n- `getApi()` - the resolved Swagger document.\n- `setHost(host)` - a helper function for setting the `host` property on the `api`.\n\n### Configuration Options\n\n- `api` - a path to a valid OpenAPI 2.0 document, or a valid document in the form of an object.\n- *deprecated* `docspath` - the path to expose api docs for swagger-ui, etc. Defaults to `/api-docs`.\n- `docs` - an object used to configure the api docs route.\n    - `path` - the path to expose api docs for swagger-ui, etc. Defaults to `/api-docs`.\n    - `auth` - options auth config for this route.\n    - `stripExtensions` - strip vendor extensions from docs. Defaults to true.\n    - `prefixBasePath` - prefix path of docs with he OpenAPI document's `basePath` value. Defaults to true.\n- `handlers` - either a string directory structure for route handlers, object, or not set if using `x-hapi-handler`.\n- `extensions` - an array of file extension types to use when scanning for handlers. Defaults to `['js']`.\n- `vhost` - *optional* domain string (see [hapi route options](http://hapijs.com/api#route-options)).\n- `cors` - *optional* cors setting (see [hapi route options](http://hapijs.com/api#route-options)).\n- `outputvalidation` - *optional* validate response data.\n\n### Mount Path\n\nApi `path` values will be prefixed with the OpenAPI document's `basePath` value.  This behavior can be negated if you set the option `docs.prefixBasePath` to `false`.\n\n### Handlers Directory\n\nThe `options.handlers` option specifies a directory to scan for handlers. These handlers are bound to the api `paths` defined in the OpenAPI document.\n\n```\nhandlers\n  |--foo\n  |    |--bar.js\n  |--foo.js\n  |--baz.js\n```\n\nWill route as:\n\n```\nfoo.js =\u003e /foo\nfoo/bar.js =\u003e /foo/bar\nbaz.js =\u003e /baz\n```\n\n### Path Parameters\n\nThe file and directory names in the handlers directory can also represent path parameters.\n\nFor example, to represent the path `/users/{id}`:\n\n```shell\nhandlers\n  |--users\n  |    |--{id}.js\n```\n\nThis works with directory names as well:\n\n```shell\nhandlers\n  |--users\n  |    |--{id}.js\n  |    |--{id}\n  |        |--foo.js\n```\n\nTo represent `/users/{id}/foo`.\n\n### Handlers File\n\nEach provided javascript file should export an object containing functions with HTTP verbs as keys.\n\nExample:\n\n```javascript\nmodule.exports = {\n    get: function (req, h) { ... },\n    put: function (req, h) { ... },\n    ...\n}\n```\n\nOptionally, `pre` handlers can be used by providing an array of handlers for a method:\n\n```javascript\nmodule.exports = {\n    get: [\n        function p1(req, h) { ... },\n        function handler(req, h) { ... }\n    ],\n}\n```\n\n### Handlers Object\n\nThe directory generation will yield this object, but it can be provided directly as `options.handlers`.\n\nExample:\n\n```javascript\n{\n    'foo': {\n        'get': function (req, h) { ... },\n        'bar': {\n            'get': function (req, h) { ... },\n            'post': function (req, h) { ... }\n        }\n    }\n    ...\n}\n```\n\n### X-Hapi-Handler\n\nAlternatively the API document can set `x-hapi-handler` attribute on each defined `paths` element if `handlers` is not defined.\n\nExample:\n\n```\n\"/pets/{id}\": {\n    \"x-hapi-handler\": \"./routes/pets-by-id.js\",\n    .\n    .\n    .\n```\n\nThis will construct a `handlers` object from the given `x-hapi-handler` files.\n\n### X-Hapi-Options\n\nThere is now support at the operations level for `x-hapi-options` which represent individual [Hapi Route Optijons](https://github.com/hapijs/hapi/blob/master/API.md#route-options).\n\nThis support is limited to configuration supported by the JSON file type.\n\nExample:\n\n```\n\"/internal\": {\n  \"post\": {\n    \"x-hapi-options\": {\n      \"isInternal\": true\n    }\n    .\n    .\n    .\n```\n\n### Authentication\n\nSupport for OpenAPI [security schemes](http://swagger.io/specification/#securitySchemeObject) requires that relevant authentication scheme and strategy are registered before the hapi-openapi plugin. See the [hapi docs](http://hapijs.com/tutorials/auth) for information about authentication schemes and strategies.\n\nThe name of the hapi authentication strategy is expected to match the name field of the OpenAPI [security requirement object](http://swagger.io/specification/#securityRequirementObject).\n\nExample:\n\n```yaml\nsecurityDefinitions:\n  api_key:\n    type: apiKey\n    name: Authorization\n    in: header\npaths:\n  '/users/':\n    get:\n      security:\n        - api_key: []\n```\n\n```javascript\nconst server = new Hapi.Server();\n\nawait server.register({ plugin: AuthTokenScheme });\n\nserver.auth.strategy('api_key', 'auth-token-scheme', {\n    validateFunc: async function (token) {\n      // Implement validation here, return { credentials, artifacts }.\n    }\n});\n\nawait server.register({\n    plugin: require('hapi-openapi'),\n    options: {\n        api: require('./config/pets.json'),\n        handlers: Path.join(__dirname, './handlers')\n    }\n});\n```\n\n### X-Hapi-Auth\n\nAlternatively it may be easier to automatically register a plugin to handle registering the necessary schemes and strategies.\n\n**x-hapi-auth-schemes**\n\nThe root document can contain an `x-hapi-auth-schemes` object specifying different plugins responsible for registering auth schemes.\n\nExample:\n\n```\n\"x-hapi-auth-schemes\": {\n    \"apiKey\": \"../lib/xauth-scheme.js\"\n}\n```\n\nThis plugin will be passed the following options:\n\n- `name` - the auth scheme name, in this example `apiKey`.\n\n**x-hapi-auth-strategy**\n\nThe `securityDefinitions` entries can contain an `x-hapi-auth-strategy` attribute pointing to a plugin responsible for registering auth strategies.\n\nExample:\n\n```\n\"securityDefinitions\": {\n  \"api_key\": {\n    \"x-hapi-auth-strategy\": \"../lib/xauth-strategy.js\",\n    \"type\": \"apiKey\",\n    \"name\": \"authorization\",\n    \"in\": \"header\"\n  }\n}\n```\n\nThe plugin will be passed the following options:\n\n- `name` - the `securityDefinitions` entry's key. In this example, `api_key`. This is typically used as the strategy name.\n- `scheme` - the `securityDefinitions` `type`. In this example, `apiKey`. This should match a `x-hapi-auth-scheme` name.\n- `where` - `securityDefinitions` entry `in` attribute. This is search for the `lookup` value; in this example `header`.\n- `lookup` - `securityDefinitions` entry `name` attribute. Used as the name to look up against `where`.\n\nThe way you can make these play together is that for every `type`, a scheme exists that delegates some lookup or evaluation to the appropriate strategy.\n\nExample:\n\n```javascript\n//xauth-scheme.js\n\nconst register = function (server, { name  }) {\n    server.auth.scheme(name /*apiKey*/, (server, /* options received from the strategy */ { validate }) =\u003e {\n        return {\n            authenticate: async function (request, h) {\n                return h.authenticated(await validate(request));\n            }\n        };\n    });\n};\n\nmodule.exports = { register, name: 'x-hapi-auth-scheme' };\n```\n\nand\n\n```javascript\n//xauth-strategy.js\n\nconst Boom = require('@hapi/boom');\n\nconst register = function (server, { name, scheme, where, lookup }) {\n    server.auth.strategy(name, /* the scheme to use this strategy with */ scheme, {\n        //Define a validate function for the scheme above to receive\n        validate: async function (request) {\n            const token = request.headers[lookup];\n\n            //Some arbitrary example\n            if (token === '12345') {\n                return { credentials: { scope: ['read'] }, artifacts: { token } };\n            }\n\n            throw Boom.unauthorized();\n        }\n    });\n};\n\nmodule.exports = { register, name: 'x-hapi-auth-strategy' };\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakenjs%2Fhapi-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakenjs%2Fhapi-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakenjs%2Fhapi-openapi/lists"}