swagger-api / swagger-api/swagger-ui
In case of request validation readOnly should disable required check
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Origin
@mathis-m, is this why its not working in swagger-ui? the id field is marked as readOnly which makes it implicitly non-required on request. this is from the 3.0.3 spec:
If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only.
also the json path correctly fills the the request body textfield from the template with description and without id. so the schema interpretation is correct there.
apart from that, user feedback should happen if the request cannot be sent and why. imho at least
Originally posted by @tfranzel in https://github.com/swagger-api/swagger-ui/issues/7242#issuecomment-833567856
Context
validateParam is used for validation Request Inputs, this creates the need for checking readonly property.
I do not see this implemented till now. OAS:
Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.
Requirements
- SHOULD NOT be sent as part of the request (it could be sent in request in given cases) -> do not validate for non existence
This phrase, or the phrase "NOT RECOMMENDED" mean that
there may exist valid reasons in particular circumstances when the
particular behavior is acceptable or even useful, but the full
implications should be understood and the case carefully weighed
before implementing any behavior described with this label. - readOnly being true and is in the required list, the required will take effect on the response only -> required check should be bypassed if property is readOnly: true
required: true: consider bypass for schema itself at https://github.com/swagger-api/swagger-ui/blob/53829f18a6c763c59360b27d5667fdd12600e4b6/src/core/utils.js#L432required: <List> & properies.readonly: consider bypass for child property level by adding filter at https://github.com/swagger-api/swagger-ui/blob/53829f18a6c763c59360b27d5667fdd12600e4b6/src/core/utils.js#L494
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/core/utils.js at the validateParam logic around lines 432 and 494. Check how schema-level required and required-list child properties are validated, then ensure readOnly properties bypass request-side required checks while retaining the stated request behavior. Done means readOnly required fields no longer block request validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100