{"id":15233408,"url":"https://github.com/dyve-agency/ngx-json-gateways","last_synced_at":"2026-01-19T02:32:43.785Z","repository":{"id":38580756,"uuid":"250248799","full_name":"dyve-agency/ngx-json-gateways","owner":"dyve-agency","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-05T17:56:57.000Z","size":977,"stargazers_count":2,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T00:45:00.557Z","etag":null,"topics":["angular","json-schema","json-schema-generator","typescript"],"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/dyve-agency.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}},"created_at":"2020-03-26T12:11:18.000Z","updated_at":"2020-04-17T11:25:27.000Z","dependencies_parsed_at":"2023-02-04T09:16:16.486Z","dependency_job_id":null,"html_url":"https://github.com/dyve-agency/ngx-json-gateways","commit_stats":null,"previous_names":["zeitdev/ngx-json-gateways"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dyve-agency/ngx-json-gateways","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyve-agency%2Fngx-json-gateways","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyve-agency%2Fngx-json-gateways/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyve-agency%2Fngx-json-gateways/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyve-agency%2Fngx-json-gateways/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dyve-agency","download_url":"https://codeload.github.com/dyve-agency/ngx-json-gateways/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyve-agency%2Fngx-json-gateways/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28558233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T00:46:33.223Z","status":"online","status_checked_at":"2026-01-19T02:00:08.049Z","response_time":67,"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":["angular","json-schema","json-schema-generator","typescript"],"created_at":"2024-09-29T05:08:39.236Z","updated_at":"2026-01-19T02:32:43.770Z","avatar_url":"https://github.com/dyve-agency.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"ngx-json-gateways\n=================\n\n![CI](https://github.com/zeitdev/ngx-json-gateways/workflows/CI/badge.svg)\n![npm](https://img.shields.io/npm/v/@zeit-dev/ngx-json-gateways)\n\nGenerate Angular gateways (api client classes) from [JSON Hyper-Schemas](https://json-schema.org/draft/2019-09/json-schema-hypermedia.html)\n\n* Generate fully and strictly typed typescript classes for your schemas.\n* Conventions based but fully customizable\n\nWhat does that mean?\n--------------------\n\nSimple example\n\n##### Input Hyper-Schema\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/hyper-schema\",\n  \"id\": \"simple-get-with-url-params\",\n  \"properties\": {\n    \"get_users\": {\n      \"links\": [{\n        \"href\": \"/users/{id}/{id2}\",\n        \"method\": \"GET\",\n        \"rel\": \"instances\",\n        \"hrefSchema\": {\n          \"properties\": {\n            \"id\": {\n              \"type\": \"integer\"\n            },\n            \"id2\": {\n              \"type\": \"integer\"\n            }\n          }\n        },\n        \"targetSchema\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"required\": [\"name\"],\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"id\": {\n                \"type\": \"integer\"\n              },\n              \"name\": {\n                \"type\": \"string\"\n              }\n            }\n          }\n        }\n      }]\n    }\n  }\n}\n```\n\n##### Output class(es)\n\nGateway:\n```typescript\n/* tslint:disable */\nimport { Observable } from 'rxjs';\nimport { HttpClient } from '@angular/common/http';\nimport { HttpResponse } from '@angular/common/http';\nimport { Inject } from '@angular/core';\nimport { Injectable } from '@angular/core';\nimport { API_HOST } from '../api-host';\nimport { GetUsersByIdById2Response } from './get-users-by-id-by-id2.response';\n@Injectable()\nexport class UsersGateway {\n  constructor(private readonly _httpClient: HttpClient, @Inject(API_HOST) private readonly _apiHost: string) {}\n\n  getUsersByIdById2(\n    id: number,\n    id2: number,\n    options?: Parameters\u003cHttpClient['request']\u003e[2],\n  ): Observable\u003cHttpResponse\u003cGetUsersByIdById2Response\u003e\u003e {\n    return this._httpClient.request('get', this._apiHost + `/users/${id}/${id2}`, {\n      ...options,\n      observe: 'response',\n    });\n  }\n}\n\n```\n\nResponse object:\n```typescript\n/* tslint:disable */\nexport type GetUsersByIdById2Response = {\n  id?: number;\n  name: string;\n}[];\n```\n\nAngular module and `API_HOST` injection token:\n```typescript\n/* tslint:disable */\nimport { NgModule } from '@angular/core';\nimport { ModuleWithProviders } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { HttpClientModule } from '@angular/common/http';\nimport { API_HOST } from './api-host';\nimport { UsersGateway } from './users/users.gateway';\n@NgModule({\n  imports: [CommonModule, HttpClientModule],\n  providers: [UsersGateway],\n})\nexport class ApiModule {\n  static forRoot(apiHost: string): ModuleWithProviders\u003cApiModule\u003e {\n    return {\n      ngModule: ApiModule,\n      providers: [{ provide: API_HOST, useValue: apiHost }],\n    };\n  }\n}\n```\n\n```typescript\n/* tslint:disable */\nimport { InjectionToken } from '@angular/core';\nexport const API_HOST = new InjectionToken('API HOST');\n```\n\nSee the `examples/` folder for more examples.\n\nGet Started\n-----------\n\n#### Install\n```shell script\nnpm install -D @zeit-dev/ngx-json-gateways\n```\n\nor\n```shell script\nyarn install -D @zeit-dev/ngx-json-gateways\n```\n\n#### Config\n\nAdd a file named `json-gateways.config.js` to your project's root folder:\n```javascript\nconst defaultOptions = require('@zeit-dev/ngx-json-gateways/dist/defaults').defaultOptions;\n\nmodule.exports = [\n  {\n    ...defaultOptions,\n  \n    schemaFile: 'schema/users_api/schema.json',\n    moduleName: 'UsersApi',\n    localSources: [\n      // Load `$ref`erenced definitions from these locations. Use standard glob patterns.\n      'schema/definitions/**/*.json'\n    ],\n    // Make the gateway return naked payloads. Change to `response` to return\n    // `HttpResonse\u003cGetUserResponse\u003e`\n    returnType: 'body',\n    json2ts: {\n      // Additional options for json-schema-to-typescript\n      ...defaultOptions.json2ts,\n      unreachableDefinitions: true,\n      style: {\n        // Configure prettier to your needs\n        ...defaultOptions.json2ts.style,\n        bracketSpacing: false,\n      }\n    }\n  },\n  // ... add more configs if needed\n];\n\n```\n\n#### Include in your build process\n\nAdd to your project's package.json sth like\n```json\n{\n  \"scripts\": {\n    \"generate:gateways\": \"ngx-json-gateways -c json-gateways.config.js -o src/app/backend\",\n    \"prebuild\": \"yarn run generate:gateways\"\n  } \n}\n```\n\nAnd add `src/app/backend` to your `.gitignore`!\n\n#### Initialize module\n\napp.module.ts\n```typescript\n@NgModule({\n  imports: [\n    // ...\n    UsersApiModule.forRoot('https://myapi.example.org/something')\n  \n    // ...\n  ]\n})\n// ...\n```\n\nFAQ\n---\n\n### Why shouldn't I commit the generated classes to my vcs (git)?\n\nThe generated classes are artefacts of the schemas, and should therefore not be included\nin the repository. \nWe recommend adding the generation step to your build process and CI. This has the advantage,\nthat the gateways will never be out-of-date if your schemas change. And more important:\nIf your schemas (api) introduces breaking changes, your build will just fail, and you can\nfix it.\n\n### Aren't Hyper-Schemas the wrong tool for the job?\n\nYes, but we find them useful.\n\n### I need a dynamic `API_HOST`\n\nJust import `MyApiModule` (remove `forRoot`), and provide the `API_HOST` yourself, e.g.\n```typescript\n    { provide: API_HOST, useFactory: getApiHost }\n```\n\n### Does it support `$ref`s?\n\nYes, all `$ref`s are resolved using [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser).\nAt the moment only one method of resolving is supported:  \nSupply a list of referencable schema files (or globbing patterns) with `id`s, and these are\nresolved by their `id`.\n\nIf you need more, contact us or open a PR.\n\n### How can I change the conventions?\n\nAll conventions are set using pure functions defined in the `GeneratorOptions` interface. \nIn order to change these, you have to overwrite these functions in your configuration, e.g.\n\n```javascript\nconst defaultOptions = require('@zeit-dev/ngx-json-gateways/dist/defaults').defaultOptions;\n\nmodule.exports = [\n  {\n    ...defaultOptions,\n  \n    // ... all the other options\n    \n    getTargetPath: ({nameOfClass}) =\u003e [nameOfClass]\n  },\n  // ... add more configs if needed\n];\n```\n\nJust look at `src/defaults.ts` for the current implementations and how to customize.\n\nTODOs\n-----\n\n* Better test coverage\n* Inline code documentation\n* Usage documentation\n* Customization documentation\n* Common secondary types (e.g. a `User` definition that is referenced by different requests/responses),\n  at the moment duplicates are generated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyve-agency%2Fngx-json-gateways","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdyve-agency%2Fngx-json-gateways","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyve-agency%2Fngx-json-gateways/lists"}