swagger-api / swagger-api/swagger-codegen

readOnly on an object property

Open
#3,803 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I want to put a readOnly to an object property but I can't find a proper way to do it.

If I have:

def1:
    type: "object"
    properties:
      prop:
        $ref: "#/definitions/def2"

def2:
    type: "object"

A) I can put a readOnly in the ref property, but I think that this is incorrect in the swagger defintion. Also the parser ignores here the readOnly property. Eg:

def1:
    type: "object"
    properties:
      prop:
        readOnly: true
        $ref: "#/definitions/def2"

def2:
    type: "object"

B) I can put a readOnly in the def2 definition, but readOnly is only define for properties and not for definitions. This doesn't work either. Eg:

def1:
    type: "object"
    properties:
      prop:
        $ref: "#/definitions/def2"

def2:
    readOnly: true
    type: "object"

C) Also I noticed that if I expand the property, the InlineFlattenerResolver removes the readOnly.
Before flatten:

def1:
    type: "object"
    properties:
      prop:
         type: "object"
         readOnly: true

After flatten:

def1:
    type: "object"
    properties:
      prop:
        $ref: "#/definitions/def2"

def2:
    type: "object"

So, how can I do it right? is there a way to define readOnly on an object property?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Swagger/OpenAPI rules for readOnly on object properties and the parser behavior shown in the examples. Then inspect InlineFlattenerResolver, especially how it handles an inline object property that becomes a definition; done should establish the supported placement and whether readOnly is preserved during flattening.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.