Swagger-ui: Read-only attributes in model definition

Created on 30 Jan 2015  路  10Comments  路  Source: swagger-api/swagger-ui

I have swagger models defined for some of the things our API can take or give in a request, but the attributes between both are not always the same. In the following example, the id cannot be set from the API:

  "models": {
    "Cart": {
      "id": "Cart",
      "required": null,
      "properties": {
        "id": {
          "type": "integer",
          "description": "Cart ID",
          "readOnly": true
        }
      }
    }
  }

I'd though adding readOnly to the id property would remove it from the Model and Model Schema in the "Parameters" section of a request, i.e. in the part where it is used for writing, but this seems to not be the case.

Did I understand that option wrong?

swagger-js feature

Most helpful comment

Has any progress been made on this?

All 10 comments

(I have Swagger UI version 2.1.0-alpha.7)

You understand correctly, it's just not implemented yet.

Ah, thanks a lot for the info :-) It seems the way to go is to define different models for read and write operations, I'll hold on to that until this is implemented.

I'd love to see this feature implemented soon, so...

... +1

:+1:

I've been looking into this too. I expected a readOnly parameter to be shown as being read only, in a similar way that non required parameters are being shown as optional.

The reason I expect this is because the API I'm documenting behaves this way: read only parameters are allowed in PUT requests, but are either simply ignored or checked to not have changed (I've not made up my mind yet on that one). The reason for this is because API consumers should be able to do a GET and then an immediate PUT without needing to delete the read only parameters.

I'd like the user to be aware of this behavior somehow. I've come up with a simple patch to do this. However it would behave differently than thegcat's assumption above. I wonder if there's something we can come up with to cover both cases?

Reading about this a bit more, the docs say:
"...it MAY be sent as part of a response but MUST NOT be sent as part of the request.". So I think what I want is the odd-case, so maybe not so appropriate...

Has any progress been made on this?

I need this :C

@ramses132, are you using the 3.x series of Swagger UI?

i am also need it and i am using 3.x

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilnurshax picture ilnurshax  路  3Comments

SangeetaGulia picture SangeetaGulia  路  4Comments

fehguy picture fehguy  路  3Comments

easyest picture easyest  路  3Comments

shockey picture shockey  路  3Comments