{"id":13989973,"url":"https://github.com/rbren/scrape-to-swagger","last_synced_at":"2025-03-27T06:31:14.725Z","repository":{"id":144782105,"uuid":"48181997","full_name":"rbren/scrape-to-swagger","owner":"rbren","description":"Scrape API Documentation from HTML to a JSON Swagger Document","archived":false,"fork":false,"pushed_at":"2019-03-12T11:39:29.000Z","size":858,"stargazers_count":30,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T07:51:13.498Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rbren.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-12-17T15:22:57.000Z","updated_at":"2024-12-18T08:10:47.000Z","dependencies_parsed_at":"2024-01-15T16:52:33.806Z","dependency_job_id":null,"html_url":"https://github.com/rbren/scrape-to-swagger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbren%2Fscrape-to-swagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbren%2Fscrape-to-swagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbren%2Fscrape-to-swagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbren%2Fscrape-to-swagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbren","download_url":"https://codeload.github.com/rbren/scrape-to-swagger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245797457,"owners_count":20673857,"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","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":[],"created_at":"2024-08-09T13:02:12.965Z","updated_at":"2025-03-27T06:31:13.702Z","avatar_url":"https://github.com/rbren.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# scrape-to-swagger\n\n## Usage\nSee the [config directory](config) for example configurations\n\n```bash\nnpm install -g scrape-to-swagger\nscrape-to-swagger --config ./config/product-hunt.js --output ./output/product-hunt.swagger.json --verbose\n```\n\n## Config\n\nThe configuration file tells scrape-to-swagger how to retrieve each piece of the swagger document from the HTML.\n\n#### Required\n* `url` - The root page to scrape\n* `depth` - The depth to crawl links\n\n#### Selectors\nSelector fields correspond to parts of the Swagger document. These can be specified as constants or as selectors.\n* `host`\n* `basePath`\n* `title`\n* `description`\n* `operations` - A group of operations\n  * `operation` - A single operation (e.g. GET /users)\n    * `path`\n    * `method`\n    * `operationDescription`\n    * `parameters`\n      * `parameter`\n        * `parameterIn`\n        * `parameterName`\n        * `parameterRequired`\n        * `parameterDescription`\n    * `responses`\n      * `response`\n        * `responseStatus`\n        * `responseDescription`\n        * `responseSchema`\n\nSelectors are passed to [cheerio](https://github.com/cheeriojs/cheerio), which is based on jQuery.\n\nThe selector object takes four parameters:\n* selector - a CSS selector. This will be applied as parent.find(selector), where the parent is the element in the hierarchy above (or \u0026lt;body\u0026gt; if none)\n* regex - A regular expression for extracting the field from the text inside the selector\n* regexIndex - The index of the matched items to use (default=1, i.e. it will capture the first thing you put in parens)\n* join - If true, join *all* the elements matched by the selector\n* split - If true, include all siblings of the element matched by the selector, up until the next match of the selector\n\n#### Other\n\n* `fixPathParameters` a function for converting to Swagger-style parameters, e.g. from /users/:username to /users/{username}\n\n```js\nvar config = module.exports = {\n  url: 'https://www.quandl.com/docs/api',\n  depth: 0,\n  protocols: ['https'],\n  host: 'www.quandl.com',\n  basePath: '/api/v3',\n  title: 'Quandl API',\n  description: 'The Quandl API',\n\n  operations: {selector: 'h2', split: true},\n  operationDescription: {selector: 'h2 ~ p', join: true},\n  path: {selector: 'pre:contains(Definition) + div + blockquote', regex: /\\w+ https:\\/\\/www.quandl.com\\/api\\/v3(\\/\\S*)/},\n  method: {selector: 'pre:contains(Definition) + div + blockquote', regex: /(\\w+) https:\\/\\/www.quandl.com\\/api\\/v3\\/\\S*/},\n\n  parameters: {selector: 'table'},\n  parameter: {selector: 'tr'},\n  parameterIn: 'query',\n  parameterType: 'string',\n  parameterName: {selector: 'td:first-of-type', regex: /(\\S+)/},\n  parameterRequired: {selector: 'td:nth-of-type(2)'},\n  parameterDescription: {selector: 'td:nth-of-type(3)'},\n\n  responseSchema: {selector: 'pre:contains(Example Response) + div + blockquote', isExample: true},\n\n  fixPathParameters: function(path) {\n    pieces = path.split('/');\n    pieces = pieces.map(function(p) {\n      return p.replace(/:(\\w+)/g, '{$1}')\n    })\n    return pieces.join('/');\n  }\n}\n\nconfig.securityDefinitions = {\n  'apiKey': {\n    type: 'apiKey',\n    name: 'api_key',\n    in: 'query',\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbren%2Fscrape-to-swagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbren%2Fscrape-to-swagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbren%2Fscrape-to-swagger/lists"}