ngx-openapi-typescript 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ngx-openapi-typescript.mjs","sources":["../../../projects/ngx-openapi-typescript/src/lib/url-utils.ts","../../../projects/ngx-openapi-typescript/src/lib/open-api-resource.ts","../../../projects/ngx-openapi-typescript/src/lib/open-api-http-client.ts","../../../projects/ngx-openapi-typescript/src/public-api.ts","../../../projects/ngx-openapi-typescript/src/ngx-openapi-typescript.ts"],"sourcesContent":["import { HttpParams } from '@angular/common/http';\r\n\r\n/** Builds a full URL by substituting path parameters into the path template */\r\nexport function buildUrl(\r\n baseUrl: string,\r\n path: string,\r\n pathParams?: Record<string, string | number | boolean>,\r\n): string {\r\n let url = baseUrl + path;\r\n if (pathParams) {\r\n for (const [key, value] of Object.entries(pathParams)) {\r\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\r\n }\r\n }\r\n return url;\r\n}\r\n\r\n/** Converts a query parameter map to an `HttpParams` instance */\r\nexport function toHttpParams(\r\n query?: Record<\r\n string,\r\n string | number | boolean | ReadonlyArray<string | number | boolean> | null | undefined\r\n >,\r\n): HttpParams | undefined {\r\n if (!query) return undefined;\r\n let params = new HttpParams();\r\n for (const [key, value] of Object.entries(query)) {\r\n if (value === undefined || value === null) continue;\r\n if (Array.isArray(value)) {\r\n for (const v of value) {\r\n params = params.append(key, String(v));\r\n }\r\n } else {\r\n params = params.set(key, String(value));\r\n }\r\n }\r\n return params;\r\n}\r\n","import {\r\n HttpContext,\r\n HttpHeaders,\r\n HttpResourceOptions,\r\n HttpResourceRef,\r\n httpResource,\r\n} from '@angular/common/http';\r\nimport type { PathsWithMethod, SuccessResponseJSON } from 'openapi-typescript-helpers';\r\nimport type { HasRequiredKeys, HttpMethod, OpenApiOperationRequest, PathRecord } from './types';\r\nimport { buildUrl as _buildUrl, toHttpParams as _toHttpParams } from './url-utils';\r\n\r\n// Re-export helpers so consumers and tests can import them from this module.\r\nexport { buildUrl, toHttpParams } from './url-utils';\r\n\r\n/** Configuration for creating an OpenAPI resource factory */\r\nexport interface OpenApiResourceConfig {\r\n /** Base URL to prepend to all resource paths */\r\n baseUrl?: string;\r\n}\r\n\r\n/** Options for the resource call, extending Angular's HttpResourceOptions with an optional HTTP method */\r\nexport type OpenApiResourceCallOptions<TValue, TError = unknown> = HttpResourceOptions<\r\n TValue,\r\n TError\r\n> & { method?: HttpMethod };\r\n\r\n/** Extracts the operation type for a given path and method */\r\ntype OpOf<Paths, Path extends keyof Paths, Method extends string> = Paths[Path] extends {\r\n [K in Method]: infer Op;\r\n}\r\n ? Op\r\n : never;\r\n\r\n/** Coerces the request object to a plain shape for URL building */\r\nfunction toRequestShape(req: unknown): {\r\n params?: {\r\n path?: Record<string, string | number | boolean>;\r\n query?: Record<string, string | number | boolean | null | undefined>;\r\n };\r\n body?: unknown;\r\n headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;\r\n context?: HttpContext;\r\n withCredentials?: boolean;\r\n} {\r\n return ((req ?? {}) as ReturnType<typeof toRequestShape>);\r\n}\r\n\r\n/** Extract which HTTP methods a given path supports */\r\ntype MethodsOfPath<Paths, Path extends keyof Paths> = {\r\n [M in HttpMethod]: Paths[Path] extends { [K in M]: unknown } ? M : never;\r\n}[HttpMethod];\r\n\r\n/**\r\n * Narrows to only those paths (for the given method) where the full request object\r\n * has no required keys — i.e. `requestFn` can be safely omitted.\r\n */\r\ntype PathsWithOptionalRequest<Paths extends PathRecord, Method extends HttpMethod> = {\r\n [P in PathsWithMethod<Paths, Method> & keyof Paths]: HasRequiredKeys<\r\n OpenApiOperationRequest<NonNullable<OpOf<Paths, P, Method>>>\r\n > extends true\r\n ? never\r\n : P;\r\n}[PathsWithMethod<Paths, Method> & keyof Paths];\r\n\r\n/** The callable type returned by `createOpenApiResource` */\r\nexport interface OpenApiResource<Paths extends PathRecord> {\r\n /**\r\n * Creates a reactive resource for an OpenAPI endpoint with an explicit HTTP method.\r\n *\r\n * The `method` option is restricted to the methods the given path supports.\r\n */\r\n <Path extends keyof Paths & string, Method extends MethodsOfPath<Paths, Path>>(\r\n path: Path,\r\n requestFn: () => OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, Method>>> | undefined,\r\n options: OpenApiResourceCallOptions<\r\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>>,\r\n unknown\r\n > & { method: Method },\r\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>> | undefined>;\r\n\r\n /**\r\n * Creates a reactive GET resource for an OpenAPI endpoint (default).\r\n *\r\n * The resource re-fetches automatically when the signals read inside `requestFn` change.\r\n * When `requestFn` returns `undefined` the resource is put into the Idle state.\r\n */\r\n <Path extends PathsWithMethod<Paths, 'get'> & keyof Paths>(\r\n path: Path,\r\n requestFn: () => OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined,\r\n options?: HttpResourceOptions<\r\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>,\r\n unknown\r\n >,\r\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined>;\r\n\r\n /**\r\n * Creates a reactive resource for an OpenAPI endpoint with an explicit HTTP method,\r\n * omitting `requestFn`. Only available when the operation has no required parameters or body.\r\n */\r\n <Path extends keyof Paths & string, Method extends MethodsOfPath<Paths, Path>>(\r\n path: Path extends PathsWithOptionalRequest<Paths, Method> ? Path : never,\r\n options: OpenApiResourceCallOptions<\r\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>>,\r\n unknown\r\n > & { method: Method },\r\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>> | undefined>;\r\n\r\n /**\r\n * Creates a reactive GET resource for an OpenAPI endpoint, omitting `requestFn`.\r\n * Only available when the operation has no required parameters or body.\r\n * The resource fetches immediately and always stays active.\r\n */\r\n <Path extends PathsWithOptionalRequest<Paths, 'get'>>(\r\n path: Path,\r\n options?: HttpResourceOptions<\r\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>,\r\n unknown\r\n >,\r\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined>;\r\n}\r\n\r\n/**\r\n * Creates a type-safe callable factory for Angular `httpResource`s backed by an OpenAPI schema.\r\n *\r\n * Must be called inside an Angular injection context (e.g. component/service field initializer\r\n * or constructor), because the returned function uses `httpResource` internally.\r\n *\r\n * The returned function defaults to GET. Pass `{ method: 'post' }` (or other method) in the\r\n * options to use a different HTTP method. Note: Angular recommends using `httpResource` only\r\n * for reads; prefer `OpenApiHttpClient` for mutations.\r\n *\r\n * @example\r\n * ```ts\r\n * import type { paths } from './api.types'; // generated by openapi-typescript\r\n *\r\n * const api = createOpenApiResource<paths>({ baseUrl: 'https://api.example.com' });\r\n *\r\n * // Reactive GET resource (default)\r\n * const pets = api('/pets', () => ({ params: { query: { limit: 10 } } }));\r\n *\r\n * // GET with path params (signal-driven)\r\n * const petId = signal(1);\r\n * const pet = api('/pets/{petId}', () => ({ params: { path: { petId: petId() } } }));\r\n *\r\n * // Explicit method override (prefer OpenApiHttpClient for mutations)\r\n * const created = api('/pets', () => ({ body: { name: 'Buddy' } }), { method: 'post' });\r\n * ```\r\n */\r\nexport function createOpenApiResource<Paths extends PathRecord>(\r\n config?: OpenApiResourceConfig,\r\n): OpenApiResource<Paths> {\r\n const baseUrl = config?.baseUrl ?? '';\r\n\r\n return ((\r\n path: string,\r\n reqFnOrOpts?: (() => unknown) | OpenApiResourceCallOptions<unknown>,\r\n maybeOpts?: OpenApiResourceCallOptions<unknown>,\r\n ) => {\r\n const hasRequestFn = typeof reqFnOrOpts === 'function';\r\n const requestFn = hasRequestFn ? reqFnOrOpts : () => ({});\r\n const options = hasRequestFn ? maybeOpts : (reqFnOrOpts as OpenApiResourceCallOptions<unknown> | undefined);\r\n const method = (options?.method ?? 'get').toUpperCase();\r\n\r\n return httpResource(\r\n () => {\r\n const req = requestFn();\r\n if (req === undefined) return undefined;\r\n const r = toRequestShape(req);\r\n return {\r\n url: _buildUrl(baseUrl, path, r.params?.path),\r\n method,\r\n body: r.body,\r\n params: _toHttpParams(r.params?.query),\r\n headers: r.headers,\r\n context: r.context,\r\n withCredentials: r.withCredentials,\r\n };\r\n },\r\n options,\r\n );\r\n }) as OpenApiResource<Paths>;\r\n}\r\n","import { HttpClient, HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';\r\nimport { inject } from '@angular/core';\r\nimport type { Observable } from 'rxjs';\r\nimport type {\r\n PathsWithMethod,\r\n RequestBodyJSON,\r\n SuccessResponseJSON,\r\n} from 'openapi-typescript-helpers';\r\nimport type {\r\n OpenApiOperationRequest,\r\n PathRecord,\r\n} from './types';\r\nimport { buildUrl, toHttpParams } from './url-utils';\r\n\r\n/** Configuration for `OpenApiHttpClient` */\r\nexport interface OpenApiHttpClientConfig {\r\n /** Base URL to prepend to all request paths */\r\n baseUrl?: string;\r\n}\r\n\r\n/** Extracts the operation type for a given path and method */\r\ntype OpOf<Paths, Path extends keyof Paths, Method extends string> = Paths[Path] extends {\r\n [K in Method]: infer Op;\r\n}\r\n ? Op\r\n : never;\r\n\r\n/** Coerces the options to a plain shape */\r\nfunction toShape(opts: unknown): {\r\n params?: {\r\n path?: Record<string, string | number | boolean>;\r\n query?: Record<string, string | number | boolean | null | undefined>;\r\n };\r\n body?: unknown;\r\n headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;\r\n context?: HttpContext;\r\n withCredentials?: boolean;\r\n} {\r\n return ((opts ?? {}) as ReturnType<typeof toShape>);\r\n}\r\n\r\nfunction buildOptions(r: ReturnType<typeof toShape>): {\r\n responseType: 'json';\r\n observe: 'body';\r\n params?: HttpParams;\r\n headers?: HttpHeaders | Record<string, string | string[]>;\r\n context?: HttpContext;\r\n withCredentials?: boolean;\r\n} {\r\n return {\r\n responseType: 'json',\r\n observe: 'body',\r\n params: toHttpParams(r.params?.query),\r\n // Cast needed: our public API allows ReadonlyArray<string> (consistent with httpResource),\r\n // but Angular HttpClient methods require string[].\r\n headers: r.headers as HttpHeaders | Record<string, string | string[]> | undefined,\r\n context: r.context,\r\n withCredentials: r.withCredentials,\r\n };\r\n}\r\n\r\n/**\r\n * A type-safe HTTP client for OpenAPI-described APIs.\r\n *\r\n * Wraps Angular's `HttpClient` and binds request/response types to an OpenAPI\r\n * schema generated by `openapi-typescript`.\r\n *\r\n * Designed to be subclassed per-API:\r\n *\r\n * @example\r\n * ```ts\r\n * import type { paths } from './api.types'; // generated by openapi-typescript\r\n *\r\n * @Injectable({ providedIn: 'root' })\r\n * export class PetApiClient extends OpenApiHttpClient<paths> {\r\n * constructor() {\r\n * super({ baseUrl: 'https://api.example.com' });\r\n * }\r\n * }\r\n * ```\r\n *\r\n * Or used directly inside an injection context:\r\n *\r\n * @example\r\n * ```ts\r\n * const client = new OpenApiHttpClient<paths>({ baseUrl: 'https://api.example.com' });\r\n * ```\r\n */\r\nexport class OpenApiHttpClient<Paths extends PathRecord> {\r\n private readonly http = inject(HttpClient);\r\n private readonly baseUrl: string;\r\n\r\n constructor(config?: OpenApiHttpClientConfig) {\r\n this.baseUrl = config?.baseUrl ?? '';\r\n }\r\n\r\n /**\r\n * Performs a typed GET request.\r\n *\r\n * @example\r\n * ```ts\r\n * client.get('/pets', { params: { query: { limit: 10 } } }).subscribe(pets => console.log(pets));\r\n * ```\r\n */\r\n get<Path extends PathsWithMethod<Paths, 'get'> & keyof Paths>(\r\n path: Path,\r\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'get'>>>,\r\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>> {\r\n const r = toShape(options);\r\n return this.http.get<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>>(\r\n buildUrl(this.baseUrl, String(path), r.params?.path),\r\n buildOptions(r),\r\n );\r\n }\r\n\r\n /**\r\n * Performs a typed POST request.\r\n */\r\n post<Path extends PathsWithMethod<Paths, 'post'> & keyof Paths>(\r\n path: Path,\r\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'post'>>>,\r\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'post'>>>> {\r\n const r = toShape(options);\r\n return this.http.post<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'post'>>>>(\r\n buildUrl(this.baseUrl, String(path), r.params?.path),\r\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'post'>>>,\r\n buildOptions(r),\r\n );\r\n }\r\n\r\n /**\r\n * Performs a typed PUT request.\r\n */\r\n put<Path extends PathsWithMethod<Paths, 'put'> & keyof Paths>(\r\n path: Path,\r\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'put'>>>,\r\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'put'>>>> {\r\n const r = toShape(options);\r\n return this.http.put<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'put'>>>>(\r\n buildUrl(this.baseUrl, String(path), r.params?.path),\r\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'put'>>>,\r\n buildOptions(r),\r\n );\r\n }\r\n\r\n /**\r\n * Performs a typed PATCH request.\r\n */\r\n patch<Path extends PathsWithMethod<Paths, 'patch'> & keyof Paths>(\r\n path: Path,\r\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'patch'>>>,\r\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>> {\r\n const r = toShape(options);\r\n return this.http.patch<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>>(\r\n buildUrl(this.baseUrl, String(path), r.params?.path),\r\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>,\r\n buildOptions(r),\r\n );\r\n }\r\n\r\n /**\r\n * Performs a typed DELETE request.\r\n */\r\n delete<Path extends PathsWithMethod<Paths, 'delete'> & keyof Paths>(\r\n path: Path,\r\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'delete'>>>,\r\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>> {\r\n const r = toShape(options);\r\n const httpOptions = buildOptions(r) as { body?: unknown } & ReturnType<typeof buildOptions>;\r\n\r\n if (r.body !== undefined) {\r\n httpOptions.body = r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>;\r\n }\r\n\r\n return this.http.delete<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>>(\r\n buildUrl(this.baseUrl, String(path), r.params?.path),\r\n httpOptions,\r\n );\r\n }\r\n}\r\n","/*\r\n * Public API Surface of ngx-openapi-typescript\r\n */\r\n\r\nexport { createOpenApiResource } from './lib/open-api-resource';\r\nexport type {\r\n OpenApiResource, OpenApiResourceCallOptions, OpenApiResourceConfig\r\n} from './lib/open-api-resource';\r\n\r\nexport { OpenApiHttpClient } from './lib/open-api-http-client';\r\nexport type { OpenApiHttpClientConfig } from './lib/open-api-http-client';\r\n\r\nexport type {\r\n HasRequiredKeys,\r\n HttpMethod, OpenApiOperationRequest,\r\n OpenApiRequestOptions, OperationBody, OperationParamsObject, PathParameters, PathRecord, PathsWithMethod, QueryParameters, RequestBodyJSON, SuccessResponseJSON\r\n} from './lib/types';\r\n\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["_buildUrl","_toHttpParams"],"mappings":";;;AAEA;SACgB,QAAQ,CACtB,OAAe,EACf,IAAY,EACZ,UAAsD,EAAA;AAEtD,IAAA,IAAI,GAAG,GAAG,OAAO,GAAG,IAAI;IACxB,IAAI,UAAU,EAAE;AACd,QAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,GAAG,CAAC,OAA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,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EACpD,CAAC,CAAC,IAAgE,EAClE,YAAY,CAAC,CAAC,CAAC,CAChB;IACH;AAEA;;AAEG;IACH,MAAM,CACJ,IAAU,EACV,OAA2E,EAAA;AAE3E,QAAA,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;AAC1B,QAAA,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAyD;AAE3F,QAAA,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE;AACxB,YAAA,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC,IAAiE;QACxF;QAEA,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CACrB,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EACpD,WAAW,CACZ;IACH;AACD;;ACnLD;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngx-openapi-typescript.mjs","sources":["../../../projects/ngx-openapi-typescript/src/lib/url-utils.ts","../../../projects/ngx-openapi-typescript/src/lib/open-api-resource.ts","../../../projects/ngx-openapi-typescript/src/lib/open-api-http-client.ts","../../../projects/ngx-openapi-typescript/src/public-api.ts","../../../projects/ngx-openapi-typescript/src/ngx-openapi-typescript.ts"],"sourcesContent":["import { HttpParams } from '@angular/common/http';\n\n/** Builds a full URL by substituting path parameters into the path template */\nexport function buildUrl(\n baseUrl: string,\n path: string,\n pathParams?: Record<string, string | number | boolean>,\n): string {\n let url = baseUrl + path;\n if (pathParams) {\n for (const [key, value] of Object.entries(pathParams)) {\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n }\n }\n return url;\n}\n\n/** Converts a query parameter map to an `HttpParams` instance */\nexport function toHttpParams(\n query?: Record<\n string,\n string | number | boolean | ReadonlyArray<string | number | boolean> | null | undefined\n >,\n): HttpParams | undefined {\n if (!query) return undefined;\n let params = new HttpParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n if (Array.isArray(value)) {\n for (const v of value) {\n params = params.append(key, String(v));\n }\n } else {\n params = params.set(key, String(value));\n }\n }\n return params;\n}\n","import {\n HttpContext,\n HttpHeaders,\n HttpResourceOptions,\n HttpResourceRef,\n httpResource,\n} from '@angular/common/http';\nimport type { PathsWithMethod, SuccessResponseJSON } from 'openapi-typescript-helpers';\nimport type { HasRequiredKeys, HttpMethod, OpenApiOperationRequest, PathRecord } from './types';\nimport { buildUrl as _buildUrl, toHttpParams as _toHttpParams } from './url-utils';\n\n// Re-export helpers so consumers and tests can import them from this module.\nexport { buildUrl, toHttpParams } from './url-utils';\n\n/** Configuration for creating an OpenAPI resource factory */\nexport interface OpenApiResourceConfig {\n /** Base URL to prepend to all resource paths */\n baseUrl?: string;\n}\n\n/** Options for the resource call, extending Angular's HttpResourceOptions with an optional HTTP method */\nexport type OpenApiResourceCallOptions<TValue, TError = unknown> = HttpResourceOptions<\n TValue,\n TError\n> & { method?: HttpMethod };\n\n/** Extracts the operation type for a given path and method */\ntype OpOf<Paths, Path extends keyof Paths, Method extends string> = Paths[Path] extends {\n [K in Method]: infer Op;\n}\n ? Op\n : never;\n\n/** Coerces the request object to a plain shape for URL building */\nfunction toRequestShape(req: unknown): {\n params?: {\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean | null | undefined>;\n };\n body?: unknown;\n headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;\n context?: HttpContext;\n withCredentials?: boolean;\n} {\n return ((req ?? {}) as ReturnType<typeof toRequestShape>);\n}\n\n/** Extract which HTTP methods a given path supports */\ntype MethodsOfPath<Paths, Path extends keyof Paths> = {\n [M in HttpMethod]: Paths[Path] extends { [K in M]: unknown } ? M : never;\n}[HttpMethod];\n\n/**\n * Narrows to only those paths (for the given method) where the full request object\n * has no required keys — i.e. `requestFn` can be safely omitted.\n */\ntype PathsWithOptionalRequest<Paths extends PathRecord, Method extends HttpMethod> = {\n [P in PathsWithMethod<Paths, Method> & keyof Paths]: HasRequiredKeys<\n OpenApiOperationRequest<NonNullable<OpOf<Paths, P, Method>>>\n > extends true\n ? never\n : P;\n}[PathsWithMethod<Paths, Method> & keyof Paths];\n\n/** The callable type returned by `createOpenApiResource` */\nexport interface OpenApiResource<Paths extends PathRecord> {\n /**\n * Creates a reactive resource for an OpenAPI endpoint with an explicit HTTP method.\n *\n * The `method` option is restricted to the methods the given path supports.\n */\n <Path extends keyof Paths & string, Method extends MethodsOfPath<Paths, Path>>(\n path: Path,\n requestFn: () => OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, Method>>> | undefined,\n options: OpenApiResourceCallOptions<\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>>,\n unknown\n > & { method: Method },\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>> | undefined>;\n\n /**\n * Creates a reactive GET resource for an OpenAPI endpoint (default).\n *\n * The resource re-fetches automatically when the signals read inside `requestFn` change.\n * When `requestFn` returns `undefined` the resource is put into the Idle state.\n */\n <Path extends PathsWithMethod<Paths, 'get'> & keyof Paths>(\n path: Path,\n requestFn: () => OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined,\n options?: HttpResourceOptions<\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>,\n unknown\n >,\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined>;\n\n /**\n * Creates a reactive resource for an OpenAPI endpoint with an explicit HTTP method,\n * omitting `requestFn`. Only available when the operation has no required parameters or body.\n */\n <Path extends keyof Paths & string, Method extends MethodsOfPath<Paths, Path>>(\n path: Path extends PathsWithOptionalRequest<Paths, Method> ? Path : never,\n options: OpenApiResourceCallOptions<\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>>,\n unknown\n > & { method: Method },\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, Method>>> | undefined>;\n\n /**\n * Creates a reactive GET resource for an OpenAPI endpoint, omitting `requestFn`.\n * Only available when the operation has no required parameters or body.\n * The resource fetches immediately and always stays active.\n */\n <Path extends PathsWithOptionalRequest<Paths, 'get'>>(\n path: Path,\n options?: HttpResourceOptions<\n SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>,\n unknown\n >,\n ): HttpResourceRef<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>> | undefined>;\n}\n\n/**\n * Creates a type-safe callable factory for Angular `httpResource`s backed by an OpenAPI schema.\n *\n * Must be called inside an Angular injection context (e.g. component/service field initializer\n * or constructor), because the returned function uses `httpResource` internally.\n *\n * The returned function defaults to GET. Pass `{ method: 'post' }` (or other method) in the\n * options to use a different HTTP method. Note: Angular recommends using `httpResource` only\n * for reads; prefer `OpenApiHttpClient` for mutations.\n *\n * @example\n * ```ts\n * import type { paths } from './api.types'; // generated by openapi-typescript\n *\n * const api = createOpenApiResource<paths>({ baseUrl: 'https://api.example.com' });\n *\n * // Reactive GET resource (default)\n * const pets = api('/pets', () => ({ params: { query: { limit: 10 } } }));\n *\n * // GET with path params (signal-driven)\n * const petId = signal(1);\n * const pet = api('/pets/{petId}', () => ({ params: { path: { petId: petId() } } }));\n *\n * // Explicit method override (prefer OpenApiHttpClient for mutations)\n * const created = api('/pets', () => ({ body: { name: 'Buddy' } }), { method: 'post' });\n * ```\n */\nexport function createOpenApiResource<Paths extends PathRecord>(\n config?: OpenApiResourceConfig,\n): OpenApiResource<Paths> {\n const baseUrl = config?.baseUrl ?? '';\n\n return ((\n path: string,\n reqFnOrOpts?: (() => unknown) | OpenApiResourceCallOptions<unknown>,\n maybeOpts?: OpenApiResourceCallOptions<unknown>,\n ) => {\n const hasRequestFn = typeof reqFnOrOpts === 'function';\n const requestFn = hasRequestFn ? reqFnOrOpts : () => ({});\n const options = hasRequestFn ? maybeOpts : (reqFnOrOpts as OpenApiResourceCallOptions<unknown> | undefined);\n const method = (options?.method ?? 'get').toUpperCase();\n\n return httpResource(\n () => {\n const req = requestFn();\n if (req === undefined) return undefined;\n const r = toRequestShape(req);\n return {\n url: _buildUrl(baseUrl, path, r.params?.path),\n method,\n body: r.body,\n params: _toHttpParams(r.params?.query),\n headers: r.headers,\n context: r.context,\n withCredentials: r.withCredentials,\n };\n },\n options,\n );\n }) as OpenApiResource<Paths>;\n}\n","import { HttpClient, HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport type { Observable } from 'rxjs';\nimport type {\n PathsWithMethod,\n RequestBodyJSON,\n SuccessResponseJSON,\n} from 'openapi-typescript-helpers';\nimport type {\n OpenApiOperationRequest,\n PathRecord,\n} from './types';\nimport { buildUrl, toHttpParams } from './url-utils';\n\n/** Configuration for `OpenApiHttpClient` */\nexport interface OpenApiHttpClientConfig {\n /** Base URL to prepend to all request paths */\n baseUrl?: string;\n}\n\n/** Extracts the operation type for a given path and method */\ntype OpOf<Paths, Path extends keyof Paths, Method extends string> = Paths[Path] extends {\n [K in Method]: infer Op;\n}\n ? Op\n : never;\n\n/** Coerces the options to a plain shape */\nfunction toShape(opts: unknown): {\n params?: {\n path?: Record<string, string | number | boolean>;\n query?: Record<string, string | number | boolean | null | undefined>;\n };\n body?: unknown;\n headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;\n context?: HttpContext;\n withCredentials?: boolean;\n} {\n return ((opts ?? {}) as ReturnType<typeof toShape>);\n}\n\nfunction buildOptions(r: ReturnType<typeof toShape>): {\n responseType: 'json';\n observe: 'body';\n params?: HttpParams;\n headers?: HttpHeaders | Record<string, string | string[]>;\n context?: HttpContext;\n withCredentials?: boolean;\n} {\n return {\n responseType: 'json',\n observe: 'body',\n params: toHttpParams(r.params?.query),\n // Cast needed: our public API allows ReadonlyArray<string> (consistent with httpResource),\n // but Angular HttpClient methods require string[].\n headers: r.headers as HttpHeaders | Record<string, string | string[]> | undefined,\n context: r.context,\n withCredentials: r.withCredentials,\n };\n}\n\n/**\n * A type-safe HTTP client for OpenAPI-described APIs.\n *\n * Wraps Angular's `HttpClient` and binds request/response types to an OpenAPI\n * schema generated by `openapi-typescript`.\n *\n * Designed to be subclassed per-API:\n *\n * @example\n * ```ts\n * import type { paths } from './api.types'; // generated by openapi-typescript\n *\n * @Injectable({ providedIn: 'root' })\n * export class PetApiClient extends OpenApiHttpClient<paths> {\n * constructor() {\n * super({ baseUrl: 'https://api.example.com' });\n * }\n * }\n * ```\n *\n * Or used directly inside an injection context:\n *\n * @example\n * ```ts\n * const client = new OpenApiHttpClient<paths>({ baseUrl: 'https://api.example.com' });\n * ```\n */\nexport class OpenApiHttpClient<Paths extends PathRecord> {\n private readonly http = inject(HttpClient);\n private readonly baseUrl: string;\n\n constructor(config?: OpenApiHttpClientConfig) {\n this.baseUrl = config?.baseUrl ?? '';\n }\n\n /**\n * Performs a typed GET request.\n *\n * @example\n * ```ts\n * client.get('/pets', { params: { query: { limit: 10 } } }).subscribe(pets => console.log(pets));\n * ```\n */\n get<Path extends PathsWithMethod<Paths, 'get'> & keyof Paths>(\n path: Path,\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'get'>>>,\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>> {\n const r = toShape(options);\n return this.http.get<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'get'>>>>(\n buildUrl(this.baseUrl, String(path), r.params?.path),\n buildOptions(r),\n );\n }\n\n /**\n * Performs a typed POST request.\n */\n post<Path extends PathsWithMethod<Paths, 'post'> & keyof Paths>(\n path: Path,\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'post'>>>,\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'post'>>>> {\n const r = toShape(options);\n return this.http.post<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'post'>>>>(\n buildUrl(this.baseUrl, String(path), r.params?.path),\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'post'>>>,\n buildOptions(r),\n );\n }\n\n /**\n * Performs a typed PUT request.\n */\n put<Path extends PathsWithMethod<Paths, 'put'> & keyof Paths>(\n path: Path,\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'put'>>>,\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'put'>>>> {\n const r = toShape(options);\n return this.http.put<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'put'>>>>(\n buildUrl(this.baseUrl, String(path), r.params?.path),\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'put'>>>,\n buildOptions(r),\n );\n }\n\n /**\n * Performs a typed PATCH request.\n */\n patch<Path extends PathsWithMethod<Paths, 'patch'> & keyof Paths>(\n path: Path,\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'patch'>>>,\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>> {\n const r = toShape(options);\n return this.http.patch<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>>(\n buildUrl(this.baseUrl, String(path), r.params?.path),\n r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'patch'>>>,\n buildOptions(r),\n );\n }\n\n /**\n * Performs a typed DELETE request.\n */\n delete<Path extends PathsWithMethod<Paths, 'delete'> & keyof Paths>(\n path: Path,\n options?: OpenApiOperationRequest<NonNullable<OpOf<Paths, Path, 'delete'>>>,\n ): Observable<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>> {\n const r = toShape(options);\n const httpOptions = buildOptions(r) as { body?: unknown } & ReturnType<typeof buildOptions>;\n\n if (r.body !== undefined) {\n httpOptions.body = r.body as RequestBodyJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>;\n }\n\n return this.http.delete<SuccessResponseJSON<NonNullable<OpOf<Paths, Path, 'delete'>>>>(\n buildUrl(this.baseUrl, String(path), r.params?.path),\n httpOptions,\n );\n }\n}\n","/*\n * Public API Surface of ngx-openapi-typescript\n */\n\nexport { createOpenApiResource } from './lib/open-api-resource';\nexport type {\n OpenApiResource, OpenApiResourceCallOptions, OpenApiResourceConfig\n} from './lib/open-api-resource';\n\nexport { OpenApiHttpClient } from './lib/open-api-http-client';\nexport type { OpenApiHttpClientConfig } from './lib/open-api-http-client';\n\nexport type {\n HasRequiredKeys,\n HttpMethod, OpenApiOperationRequest,\n OpenApiRequestOptions, OperationBody, OperationParamsObject, PathParameters, PathRecord, PathsWithMethod, QueryParameters, RequestBodyJSON, SuccessResponseJSON\n} from './lib/types';\n\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["_buildUrl","_toHttpParams"],"mappings":";;;AAEA;SACgB,QAAQ,CACtB,OAAe,EACf,IAAY,EACZ,UAAsD,EAAA;AAEtD,IAAA,IAAI,GAAG,GAAG,OAAO,GAAG,IAAI;IACxB,IAAI,UAAU,EAAE;AACd,QAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAA,CAAA,CAAG,EAAE,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClE;IACF;AACA,IAAA,OAAO,GAAG;AACZ;AAEA;AACM,SAAU,YAAY,CAC1B,KAGC,EAAA;AAED,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,OAAO,SAAS;AAC5B,IAAA,IAAI,MAAM,GAAG,IAAI,UAAU,EAAE;AAC7B,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AAChD,QAAA,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE;AAC3C,QAAA,IAAI,KAAK,CA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MAAM,CACrB,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EACpD,WAAW,CACZ;IACH;AACD;;ACnLD;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "ngx-openapi-typescript",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
+ "description": "Type-safe Angular httpResource and HttpClient backed by openapi-typescript",
5
+ "keywords": [
6
+ "angular",
7
+ "openapi",
8
+ "typescript",
9
+ "http-client",
10
+ "signals",
11
+ "type-safe",
12
+ "resource",
13
+ "reactive"
14
+ ],
15
+ "author": {
16
+ "name": "Marvin Luchs",
17
+ "email": "marvin.luchs@holisticon.de"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/holisticon/ngx-openapi-typescript"
22
+ },
23
+ "homepage": "https://github.com/holisticon/ngx-openapi-typescript",
24
+ "bugs": {
25
+ "url": "https://github.com/holisticon/ngx-openapi-typescript/issues"
26
+ },
4
27
  "peerDependencies": {
5
28
  "@angular/common": "^21.2.0 || ^22.0.0",
6
29
  "@angular/core": "^21.2.0 || ^22.0.0",
package/README.md DELETED
@@ -1,139 +0,0 @@
1
- # ngx-openapi-typescript
2
-
3
- Type-safe Angular resource signals and HTTP client backed by [openapi-typescript](https://openapi-ts.dev/).
4
-
5
- This library provides two main utilities:
6
-
7
- - **`createOpenApiResource`** — a reactive factory built on Angular's `httpResource` that gives you compile-time type safety for every HTTP request and response shape defined in your OpenAPI schema.
8
- - **`OpenApiHttpClient`** — a typed wrapper around Angular's `HttpClient` for imperative (non-reactive) HTTP calls.
9
-
10
- Both are driven by the types generated by `openapi-typescript`, so typos in paths, wrong parameter names, or incorrect body shapes are caught at **compile time**, not at runtime.
11
-
12
- ## Installation
13
-
14
- ```sh
15
- npm install ngx-openapi-typescript openapi-typescript-helpers
16
- ```
17
-
18
- This package is built for Angular `^21.2.0` and `^22.0.0` and expects these peer dependencies in your app:
19
-
20
- - `@angular/common ^21.2.0 || ^22.0.0`
21
- - `@angular/core ^21.2.0 || ^22.0.0`
22
- - `openapi-typescript-helpers ^0.1.0`
23
-
24
- If you want to generate types locally, also install the generator as a dev dependency:
25
-
26
- ```sh
27
- npm install -D openapi-typescript
28
- ```
29
-
30
- ## Generating types
31
-
32
- Generate type definitions by pointing `openapi-typescript` at your OpenAPI spec:
33
-
34
- ```sh
35
- npx openapi-typescript https://api.example.com/openapi.yaml -o src/api.types.ts
36
- ```
37
-
38
- This creates a `paths` interface that both utilities consume.
39
-
40
- ## API
41
-
42
- ### `createOpenApiResource`
43
-
44
- A factory for creating reactive Angular resource signals. Must be called inside an Angular injection context (component/service field initializer or constructor).
45
-
46
- ```ts
47
- import type { paths } from './api.types';
48
- import { createOpenApiResource } from 'ngx-openapi-typescript';
49
-
50
- @Component({ ... })
51
- export class PetListComponent {
52
- // Set up once per component/service
53
- private readonly api = createOpenApiResource<paths>({
54
- baseUrl: 'https://api.example.com',
55
- });
56
-
57
- // Simple GET — no params required
58
- protected readonly pets = this.api('/pets');
59
-
60
- // Reactive GET with params — re-fetches when the signals read inside the lambda change
61
- protected readonly petsLimited = this.api('/pets', () => ({
62
- params: { query: { limit: 10 } },
63
- }));
64
-
65
- // Pass signal-driven path params — re-fetches when petId() changes
66
- private readonly petId = signal(1);
67
- protected readonly pet = this.api('/pets/{petId}', () => ({
68
- params: { path: { petId: this.petId() } },
69
- }));
70
-
71
- // Return undefined to put the resource in Idle state (no request made)
72
- private readonly enabled = signal(false);
73
- protected readonly lazyPets = this.api('/pets', () =>
74
- this.enabled() ? {} : undefined,
75
- );
76
- }
77
- ```
78
-
79
- #### Method Override
80
-
81
- The factory defaults to GET. You can pass a `method` option to use a different HTTP method,
82
- but Angular recommends using `httpResource` only for reads. Prefer `OpenApiHttpClient` for mutations.
83
-
84
- ```ts
85
- // Explicit method override (not recommended for production use)
86
- protected readonly createResult = this.api('/pets', () => ({
87
- body: { name: 'Buddy' },
88
- }), { method: 'post' });
89
- ```
90
-
91
- ### `OpenApiHttpClient`
92
-
93
- A base class that wraps Angular's `HttpClient` with OpenAPI types. Ideal for imperative calls, mutations, or service-layer code.
94
-
95
- ```ts
96
- import type { paths } from './api.types';
97
- import { OpenApiHttpClient } from 'ngx-openapi-typescript';
98
- import { Injectable } from '@angular/core';
99
-
100
- @Injectable({ providedIn: 'root' })
101
- export class PetApiClient extends OpenApiHttpClient<paths> {
102
- constructor() {
103
- super({ baseUrl: 'https://api.example.com' });
104
- }
105
- }
106
- ```
107
-
108
- ```ts
109
- // In a component/service
110
- @Component({ ... })
111
- export class PetDetailComponent {
112
- private readonly api = inject(PetApiClient);
113
-
114
- load(id: number) {
115
- this.api
116
- .get('/pets/{petId}', { params: { path: { petId: id } } })
117
- .subscribe(pet => console.log(pet)); // pet is typed as Pet
118
- }
119
-
120
- create(name: string) {
121
- this.api
122
- .post('/pets', { body: { name } })
123
- .subscribe(newPet => console.log(newPet));
124
- }
125
- }
126
- ```
127
-
128
- ## Development
129
-
130
- ```sh
131
- # Build the library
132
- ng build ngx-openapi-typescript
133
-
134
- # Run tests
135
- ng test ngx-openapi-typescript
136
-
137
- # Start the demo app
138
- ng serve demo
139
- ```