Prevent loss of field descriptions when converting swagger specs by using refSiblings: 'preserve' #2207
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.
This change resolves #2067 for converting swagger 2.0 based specs to open-api 3.0.0.
What/Why/How?
Previously, when using a swagger 2.0 file with ReDoc, the descriptions of any field using a complex type (referencing another schema) would show the description of the type, instead of the description of the field itself.
Reference
As per Mermade/oas-kit#597 (comment),
swagger2openapineedsrefSiblings: 'preserve'to bring additional fields into the converted open-api object.This change makes the description field available to the
fieldSchemaobjects, but it also needs to be merged into the field model to be shown in the UI.swagger2openapito use refSiblings: 'preserve'models\Field.tswhen deciding on the description value to use, now also considers thefieldSchema.descriptionin addition to the existing info or schema description.FieldModel.test.tsand a new swagger 2.0 fixturecomplexFieldDescriptions.jsonfor testing.Additionally, there are two options for consideration when choosing the description:
fieldSchema.descriptionverbatim if it's defined, orI'll update (clean) the code depending on your thoughts.
Screenshots
If you would reuse a type, say "Measurement", for both weight and volume fields, the intended description is lost i.e. see the repetitive description in the first screenshot:

where the expected result is to show the explanation for the field:

Checks
Final Notes:
loadAndBundleSpec.tsfile would have had a lot of unrelated formatting changes to existing code. I opted out for that file only, so the diff is more representative of the change.