You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the readOnly and writeOnly keywords to mark specific properties as read-only or write-only. This is useful, for example, when GET returns more properties than used in POST – you can use the same schema in both GET and POST and mark the extra properties as readOnly. readOnly properties are included in responses but not in requests, and writeOnly properties may be sent in requests but not in responses.
This implies that when a property is marked readOnly it should not be documented as part of the request object
To Reproduce
Generate the following spec
OpenAPI spec file
openapi: 3.0.3info:title: Templi APIversion: 1.0.0description: The REST API for the Templi application.paths:/documents/:get:operationId: documents_listdescription: API for document CRUD actionsparameters:- name: pagerequired: falsein: querydescription: A page number within the paginated result set.schema:type: integertags:- documentssecurity:- auth0: []responses:
'200':content:application/json:schema:$ref: '#/components/schemas/Document'openapi: 3.0.3info:title: Templi APIversion: 1.0.0description: The REST API for the Templi application.paths:/documents/:get:operationId: documents_listdescription: API for document CRUD actionsparameters:- name: pagerequired: falsein: querydescription: A page number within the paginated result set.schema:type: integertags:- documentssecurity:- auth0: []responses:
'200':content:application/json:schema:$ref: '#/components/schemas/PaginatedDocumentList'description: ''components:schemas:Document:type: objectproperties:creator:allOf:- $ref: '#/components/schemas/Auth0User'readOnly: trueid:type: integerreadOnly: trueorgId:type: integerwriteOnly: truerequired:- name
Expected behavior openapi/requests/types.gen.ts should make a differentation between a requset and response schema
ie.
// one type for requesting with readOnly props removedexporttypeCreateDocumentRequest={name: string;orgId: number};// one type for response with writeOnly props removedexporttypeDocument={id: numbername: string;}
** Actual behaviour **
The ts readonly keyword is just prepended to fields with readonly, which is not semantically correct by OpenAPI spec
This library uses @hey-api/openapi-ts to generate the typescript models and service layer.
The effort to fix that package would be better for the ecosystem IMO.
Thanks for the great lib, I've been looking for something to replace https://github.com/ferdikoomen/openapi-typescript-codegen as its no longer mantained.
There is quite a big issue on that old project too which was never fixed ferdikoomen/openapi-typescript-codegen#432
There have been considerations to fix it in a fork => hey-api/openapi-ts#28
But as of right now, they don't support react query codegen, so i'm out of options.
This library seems well mantained, and I like the API. So I would like to contribute to fixing this issue.
Describe the bug
As per the OpenAPI spec for
readOnly
andwriteOnly
This implies that when a property is marked
readOnly
it should not be documented as part of the request objectTo Reproduce
OpenAPI spec file
Expected behavior
openapi/requests/types.gen.ts
should make a differentation between a requset and response schemaie.
** Actual behaviour **
The ts
readonly
keyword is just prepended to fields with readonly, which is not semantically correct by OpenAPI specThe text was updated successfully, but these errors were encountered: