swagger-api / swagger-api/swagger-ui

In case of request validation readOnly should disable required check

Open
#7,263 1 comment 0 reactions 0 assignees View on GitHub

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.