swagger-php
swagger-php copied to clipboard
readOnly for property of type object
Hello,
The following code
#[OA\Property(readOnly:true)]
public Article $article;
#[OA\Property(readOnly:true)]
public string $label;
Produce readonly property only for string property in json openapi, not for object :
"article": {
"$ref": "#/components/schemas/Article"
},
"label": {
"type": "string",
"readOnly": true
},
Is it the expected behavior ?
Curretly yes. The spec for 3.0 doesn't allow any other properties next to $ref
and 3.1 only allows title
/description
.
The solution would be to express $ref
's with additional properties using a different JSON contruct altogether. Actually, that is something I've started thinking about lately as there seem to be more and more of those transformations recently.
In fact, that might also help with a lot of the 3.0/3.1 conditional code.
For now this is, unfotunately, the expected behaviour.
Thanks for your reply,
I've used the allOf
attribute to set property as readonly, and it worked.
#[OA\Property(allOf: [new OA\Schema(ref:"#/components/schemas/Article")],readOnly:true)]
public $article;
=>
"article": {
"readOnly": true,
"allOf": [
{
"$ref": "#/components/schemas/Article"
}
]
},
Cool. I suppose this could be a pattern to support any property in combination with $ref
, although I am not sure how valid that would be...