Expand or wrap refs to preserve descriptions #1
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.
We customize the go-swagger generator to overcome the issue noted here: OAI/OpenAPI-Specification#556.
The issue is that when generating a swagger definition from code, the description comment for a field is ignored if the field is an object. The description is instead taken from the description of the object.
For example, for a struct like:
The generated swagger description of the Cloudlet.Location field would end up being "GPS Location" instead of "Location of the Cloudlet site". Beside the description now lacking proper context, this has obvious drawbacks if you have more than one instance of the same object in a struct.
The OpenAPI issue only provides a work-around, which is in the swagger to wrap a #ref with an "allOf" closure, which allows for the field description to be used. The other work-around is to flatten the object definition, putting all fields inline, rather than using a reference.
In this change, we do both. For enums, we use the "allOf" wrapper. For structs, we flatten, because we also want to deal with another issue that swagger doesn't support. This issue is that for multiple APIs (create/update/delete) that use the same object (Cloudlet), but have different allowed fields (for example UpdateCloudlet does not allow the PlatformType to be specified), we want to be able to tailor the allowed fields per API. This can't be done when using a #ref reference, since the specifiable fields then come from the Cloudlet struct definition, which is shared by all referring APIs.
So this change causes objects to be flattened, and enums to be wrapped in an extra "allOf" closure, in order to preserve field descriptions, and allow us to tailor which fields are specified per API. The per-API field manipulation is done as a post-processing step, not part of this repo.