apigear-io / cli

The ApiGear client as go project
https://apigear.io
MIT License
1 stars 2 forks source link

readonly properties #84

Closed jryannel closed 1 year ago

jryannel commented 1 year ago

Readonly properties allow API writers to designate properties as fields to be readonly.

In the YAML document you would add:

properties:
  - name: prop01
    type: int
    readonly: true

In the IDL you would use

interface Demo {
  readonly prop0: int

In the template you can check the type field:

{{ range .Properties }}
{{ if .IsReadOnly }}
// write readonly code
{{ end }}
{{ end }}

The same applies also to struct fields. But in general we see properties much more useful to be readonly then struct fields.