pactflow / swagger-mock-validator

Other
13 stars 4 forks source link

Support the "readOnly" and "writeOnly" attribute #49

Open mefellows opened 9 months ago

mefellows commented 9 months ago

From https://swagger.io/specification/v3/?sbsearch=readOnly

Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.

That is, attributes marked as "readOnly" in a shared model between request and response bodies should only be part of the response, writeOnly attributes should only be part of the request body.

The validator currently does not consider these attributes, which makes it hard to re-use models on the request and response.

Given this model:

bb9214c9-c137-461d-80ea-2c7c722b194c

An error will show if the created_at property is not in the request, despite it being a read-only property:

758e889c-224e-458f-aa44-7d20987c1237

Workaround

The workaround is to separate request and response schemas, perhaps using other composition capabilities of JSON schema.

github-actions[bot] commented 9 months ago

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1435). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

mefellows commented 9 months ago

See also: