{"id":21488513,"url":"https://github.com/papirosko/swagger-code-gen","last_synced_at":"2026-03-03T15:02:11.117Z","repository":{"id":64241963,"uuid":"574379832","full_name":"papirosko/swagger-code-gen","owner":"papirosko","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-07T12:06:24.000Z","size":263,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T13:24:07.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/papirosko.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-05T07:17:32.000Z","updated_at":"2025-05-07T12:06:27.000Z","dependencies_parsed_at":"2024-06-19T18:14:35.023Z","dependency_job_id":"e567a1cd-68e9-4fcb-bc09-b0833e085bf8","html_url":"https://github.com/papirosko/swagger-code-gen","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"15ffffb26715641a52f871e6f51bae2332a9858e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/papirosko/swagger-code-gen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papirosko%2Fswagger-code-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papirosko%2Fswagger-code-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papirosko%2Fswagger-code-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papirosko%2Fswagger-code-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/papirosko","download_url":"https://codeload.github.com/papirosko/swagger-code-gen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papirosko%2Fswagger-code-gen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265445302,"owners_count":23766445,"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-11-23T14:09:43.765Z","updated_at":"2026-03-03T15:02:11.105Z","avatar_url":"https://github.com/papirosko.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swagger-code-gen\nThe utility to generate a client for a services, described with openapi.\n\nInstall:\n```shell\nnpm install -D @penkov/swagger-code-gen\n```\n\n\nUsage:\n```shell\ngenerate-client --url \u003cURI\u003e output_filename.ts\ngenerate-client --url \u003cURI\u003e --includeTags tag1 tag2 -- output_filename.ts\ngenerate-client --url \u003cURI\u003e --includeTags tag1 tag2 --onlyUsedSchemas -- output_filename.ts\n```\n\nCli parameters:\n* `--url \u003cURI\u003e` - the swagger url\n* `--includeTags \u003ctags...\u003e` - Space-separated list of tags of paths to be included. Path is included if it contains any of specified tag\n  Path is included if exclusion list is empty or path contains any of the tags from inclusion list.\n  If the tag is both in inclusion and exclusion lists, it gets excluded.\n* `--excludeTags \u003ctags...\u003e` - Space-separated list of tags of paths to be excluded. \n  Path is excluded if exclusion list is non-empty and path contains any of the tags from exclusion list.\n  If the tag is both in inclusion and exclusion lists, it gets excluded.\n* `--onlyUsedSchemas` - generate only schemas that are reachable from filtered methods\n  (useful with `--includeTags`/`--excludeTags`). By default all schemas are generated.\n* `--includeSchemasByMask \u003cmasks...\u003e` Space-separated list of schema name masks to force-include with dependencies (supports * and ? wildcards)\n* `--referencedObjectsNullableByDefault` - then specified, the generated code will assume that\n  any object's field, that references another object, can be null, unless it is explicitly specified to be not nullable\n  (which is default in .net world: asp generates wrong spec)\n* `--enableScats` - generate additional wrappers in [scats](https://www.npmjs.com/package/scats) \n  style for all objects and create a service with methods for each endpoint.\n* `--targetNode` - adds imports for `node-fetch` package in generated code.\n\n## Tag filtering and schema pruning\n\nBy default, tag filters affect only methods and all schemas are still generated:\n```shell\ngenerate-client --url \u003cURI\u003e --includeTags public -- output_filename.ts\n```\n\nTo generate only schemas that are reachable from filtered methods, add `--onlyUsedSchemas`:\n```shell\ngenerate-client --url \u003cURI\u003e --includeTags public --onlyUsedSchemas -- output_filename.ts\n```\n\n\n\n# Example of generated code:\n\n```shell\ngenerate-client --enableScats --url https://petstore3.swagger.io/api/v3/openapi.json petstore.ts\n```\n\nWill generate:\n```typescript\n// header skipped\n\nasync function requestImpl\u003cT\u003e(request: Request, requestOptions: RequestOptions): Promise\u003cT\u003e {\n  const preProcessed = requestOptions.preProcessRequest ? await requestOptions.preProcessRequest(request) : request;\n  const resp = await fetch(preProcessed);\n  const postProcessed = requestOptions.postProcessResponse ? await requestOptions.postProcessResponse(preProcessed, resp) : resp;\n  if (postProcessed.ok) {\n    let json: any = null;\n    if (postProcessed.headers.has('content-length')) {\n      const ct = parseInt(postProcessed.headers.get('content-length'));\n      if (ct \u003e 0) {\n        json = await postProcessed.json()\n      }\n    }\n    return json as T;\n  } else {\n    throw postProcessed;\n  }\n}\n\n\n\n\nexport interface Customer {\n  readonly id: number;\n  readonly username: string;\n  readonly address: ReadonlyArray\u003cAddress\u003e;\n}\n\n\nexport interface Address {\n  readonly street: string;\n  readonly city: string;\n  readonly state: string;\n  readonly zip: string;\n}\n\n\nexport interface Category {\n  readonly id: number;\n  readonly name: string;\n}\n\n\nexport interface User {\n  readonly id: number;\n  readonly username: string;\n  readonly firstName: string;\n  readonly lastName: string;\n  readonly email: string;\n  readonly password: string;\n  readonly phone: string;\n  readonly userStatus: number;\n}\n\n\nexport interface Tag {\n  readonly id: number;\n  readonly name: string;\n}\n\n\nexport interface Pet {\n  readonly id: number;\n  readonly name: string;\n  readonly category: Category;\n  readonly photoUrls: ReadonlyArray\u003cstring\u003e;\n  readonly tags: ReadonlyArray\u003cTag\u003e;\n  readonly status: string;\n}\n\n\nexport interface ApiResponse {\n  readonly code: number;\n  readonly type: string;\n  readonly message: string;\n}\n\n\n\n/**\n * PUT /pet\n * @summary Update an existing pet\n * @description Update an existing pet by Id\n * @param {Pet} body Update an existent pet in the store\n * @param {RequestOptions} requestOptions Additional request params\n * @return {Pet} Successful operation\n */\nexport async function updatePet(\n        body: Pet,\n        requestOptions: RequestOptions = defReqOpts()\n): Promise\u003cPet\u003e {\n  let query = '';\n  const request = new Request(`${requestOptions.apiPrefix}/pet${query}`, {\n    method: 'put',\n    body: JSON.stringify(body),\n    headers: {\n      ...option(requestOptions.headers).getOrElseValue({}),\n    }\n  });\n  return requestImpl\u003cPet\u003e(request, requestOptions);\n}\n\n\n// ...\n\n\n/**\n * GET /pet/findByStatus\n * @summary Finds Pets by status\n * @description Multiple status values can be provided with comma separated strings\n * @param {\u0026#39;available\u0026#39; | \u0026#39;pending\u0026#39; | \u0026#39;sold\u0026#39;} status Status values that need to be considered for filter\n * @param {RequestOptions} requestOptions Additional request params\n * @return {ReadonlyArray\u0026lt;Pet\u0026gt;} successful operation\n */\nexport async function findPetsByStatus(\n        status: 'available' | 'pending' | 'sold' = 'available',\n        requestOptions: RequestOptions = defReqOpts()\n): Promise\u003cReadonlyArray\u003cPet\u003e\u003e {\n  let query = '';\n  const queryParams = [];\n  queryParams.push(`status=${status}`);\n  if (queryParams.length \u003e 0) {\n    query = '?' + queryParams.join('\u0026');\n  }\n  const request = new Request(`${requestOptions.apiPrefix}/pet/findByStatus${query}`, {\n    method: 'get',\n    body: undefined,\n    headers: {\n      ...option(requestOptions.headers).getOrElseValue({}),\n    }\n  });\n  return requestImpl\u003cPet\u003e(request, requestOptions);\n}\n\n\n// ...\n\n\n\n// scats wrappers\n\n\nexport class PetDto {\n\n  constructor(\n          readonly id: number,\n          readonly name: string,\n          readonly category: CategoryDto,\n          readonly photoUrls: Collection\u003cstring\u003e,\n          readonly tags: Collection\u003cTagDto\u003e,\n          readonly status: string,\n  ) {}\n\n\n  static fromJson(json: Pet): PetDto {\n    return new PetDto(\n            json.id,\n            json.name,\n            CategoryDto.fromJson(json.category),\n            Collection.from(option(json.photoUrls).getOrElseValue([]))\n            ,\n            Collection.from(option(json.tags).getOrElseValue([]))\n                    .map(i =\u003e TagDto.fromJson(i)),\n            json.status,\n    );\n  }\n\n  copy(fields: Partial\u003cPetDto\u003e): PetDto {\n    return new PetDto(\n            option(fields.id).getOrElseValue(this.id),\n            option(fields.name).getOrElseValue(this.name),\n            option(fields.category).getOrElseValue(this.category),\n            option(fields.photoUrls).getOrElseValue(this.photoUrls),\n            option(fields.tags).getOrElseValue(this.tags),\n            option(fields.status).getOrElseValue(this.status),\n    );\n  }\n\n  get toJson(): Pet {\n    return {\n      id: this.id,\n      name: this.name,\n      category: this.category.toJson,\n      photoUrls: this.photoUrls\n              .toArray,\n      tags: this.tags\n              .map(_ =\u003e _.toJson)                .toArray,\n      status: this.status,\n    };\n  }\n}\n\n\nexport class ApiClient {\n\n  constructor(private readonly requestOptions: RequestOptions = defReqOpts()) {\n  }\n\n  // ... some methods skipped\n\n  async updatePet(\n          body: PetDto,\n          requestOptions: RequestOptions = this.requestOptions\n  ): Promise\u003cTryLike\u003cPetDto\u003e\u003e {\n    return (await Try.promise(() =\u003e\n            updatePet(\n                    body.toJson,\n                    requestOptions\n            )\n    ))\n            .map(res =\u003e PetDto.fromJson(res))\n            ;\n  }\n\n  async findPetsByStatus(\n          status: 'available' | 'pending' | 'sold',\n          requestOptions: RequestOptions = this.requestOptions\n  ): Promise\u003cTryLike\u003cCollection\u003cPetDto\u003e\u003e\u003e {\n    return (await Try.promise(() =\u003e\n            findPetsByStatus(\n                    status,\n                    requestOptions\n            )\n    ))\n            .map(res =\u003e Collection.from(option(res).getOrElseValue([])))\n            .map(items =\u003e items.map(i =\u003e PetDto.fromJson(i)))\n            ;\n  }\n\n//...\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapirosko%2Fswagger-code-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpapirosko%2Fswagger-code-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapirosko%2Fswagger-code-gen/lists"}