From fd5f5801b09e5da666f7cf02c1e69a7ad0a96a57 Mon Sep 17 00:00:00 2001 From: nlsui <37106890+nlsui@users.noreply.github.com> Date: Mon, 26 Apr 2021 15:30:51 +0200 Subject: [PATCH] add possibility to define individuel description --- jsonschema/reflection.go | 9 ++++++++- jsonschema/reflection_test.go | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jsonschema/reflection.go b/jsonschema/reflection.go index e86d071..bcc6c21 100644 --- a/jsonschema/reflection.go +++ b/jsonschema/reflection.go @@ -145,11 +145,18 @@ func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type) (*Typ interactionText := reflect.New(t).MethodByName("InteractionText").Call(dummyInputs)[0].String() + descriptionMethod := reflect.New(t).MethodByName("Description") + + description := "Build a " + name + if descriptionMethod.IsValid() { + description = descriptionMethod.Call(dummyInputs)[0].String() + } + st := &Type{ Name: name, Type: defType, Properties: orderedmap.New(), - Description: "Build a " + name, + Description: description, InteractionText: interactionText, } definitions[r.typeName(t)] = st diff --git a/jsonschema/reflection_test.go b/jsonschema/reflection_test.go index aaa9756..6da4f3e 100644 --- a/jsonschema/reflection_test.go +++ b/jsonschema/reflection_test.go @@ -41,6 +41,10 @@ func (a action) InteractionText() string { return "§Name §Costs §Time §MultipleUse" } +func (a action) Description() string { + return "This allows you to build an Action-card" +} + type costs []cost func (c costs) Validate() error {