-
-
Notifications
You must be signed in to change notification settings - Fork 261
Description
Description
Using @hey-api/openapi-ts v0.85.2, request bodies that reference a schema containing writeOnly fields are generated with the read-only shape instead of the writable shape. The generator correctly emits both Payload and PayloadWritable, but CreateItemRequest keeps pointing at Payload, so the required writeOnly property (encoded in the repro) disappears from the type you’re supposed to send to the API.
That leaves the writable helper unused and causes TS2353 (“Object literal may only specify known properties”) whenever you try to supply the required field:
const req: CreateItemRequest = {
payload: { kind: 'jpeg', encoded: 'YmFy' },
// ^^^^^^^ Property 'encoded' is missing in type 'Payload'
};I’d expect request payloads (operation body types) to reference the writable variant so that writeOnly properties remain available when constructing the request.
Reproducible example or configuration
npx --yes @hey-api/openapi-ts \
--input writeonly-repro.yml \
--output out \
--plugins @hey-api/typescript
Generated snippet (out/types.gen.ts):
export type CreateItemRequest = {
payload: Payload;
};
export type Payload = {
kind: 'jpeg';
};
export type PayloadWritable = {
kind: 'jpeg';
/**
* Data required on write
*/
encoded: string;
};OpenAPI specification (optional)
openapi: 3.0.3
info:
title: writeOnly repro
version: 1.0.0
paths:
/items:
post:
operationId: item_create
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateItemRequest'
responses:
'201':
description: Created
components:
schemas:
CreateItemRequest:
type: object
required:
- payload
properties:
payload:
$ref: '#/components/schemas/Payload'
Payload:
type: object
required:
- kind
- encoded
properties:
kind:
type: string
enum: [jpeg]
encoded:
type: string
writeOnly: true
description: Data required on write
System information (optional)
@hey-api/openapi-ts 0.85.2
Node.js v23.7.0
macOS 15.7.1 (24G231)