Redocly / Redocly/openapi-sampler
readOnly and writeOnly are not honored when used in an allOf
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 228
- Forks
- 52
- Avg merge
- 48m
- Merged PRs (30d)
- 6
Description
readOnly & writeOnly are not honored when they are set in an allOf block to edit an objects properties.
E.g. we got these components:
openapi: 3.0.0
info:
title: Test
version: 0.1.0
paths:
/users:
get:
summary: Get Users
operationId: getAllAccounts
responses:
200:
description: Default
content:
application/json:
schema:
$ref: '#/components/schemas/User'
post:
summary: Create User
operationId: createUser
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
201:
description: 'User created'
/users/{userId}:
patch:
summary: Update User
operationId: updateUser
parameters:
- in: path
name: userId
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PatchUser'
responses:
200:
description: 'User updated'
components:
schemas:
User:
type: object
properties:
id:
type: integer
readOnly: true
tenant_id:
type: integer
username:
type: string
PatchUser:
allOf:
- $ref: '#/components/schemas/User'
- type: object
properties:
tenant_id:
readOnly: true
Assuming the id of a User will never change and User is used to create and read the user and PatchUser is used to update it.
This setup would disallow to patch the tenant_id of a user, but keeps it writable when the user is created. Exactly that is not shown correctly in the request samples tab. It keeps showing the tenant_id in the request sample which implies it is updatable when it is not. The request body schema omits the tenant_id correctly.

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
Reproduce the provided OpenAPI YAML in the request samples tab and inspect how the allOf schema is sampled for PATCH requests. Compare the request sample with the request body schema, and verify that tenant_id is omitted from the PATCH sample while remaining writable in the create request sample.
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
- Mostly clear
- Newbie friendliness
- 48/100