Swagger-codegen: Question: Creating immutable model objects by yaml files.

Created on 6 Oct 2016  路  3Comments  路  Source: swagger-api/swagger-codegen

Question

Is it possible to generate immutable objects by yaml modification?

Usage example

```yaml CreatePerson type: object **immutable: true** -- Is this possible? ... properties: ....

Most helpful comment

immutable is not the same thing as readOnly. Immutability means that a CREATE can write, but you cannot change it once it is posted.

All 3 comments

Yes, per https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schema-object

     type: object
     readOnly: true
     properties:
        myId:
          # also legal in properties
          readOnly: true

immutable is not the same thing as readOnly. Immutability means that a CREATE can write, but you cannot change it once it is posted.

When I set readOnly property for model, Swagger code generator still generate setters for fields.

Used:
{code}
io.swagger
swagger-codegen-maven-plugin
2.4.7
{code}

Swagger 2.0 & Java 8

Can I make properties for code generator to generate immutable Java POJO models?

Was this page helpful?
0 / 5 - 0 ratings