{"library":"openapi-typescript-helpers","title":"OpenAPI TypeScript Helpers","description":"openapi-typescript-helpers is a utility package providing TypeScript helper types designed to complement types generated by `openapi-typescript`. Its primary purpose is to offer generic type transformations, which are internally leveraged by other packages in the `openapi-ts` ecosystem, such as `openapi-fetch`. The current stable version is `0.1.0`. Given its recent initial release and close ties to `openapi-typescript`, its release cadence is likely tied to major `openapi-typescript` releases and feature additions, though it may not have independent major version bumps as frequently. Key differentiators include its focus on type-level transformations for refining generated OpenAPI types, particularly for handling `readOnly` and `writeOnly` properties, ensuring type safety and correct data handling across different API operations. Unlike `openapi-typescript` which generates the types, this package provides tools to manipulate and refine those generated types for specific application logic.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install openapi-typescript-helpers"],"cli":null},"imports":["import type { Readable } from 'openapi-typescript-helpers';","import type { Writable } from 'openapi-typescript-helpers';","import type { $Read } from 'openapi-typescript-helpers';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import type { paths } from './my-api'; // Assume this is generated by openapi-typescript\nimport type { Readable, Writable } from 'openapi-typescript-helpers';\n\n// Example: Define a schema type from openapi-typescript generated types\ntype Pet = paths['/pets/{petId}']['get']['responses'][200]['content']['application/json'];\n\n// Create a type for a pet when fetching (should not include writeOnly fields)\ntype ReadablePet = Readable<Pet>;\n\n// Create a type for creating a pet (should not include readOnly fields)\ntype WritablePet = Writable<Pet>;\n\ninterface PetInput { // Simulate a type with readOnly/writeOnly markers\n  id: $Read<string>;\n  name: string;\n  tag?: string;\n  secretToken: $Write<string>;\n}\n\ntype FetchablePetInput = Readable<PetInput>; // id, name, tag\ntype CreatablePetInput = Writable<PetInput>; // name, tag, secretToken\n\n// You would typically use these types in your API client logic:\n// async function fetchPet(petId: string): Promise<ReadablePet> { /* ... */ }\n// async function createPet(newPet: WritablePet): Promise<ReadablePet> { /* ... */ }\n\n// Demonstrate how the types change\nconst petToCreate: CreatablePetInput = {\n  name: 'Buddy', \n  // id is excluded by Writable\n  secretToken: process.env.PET_SECRET ?? '' // secretToken is included\n};\n\nconst fetchedPet: FetchablePetInput = {\n  id: '123',\n  name: 'Buddy' \n  // secretToken is excluded by Readable\n};","lang":"typescript","description":"Demonstrates the usage of `Readable` and `Writable` helper types to refine generated OpenAPI types for specific read and write operations, highlighting how they filter `readOnly` and `writeOnly` properties.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}