Prevent ReadOnly/WriteOnly flag cascade on reusable object definitions #884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #882
This PR updates the type generator to be aware of when it is generating a definition for a specific, named object (i.e., one that would be used via
"$ref": "#/definitions/<type name>"
) and a "synthetic" object (one that is encountered when a resource input and output are defined separately). This allows the generator to know when it must flag properties as ReadOnly/WriteOnly, which should only happen with synthetic objects, as named object types may be reused in other contexts. Currently, if a shape is reused by multiple resources, it will haveReadOnly
/WriteOnly
usage flags applied per the resource defined earlier in the RP swagger model, and subsequent usages of the same type will retrieve the object definition from cache. If a shape is only present on the PUT request for one resource and only on the GET response for another, all of its properties will be defined as eitherReadOnly
orWriteOnly
, depending on which resource is encountered first during type generation.This functionality is important to #411, which will increase the amount of type reuse in this library (and, without a change like the one in this PR, will designate many of those reused types as consisting entirely of
ReadOnly
properties).There are two changes to the type generator included in this PR that are meant to accomplish the goal described above:
<PUT path name>Or<GET path name>
is created, andReadOnly
/WriteOnly
property flags are applied as before.$.properties
onTest.Rp1/testType1
in the integration test model, which is of typeTestType1CreateOrUpdateProperties
on thePUT
request and of typeTestType1Properties
on theGET
request. A new object definition namedTestType1CreateOrUpdatePropertiesOrTestType1Properties
is created, and thelocationData
property, which exists only onTestType1Properties
, is flagged asReadOnly
.GET
orPUT
schemata, it does not automatically flag the object's properties asReadOnly
orWriteOnly
.LocationData
are not flagged asReadOnly
, even though they are first encountered by the type generator in the context of theTest.Rp1/testType1
resource.LocationData
is also accepted as part of the request for thelistFoos
resource function, in which case it would not be composed ofReadOnly
properties.