OpenAPI writeOnly property appears in response
Version
4.1.3
Context
Properties which are writeOnly are still appearing in response body
Sample Schema
SampleObject:
type: object
description: Sample description
properties:
id:
type: string
name:
type: string
writeOnly: true
Expected behaviour: Only id should be present in response body Actual behaviour: Both id and name are present in response
As per the OpenAPI documentation:
readOnly properties are included in responses but not in requests, and writeOnly properties may be sent in requests but not in responses.
Do you have a reproducer?
https://github.com/KeerthanaSrikanth/web-and-openapi-howto/tree/writeonly
I have added writeOnly property to the property tag in the Pet schema.
Steps to reproduce
1. `mvn compile exec:java`
2. `curl -X POST -H "Content-type: application/json" --data '{"id":4,"name":"Alan", "tag": "PQR"}' http://localhost:8080/pets`
3. `curl http://localhost:8080/pets/4`
Expected response: {"id":4,"name":"Alan"}%
Actual response: {"id":4,"name":"Alan","tag":"PQR"}%
AFAIK the OpenAPI contract only validates the request coming in, not the response going out. The outgoing code is your responsibility