Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readOnly for property of type object #1570

Open
willylambert opened this issue Apr 11, 2024 · 3 comments
Open

readOnly for property of type object #1570

willylambert opened this issue Apr 11, 2024 · 3 comments

Comments

@willylambert
Copy link

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 ?

@DerManoMann
Copy link
Collaborator

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.

@willylambert
Copy link
Author

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"
    }
  ]
},

@DerManoMann
Copy link
Collaborator

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants