Allow to set referenced schema property as readOnly

Hi,

Please take a look at the Screenshot #1. For me this feels like a pretty obvious use case - to be able to have referenced element as readonly/writeonly in the context of the schema that references it.

The lack of it limits usage of components drastically, at least in our APIs. I have to create a new copy of a schema just to mark the same object as readonly in few contexts.

Please consider at least supporting a manual entry (Screenshot #2)


image.png

Thanks for the feedback. Could you please describe your usage scenario in detai? It would help us understand your needs better.

Sure,

For example, in our API we have a common way to represent internationalized content. For example, let’s say I have a Post and it has title, slug and body:

{ 
  "post": { 
    "title": { 
      "en": "Helo",
      "es": "Hola"
    },
    "slug": {
      "en": "helo",
      "es": "hola"
    },
    "body": {
      "en": "Welcome",
      "es": "Bienvenido"
    }
  }
}

As you can imagine, there would be a lot of duplication to describe each attribute on each model

So, i’ve created a schema like this (it’s more complicated, i left only what is relevant here) to describe such structure, let’s call it LocalizedContent:

{
  "type": ["object", "null"],
  "examples": [
      { "en": "Text" }
  ],
  "additionalProperties": {
      "type": "string"
  }
}

However, It does not make sense to set “readOnly” property on this schema globally, as some model attributes are readonly, and some are not - for example Post has editable title and body, but slug is autogenerated

In other words, when i reference LocalizedContent on Post’s attributes, I need to specify that slug is readonly. Without it, I would have to create a “readonly” version of this schema ([READONLY] LocalizedContent :D) or just copy-paste it without reference.

Both workarounds feel hacky and untidy to me.

The example above may feel a bit complicated and specific to just one case, but because of the same issue, we cannot fully efficiently use “primitives” like these that make the whole API specs more clean and DRY:


I hope you can imagine that specifying “readonliness” of “primitives” like these globally and statically doesn’t feel very natural :smile:

Sure,

For example, in our API we have a common way to represent internationalized content. For example, let’s say I have a Post and it has title, slug and body:

{ 
  "post": { 
    "title": { 
      "en": "Helo",
      "es": "Hola"
    },
    "slug": {
      "en": "helo",
      "es": "hola"
    },
    "body": {
      "en": "Welcome",
      "es": "Bienvenido"
    }
  }
}

So, i’ve created a schema like this (it’s more complicated, i left only what is relevant here) to describe such structure, let’s call it LocalizedContent:

{
  "type": ["object", "null"],
  "examples": [
      { "en": "Text" }
  ],
  "additionalProperties": {
      "type": "string"
  }
}

However, It does not make sense to set “readOnly” property on this schema globally, as some model attributes are readonly, and some are not - for example Post has editable title and body, but slug is autogenerated

In other words, when i reference LocalizedContent on Post’s attributes, I need to specify that slug is readonly. Without it, I would have to create a “readonly” version of this schema ([READONLY] LocalizedContent :D) or just copy-paste it without reference.

Both workarounds feel hacky and untidy to me.

I hope you can imagine that specifying “readonliness” of “primitives” like these globally and statically doesn’t feel very natural :smile: