Skip to content

required and readyOnly/writeOnly properties #432

Open
@stefanprobst

Description

@stefanprobst

hi, i'm curious how this library handles the contextual behavior of required properties interacting with readOnly/writeOnly?

from https://swagger.io/specification

  • "If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only."
  • "If the property is marked as writeOnly being true and is in the required list, the required will take effect on the request only."

i have tried with the following example, and it looks like marking the property as readonly does not fully capture the above behavior?

Example
{
  "openapi": "3.0.0",
  "info": {
    "title": "Test API",
    "version": "1.0.0"
  },
  "paths": {
    "/api/tests": {
      "get": {
        "operationId": "getTests",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Test" } }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createTest",
        "requestBody": {
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/Test" } }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Test" } }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Test": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "res": { "type": "string", "readOnly": true },
          "req": { "type": "string", "writeOnly": true }
        },
        "required": ["req", "res"]
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions