Redocly / Redocly/openapi-sampler

readOnly and writeOnly are not honored when used in an allOf

Open
#140 0 comments 0 reactions 0 assignees View on GitHub

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.

image

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.