swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Java] setters for readonly fields are missed

Open punksta opened this issue 7 years ago • 1 comments

Description

Json parsers like gson need setters for all non transient fields by default. But setters for readonly fields are missed in codegen. So json parser can to use only slow reflection to set value into private read only methods.

Swagger-codegen version

2.2.2-SNAPSHOT

Command line used for generation
java -jar /home/punksta/apps/swagger-codegen-cli.jar generate \
  -i ../api-v1.yml \
  -l java \
Steps to reproduce

read_only for any fields

Related to

https://github.com/swagger-api/swagger-codegen/issues/2189

Suggest a Fix

Easy way: Generate setters, but annotate fields as "read only". Hard way: Let read_only fields final and generate custom constructors for it. Also need to generate deserialization for every library what invoke custom constructors while json parsing.

punksta avatar Nov 20 '16 21:11 punksta