{"id":13724590,"url":"https://github.com/wcandillon/swagger-js-codegen","last_synced_at":"2026-01-26T18:54:07.223Z","repository":{"id":526999,"uuid":"20851554","full_name":"wcandillon/swagger-js-codegen","owner":"wcandillon","description":"A Swagger Codegen for typescript, nodejs \u0026 angularjs","archived":false,"fork":false,"pushed_at":"2022-12-06T17:19:19.000Z","size":497,"stargazers_count":694,"open_issues_count":72,"forks_count":286,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-10-29T22:53:47.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wcandillon.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}},"created_at":"2014-06-15T08:50:24.000Z","updated_at":"2024-10-29T13:54:11.000Z","dependencies_parsed_at":"2023-01-13T16:21:57.466Z","dependency_job_id":null,"html_url":"https://github.com/wcandillon/swagger-js-codegen","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/wcandillon%2Fswagger-js-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcandillon%2Fswagger-js-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcandillon%2Fswagger-js-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcandillon%2Fswagger-js-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wcandillon","download_url":"https://codeload.github.com/wcandillon/swagger-js-codegen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243859602,"owners_count":20359560,"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-03T01:01:59.936Z","updated_at":"2026-01-26T18:54:07.186Z","avatar_url":"https://github.com/wcandillon.png","language":"HTML","funding_links":[],"categories":["Docs generator","HTML"],"sub_categories":[],"readme":"# Swagger to JS \u0026 Typescript Codegen\n[![Circle CI](https://circleci.com/gh/wcandillon/swagger-js-codegen.svg?style=svg)](https://circleci.com/gh/wcandillon/swagger-js-codegen) [![NPM version](http://img.shields.io/npm/v/swagger-js-codegen.svg?style=flat)](http://badge.fury.io/js/swagger-js-codegen)\n\n## We are looking for a new maintainer\n\nThis project is no longer actively maintained by its creator. Please let us know if you would like to become a maintainer.\nAt the time we wrote this package, the swagger didn't have generators for JavaScript nor TypeScript. Now there are [great alternatives of this package available](https://github.com/swagger-api/swagger-codegen). \n\nThis package generates a nodejs, reactjs or angularjs class from a [swagger specification file](https://github.com/wordnik/swagger-spec). The code is generated using [mustache templates](https://github.com/wcandillon/swagger-js-codegen/tree/master/templates) and is quality checked by [jshint](https://github.com/jshint/jshint/) and beautified by [js-beautify](https://github.com/beautify-web/js-beautify).\n\nThe typescript generator is based on [superagent](https://github.com/visionmedia/superagent) and can be used for both nodejs and the browser via browserify/webpack.\n\n## Installation\n```bash\nnpm install swagger-js-codegen\n```\n\n## Example\n```javascript\nvar fs = require('fs');\nvar CodeGen = require('swagger-js-codegen').CodeGen;\n\nvar file = 'swagger/spec.json';\nvar swagger = JSON.parse(fs.readFileSync(file, 'UTF-8'));\nvar nodejsSourceCode = CodeGen.getNodeCode({ className: 'Test', swagger: swagger });\nvar angularjsSourceCode = CodeGen.getAngularCode({ className: 'Test', swagger: swagger });\nvar reactjsSourceCode = CodeGen.getReactCode({ className: 'Test', swagger: swagger });\nvar tsSourceCode = CodeGen.getTypescriptCode({ className: 'Test', swagger: swagger, imports: ['../../typings/tsd.d.ts'] });\nconsole.log(nodejsSourceCode);\nconsole.log(angularjsSourceCode);\nconsole.log(reactjsSourceCode);\nconsole.log(tsSourceCode);\n```\n\n## Custom template\n```javascript\nvar source = CodeGen.getCustomCode({\n    moduleName: 'Test',\n    className: 'Test',\n    swagger: swaggerSpec,\n    template: {\n        class: fs.readFileSync('my-class.mustache', 'utf-8'),\n        method: fs.readFileSync('my-method.mustache', 'utf-8'),\n        type: fs.readFileSync('my-type.mustache', 'utf-8')\n    }\n});\n```\n\n## Options\nIn addition to the common options listed below, `getCustomCode()` *requires* a `template` field:\n\n    template: { class: \"...\", method: \"...\" }\n\n`getAngularCode()`, `getNodeCode()`, and `getCustomCode()` each support the following options:\n\n```yaml\n  moduleName:\n    type: string\n    description: Your AngularJS module name\n  className:\n    type: string\n  lint:\n    type: boolean\n    description: whether or not to run jslint on the generated code\n  esnext:\n    type: boolean\n    description: passed through to jslint\n  beautify:\n    type: boolean\n    description: whether or not to beautify the generated code\n  mustache:\n    type: object\n    description: See the 'Custom Mustache Variables' section below\n  imports:\n    type: array\n    description: Typescript definition files to be imported.\n  swagger:\n    type: object\n    required: true\n    description: swagger object\n```\n\n### Template Variables\nThe following data are passed to the [mustache templates](https://github.com/janl/mustache.js):\n\n```yaml\nisNode:\n  type: boolean\nisES6:\n  type: boolean\ndescription:\n  type: string\n  description: Provided by your options field: 'swagger.info.description'\nisSecure:\n  type: boolean\n  description: false unless 'swagger.securityDefinitions' is defined\nmoduleName:\n  type: string\n  description: Your AngularJS module name - provided by your options field\nclassName:\n  type: string\n  description: Provided by your options field\ndomain:\n  type: string\n  description: If all options defined: swagger.schemes[0] + '://' + swagger.host + swagger.basePath\nmethods:\n  type: array\n  items:\n    type: object\n    properties:\n      path:\n        type: string\n      className:\n        type: string\n        description: Provided by your options field\n      methodName:\n        type: string\n        description: Generated from the HTTP method and path elements or 'x-swagger-js-method-name' field\n      method:\n        type: string\n        description: 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'COPY', 'HEAD', 'OPTIONS', 'LINK', 'UNLIK', 'PURGE', 'LOCK', 'UNLOCK', 'PROPFIND'\n        enum:\n        - GET\n        - POST\n        - PUT\n        - DELETE\n        - PATCH\n        - COPY\n        - HEAD\n        - OPTIONS\n        - LINK\n        - UNLIK\n        - PURGE\n        - LOCK\n        - UNLOCK\n        - PROPFIND\n      isGET:\n        type: string\n        description: true if method === 'GET'\n      summary:\n        type: string\n        description: Provided by the 'description' or 'summary' field in the schema\n      externalDocs:\n        type: object\n        properties:\n          url:\n            type: string\n            description: The URL for the target documentation. Value MUST be in the format of a URL.\n            required: true\n          description:\n            type: string\n            description: A short description of the target documentation. GitHub-Markdown syntax can be used for rich text representation.\n      isSecure:\n        type: boolean\n        description: true if the 'security' is defined for the method in the schema\n      parameters:\n        type: array\n        description: Includes all of the properties defined for the parameter in the schema plus:\n        items:\n          camelCaseName:\n            type: string\n          isSingleton:\n            type: boolean\n            description: true if there was only one 'enum' defined for the parameter\n          singleton:\n            type: string\n            description: the one and only 'enum' defined for the parameter (if there is only one)\n          isBodyParameter:\n            type: boolean\n          isPathParameter:\n            type: boolean\n          isQueryParameter:\n            type: boolean\n          isPatternType:\n            type: boolean\n            description: true if *in* is 'query', and 'pattern' is defined\n          isHeaderParameter:\n            type: boolean\n          isFormParameter:\n            type: boolean\n```\n\n#### Custom Mustache Variables\nYou can also pass in your own variables for the mustache templates by adding a `mustache` object:\n\n```javascript\nvar source = CodeGen.getCustomCode({\n    ...\n    mustache: {\n      foo: 'bar',\n      app_build_id: env.BUILD_ID,\n      app_version: pkg.version\n    }\n});\n```\n\n## Swagger Extensions\n\n### x-proxy-header\nSome proxies and application servers inject HTTP headers into the requests.  Server-side code\nmay use these fields, but they are not required in the client API.\n\neg: https://cloud.google.com/appengine/docs/go/requests#Go_Request_headers\n\n```yaml\n  /locations:\n    get:\n      parameters:\n      - name: X-AppEngine-Country\n        in: header\n        x-proxy-header: true\n        type: string\n        description: Provided by AppEngine eg - US, AU, GB\n      - name: country\n        in: query\n        type: string\n        description: |\n          2 character country code.\n          If not specified, will default to the country provided in the X-AppEngine-Country header\n      ...\n```\n\n\n## Grunt task\n[There is a grunt task](https://github.com/wcandillon/grunt-swagger-js-codegen) that enables you to integrate the code generation in your development pipeline. This is extremely convenient if your application is using APIs which are documented/specified in the swagger format.\n\n## Who is using it?\n[28.io](http://28.io) is using this project to generate their [nodejs](https://github.com/28msec/28.io-nodejs) and [angularjs language bindings](https://github.com/28msec/28.io-angularjs).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcandillon%2Fswagger-js-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwcandillon%2Fswagger-js-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcandillon%2Fswagger-js-codegen/lists"}