question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarify spec wrt readOnly and writeOnly in referenced schemas

See original GitHub issue

The current spec says that readOnly and writeOnly are “relevant only for Schema properties definitions.”

I have encountered at least two parsers, one new, one widely used, that interpret this in the most literal sense, meaning “discard readOnly and writeOnly if they occur in a top-level schema definition.”

The parsers either have their own logic that does this, or they parse into an object graph that:

  • has separate classes for top-level schema objects vs. property subschemas; and
  • the top-level schema object class has no way to represent readOnly and writeOnly.

With this interpretation, reusable schemas can’t be intrinsically readOnly or writeOnly by definition. The following won’t work:

components:
  schemas:
    project:
      type: object
      properties:
        projectID:
          type: string
        projectName: 
          type: sting
        created:
          $ref: "#/components/schemas/dataChangeEvent"
        updated: 
          $ref: "#/components/schemas/dataChangeEvent"
          
    dataChangeEvent:
      readOnly: true
      type: object
      properties:
        changedBy:
          type: string
        timestamp:
          type: string
          format: date-time

I would interpret “relevant” to mean that the readOnly and writeOnly annotations are only effective in the context of a property subschema. Not that they are disallowed, safe to ignore, or safe to discard when declared in other contexts.

I think my interpretation is probably consistent with the original intent, but I wasn’t part of that discussion. The word “relevant” is ambiguous, and the spec only uses that word in the readOnly and writeOnly descriptions.

I think the simple answer is to clarify the meaning of the spec. The current spec for readOnly starts like this:

Relevant only for Schema “properties” definitions. Declares the property as “read only”.

I’d propose changing it to:

MAY occur in any Schema Object. When used in a property subschema, either directly or by reference, a true value declares the property as “read only”.

Similar change proposed for writeOnly. Happy to open a PR with this change if the TSC agrees.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:27 (25 by maintainers)

github_iconTop GitHub Comments

1reaction
ChaitanyaBabarcommented, Mar 24, 2021

@darrelmiller @tedepstein Since we seem very likely to move to JSON Schema 2019-09 in OAS 3.1, this problem will go away since (as noted above) the issue is now addressed in the JSON Schema spec. We haven’t had anyone complain about how we specified it so it seems to be working out OK.

@handrews I had gone through above discussion and since the docs change by @tedepstein is not yet reflected in trunk just wanted to sure that I have interpreted the discussion correctly so asking few Questions below.

@handrews @philsturgeon @darrelmiller Can you please put in your thoughts/comments about the same.

  • Question 1 :- Does above comment mean that readOnly would be supported in root context in current OAS specifications ?

  • Question 2 :- If that is the case what would happen when readOnly is used along side $ref ? As per docs official here it says siblings property along side $ref are ignored , so is the use of readOnly along side $ref supported ?

  • Question 3 :- Is there any difference between use/interpretion of readOnly between OAS 3.0.X and OAS 3.1.X versions ?

1reaction
MikeRalphsoncommented, Feb 27, 2020

I would be in favour of pointing people at the schema pre-processing solutions suggested by @tedepstein if/when this comes up (i.e. not in the spec itself)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property still showing in Swagger with writeonly=true
When I make a property read-only ([SwaggerSchema(ReadOnly = true)]) it only shows on GET requests, as it should.
Read more >
Web Audio API - W3C
Abstract. This specification describes a high-level Web API for processing and synthesizing audio in web applications.
Read more >
pytest Documentation - Read the Docs
Notice that the methods are only referencing self in the signature as a formality. No state is tied to the actual test class....
Read more >
Raw file - Earthdata Source Code Repository
New GDAL drivers: - BYN: read/write support for Natural Resources Canada's Geoid binary format - EEDAI: read-only driver for Google Earth Engine Data...
Read more >
SPIR-V Specification - Khronos Registry
Generator: 0x00080001 (Khronos Glslang Reference Front End; 1). ; Bound: ... ReadOnly. A read-only object. Kernel. 1. WriteOnly. A write-only object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found