{"id":15636692,"url":"https://github.com/erikwittern/openapi-snippet","last_synced_at":"2025-10-05T14:07:36.768Z","repository":{"id":10756745,"uuid":"66855599","full_name":"ErikWittern/openapi-snippet","owner":"ErikWittern","description":"Generates code snippets for given Swagger / Open API documents","archived":false,"fork":false,"pushed_at":"2024-06-24T19:35:31.000Z","size":356,"stargazers_count":123,"open_issues_count":37,"forks_count":68,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T04:16:08.788Z","etag":null,"topics":["openapi","openapi3","snippets","swagger"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ErikWittern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-29T15:24:00.000Z","updated_at":"2025-02-10T15:24:02.000Z","dependencies_parsed_at":"2024-10-23T03:52:05.834Z","dependency_job_id":null,"html_url":"https://github.com/ErikWittern/openapi-snippet","commit_stats":{"total_commits":86,"total_committers":26,"mean_commits":"3.3076923076923075","dds":0.7209302325581395,"last_synced_commit":"cfe92a022c76f4bb774710df5f5883486beb4851"},"previous_names":["erikwittern/swagger-snippet"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fopenapi-snippet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fopenapi-snippet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fopenapi-snippet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fopenapi-snippet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ErikWittern","download_url":"https://codeload.github.com/ErikWittern/openapi-snippet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123107,"owners_count":20887261,"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":["openapi","openapi3","snippets","swagger"],"created_at":"2024-10-03T11:06:18.209Z","updated_at":"2025-10-05T14:07:31.715Z","avatar_url":"https://github.com/ErikWittern.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAPI Snippet\n**Generates code snippets from Open API (previously Swagger) documents.**\n\nThis package takes as input an OpenAPI v2.0 or v3.0.x document. It translates the document into an [HTTP Archive 1.2 request object](http://www.softwareishard.com/blog/har-12-spec/#request). It uses the [HTTP Snippet](https://github.com/Mashape/httpsnippet) library to generate code snippets for every API endpoint (URL path + HTTP method) defined in the specification in various languages \u0026 tools (`cURL`, `Node`, `Python`, `Ruby`, `Java`, `Go`, `C#`...), or for selected endpoints.\n\n## Installation\n\n```bash\nnpm i openapi-snippet\n```\n\n## Build OpenAPI Snippet (for use in browser)\nClone this repository. Install required dependencies:\n\n```bash\nnpm i\n```\n\nBuild a minified version of OpenAPI Snippet (`openapisnippet.min.js`):\n\n```bash\nnpm run build\n```\n\n## Usage\n\n### As a module\n\n```javascript\nconst OpenAPISnippet = require('openapi-snippet')\n\n// define input:\nconst openApi = ... // Open API document\nconst targets = ['node_unirest', 'c'] // array of targets for code snippets. See list below...\n\ntry {\n  // either, get snippets for ALL endpoints:\n  const results = OpenAPISnippet.getSnippets(openApi, targets) // results is now array of snippets, see \"Output\" below.\n\n  // ...or, get snippets for a single endpoint:\n  const results2 = OpenAPISnippet.getEndpointSnippets(openApi, '/users/{user-id}/relationship', 'get', targets)\n} catch (err) {\n  // do something with potential errors...\n}\n```\n\n### Within the browser\n\nInclude the `openapisnippet.min.js` file created after building the the library (see above) in your HTML page:\n\n```html\n\u003cscript type=\"text/javascript\" src=\"path/to/openapisnippet.min.js\"\u003e\u003c/script\u003e\n```\n\nUse OpenAPI Snippet, which now defines the global variable `OpenAPISnippet`.\n\n\n## Output\nThe output for every endpoint is an object, containing the `method`, `url`, a human-readable `description`, and the corresponding `resource` - all of these values stem from the OpenAPI document. In addition, within the `snippets` list, an object containing a code snippet for every chosen target is provided. As of version `0.4.0`, the snippets include exemplary payload data.\n\nIf `getSnippets` is used, an array of the above described objects is returned.\n\nFor example:\n\n```js\n[\n  // ...\n  {\n    \"method\": \"GET\",\n    \"url\": \"https://api.instagram.com/v1/users/{user-id}/relationship\",\n    \"description\": \"Get information about a relationship to another user.\",\n    \"resource\": \"relationship\",\n    \"snippets\": [\n      {\n        \"id\": \"node\",\n        \"mimeType\": \"application/json\",  // Only set for methods with a request body\n        \"title\": \"Node + Native\",\n        \"content\": \"var http = require(\\\"https\\\");\\n\\nvar options = {...\"\n      }\n    ]\n  }\n  // ...\n]\n```\n\n## Targets\nCurrently, OpenAPI Snippet supports the following [targets](https://github.com/Kong/httpsnippet/tree/master/src/targets) (depending on the HTTP Snippet library):\n\n* `c_libcurl` (default)\n* `csharp_restsharp` (default)\n* `csharp_httpclient`\n* `go_native` (default)\n* `java_okhttp`\n* `java_unirest` (default)\n* `javascript_jquery`\n* `javascript_xhr` (default)\n* `node_native` (default)\n* `node_request`\n* `node_unirest`\n* `objc_nsurlsession` (default)\n* `ocaml_cohttp` (default)\n* `php_curl` (default)\n* `php_http1`\n* `php_http2`\n* `python_python3` (default)\n* `python_requests`\n* `ruby_native` (default)\n* `shell_curl` (default)\n* `shell_httpie`\n* `shell_wget`\n* `swift_nsurlsession` (default)\n\nIf only the language is provided (e.g., `c`), the default library will be selected.\n\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikwittern%2Fopenapi-snippet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikwittern%2Fopenapi-snippet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikwittern%2Fopenapi-snippet/lists"}