Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation of sample : readOnly / writeOnly and required statement interaction #1416

Open
LasneF opened this issue Jan 30, 2024 · 2 comments
Labels
p3 Type: Bug Something isn't working

Comments

@LasneF
Copy link

LasneF commented Jan 30, 2024

Describe the bug

given an API specification mixing required keyword and readOnly , writeOnly redocly generate a warning wheras it should not

To Reproduce
given the minimal files attached small.json
redocly lint generate 2 warnings

Expected behavior
it should not,

the object contains Id , name , password , both are required ... in differents scenario

  • id is set to ReadOnly
  • password as WriteOnly

i would expect to do a single representation of my object, for input / output and exemple matching

this is a quite common use case (especially for id that is generated by server so mandatory in return only ... so readOnly)
i extended the use case to writeOnly and password just for the record.

The Json Schema specification is not 100 % clear if there is a precedence between required statement and the readOnly and writeOnly context .

=> discussing with JsonSchema team , it is up to the upper layer aka OAS / and so redocly to "customize" the validation as it is the only pieces that has the information

Logs

Example value must conform to the schema: must have required property 'id'.

80 | "inputExample" : {
81 |     "description" : "sampleOfInput",
82 |     "value" : {
83 |         "name" : "Doe",
84 |         "password" : "securityFirst"
85 |     }
86 | },
87 | "outputExample" : {

referenced from small.json:23:45 at #/paths/~1test/post/requestBody/content/application~1json

Warning was generated by the no-invalid-media-type-examples rule.


[2] small.json:89:27 at #/components/examples/outputExample/value

Example value must conform to the schema: must have required property 'password'.

87 |     "outputExample" : {
88 |         "description" : "sampleOfOutPut",
89 |         "value" : { 
90 |             "id" : "goodId",
91 |             "name" : "Doe"
92 |         }
93 |     }   
94 | }

referenced from small.json:39:49 at #/paths/~1test/post/responses/200/content/application~1json

Warning was generated by the no-invalid-media-type-examples rule. 

Redocly Version(s)

redocly 1.8.1

Additional context

thx for your attention , do not hesitate to close it if you consider it as too corner case

@LasneF LasneF added the Type: Bug Something isn't working label Jan 30, 2024
@tatomyr
Copy link
Contributor

tatomyr commented Jan 30, 2024

Oh, this is indeed a corner case. Nevertheless, I think it is still worth fixing. Thank you for bringing this up!

@r-reload
Copy link

Hi, I ran into this exact issue. We make use of the readOnly attribute a lot in our definitions, and I think it would be great if you could fix this issue. It is interesting that another OpenAPI linter ran into the same issue and fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants