OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] [JaxRS] readOnly parameter breaks reading response

Open
#10,663 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

#9276 implemented "readOnly" by generating the annotation "JsonProperty.Access.READ_ONLY".

readOnly (OpenAPI): a property which can be sent in a response but not in a request.
JsonProperty.Access.READ_ONLY: property is ignored on deserialization.

These are differnet things. So on reading a response, properties marked as readOnly are not deserialized by jackson and are always null. This breaks all schemas that contain readOnly-properties because those properties are never deserialized. The same is probably true for writeOnly when trying to read requests.

Might be I simply don't understand something here, but how are you supposed to use this? Dont use readOnly? Create separate schemas for server and client?

openapi-generator version

5.2.1

Related issues/PRs

#9222

Suggest a fix

Don't generate "JsonProperty.Access.READ_ONLY" because it has different semantics from OpenAPI's "readOnly".

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 by reviewing the readOnly implementation from #9276 and the related discussion in #9222. Reproduce the generated Java JAX-RS model behavior with a response containing a readOnly property, then verify that the property is deserialized instead of being made null by JsonProperty.Access.READ_ONLY.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.