This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
Allow Go code comments to be used as source of schema descriptions #106
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 is a bit of an experimental feature for consideration.
Our use-case is that we want to be able to use a single set of "descriptions" for both Go documentation and the generated JSON Schema. It get's boring very quickly adding both a comment describing a type of field, and a
jsonschema_description
.This PR adds a
CommentsMap
property to the reflector which is essentially a dictionary that maps fully qualified package paths alongside types and fields, pointing to comment strings.The
AddGoComments
method included in theReflector
takes a base import module and a path, extracts all the comments, and adds them to theCommentsMap
:I couldn't figure out a way to automatically determine the full module name, so it has to be defined manually for each package you'd like to use comments from.
The end result is that you can define Go comments, and have them imported into your Schema. The tests provide a complete example of the results. One of the big advantages of this approach is that it makes it much easier to add descriptions to types.