openapi-processor-spring icon indicating copy to clipboard operation
openapi-processor-spring copied to clipboard

interpretation of openapi readOnly flag in model

Open richard-melvin opened this issue 9 months ago • 2 comments

Given a definition like:

``yaml

Data:
  type: object
  properties:        
    status:
      type: string)
      readOnly: true

get generated java:


```java

public record Data {
    @JsonProperty(value = "status", access = JsonProperty.Access.READ_ONLY)
    String status
) {}

This is correct if the generated code is for the provider of the interface (i.e. server-side). But if the code is to be the client of the interface, the field should instead be annotated with JsonProperty.Access.WRITE_ONLY.

So, as a feature request, it would be useful if there was a code generation option that declared the intended usage of the generated code.

See: https://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonProperty.Access.html

richard-melvin avatar Apr 08 '25 15:04 richard-melvin

actually it turns out there is a Jacksonm flag that already does this (MapperFeature.INVERSE_READ_WRITE_ACCESS), so this wouldn;t actually be very useful.

richard-melvin avatar Apr 09 '25 12:04 richard-melvin

interesting, I didn't know about that.

hauner avatar Apr 09 '25 21:04 hauner