mnahkies / mnahkies/openapi-code-generator

correctly interpret readOnly / writeOnly

Open
#157 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
34
Forks
8
Avg merge
20h 27m
Merged PRs (30d)
7

Description

so this is embarrassing, I've interpreted readOnly as being equivalent to the typescript readonly modifier.

however, the specification defines this, and it's friend writeOnly quite differently:

readOnly

Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.

writeOnly

Relevant only for Schema "properties" definitions. Declares the property as "write only". Therefore, it MAY be sent as part of a request but SHOULD NOT be sent as part of the response. If the property is marked as writeOnly being true and is in the required list, the required will take effect on the request only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.

Eg: these serve to allow models to express a different interface for the different CRUD operations - without needing separate CreateUpdateX / X models as I've normally done...

fixing this will be a breaking change, and probably quite challenging to implement. It's unclear whether it's best to synthesis separate XWrite / XRead models, or use an Omit / Pick type approach.

note: 3.1 dropped these from the spec, deferring to the JSON schema definition. should consider whether we need to implement it differently for 3.1 vs 3.0, or just follow 3.1.

references

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/openapi-code-generator/src/typescript/common/type-utils.ts and compare its current readOnly handling with the OpenAPI 3.0 and 3.1 references linked in the issue. Decide how generated models should represent request-only and response-only properties, then verify that readOnly and writeOnly produce the intended interfaces without treating either as TypeScript readonly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.