Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly property is not processed for an individual field #1030

Closed
DanielTrommel opened this issue Feb 8, 2023 · 2 comments
Closed

ReadOnly property is not processed for an individual field #1030

DanielTrommel opened this issue Feb 8, 2023 · 2 comments

Comments

@DanielTrommel
Copy link

DanielTrommel commented Feb 8, 2023

A definition with an individual readonly property does not produce a type/interface definition with a readonly property.

Name Version
openapi-typescript 6.1.0
Node.js v18.12.1
OS + version Windows 10

Reproduction

a YAML definition like this:
image

Expected result

...should produce a readonly property like this:
image
but it does not...

Solution proposal

Line 174 in \transform\schema-object.ts is currently:

if (ctx.immutableTypes || schemaObject.readOnly) key = tsReadonly(key);

and should(?) be:

if (ctx.immutableTypes || schemaObject.readOnly || ("readOnly" in v && v.readOnly)) key = tsReadonly(key);

Also notice that no test exists for the "readonly" case in schema-object-test.ts.

Question
I tried to push this fix to this repo on a new branch (to open a PR), but got a HTTP 403.
Hopefully someone else can submit this fix instead?

@olivierbeaulieu
Copy link

I think you're misunderstanding OpenAPI's readOnly annotation. It has nothing to do with TypeScript's readonly modifier.

From the spec:

Read-Only and Write-Only Properties
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.

openapi-typescript does not handle readOnly and writeOnly properly even by that definition though, see issue #604

@DanielTrommel
Copy link
Author

Thanks for taking the time; I indeed misunderstood and will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants