@@ -63,9 +63,16 @@ func (e *ExecExecutableType) GetLogFields() map[string]interface{} {
6363type enrichedExecutableList struct {
6464 Executables []* enrichedExecutable `json:"executables" yaml:"executables"`
6565}
66+
6667type enrichedExecutable struct {
67- ID string `json:"id" yaml:"id"`
68- Spec * Executable `json:"spec" yaml:"spec"`
68+ * Executable
69+
70+ ID string `json:"id" yaml:"id"`
71+ Ref string `json:"ref" yaml:"ref"`
72+ Namespace string `json:"namespace" yaml:"namespace"`
73+ Workspace string `json:"workspace" yaml:"workspace"`
74+ Flowfile string `json:"flowfile" yaml:"flowfile"`
75+ FullDescription string `json:"fullDescription" yaml:"fullDescription"`
6976}
7077
7178func (e * Executable ) SetContext (workspaceName , workspacePath , namespace , flowFilePath string ) {
@@ -93,24 +100,28 @@ func (e *Executable) SetInheritedFields(flowFile *FlowFile) {
93100 e .inheritedDescription = strings .Join ([]string {flowFile .Description , descFromFIle }, "\n " )
94101}
95102
96- func (e * Executable ) YAML () (string , error ) {
97- enriched := & enrichedExecutable {
98- ID : e .ID (),
99- Spec : e ,
103+ func (e * Executable ) enriched () * enrichedExecutable {
104+ return & enrichedExecutable {
105+ Executable : e ,
106+ ID : e .ID (),
107+ Ref : e .Ref ().String (),
108+ Namespace : e .Namespace (),
109+ Workspace : e .Workspace (),
110+ Flowfile : e .FlowFilePath (),
111+ FullDescription : strings .TrimSpace (execDescriptionMarkdown (e , false )),
100112 }
101- yamlBytes , err := yaml .Marshal (enriched )
113+ }
114+
115+ func (e * Executable ) YAML () (string , error ) {
116+ yamlBytes , err := yaml .Marshal (e .enriched ())
102117 if err != nil {
103118 return "" , fmt .Errorf ("failed to marshal executable - %w" , err )
104119 }
105120 return string (yamlBytes ), nil
106121}
107122
108123func (e * Executable ) JSON () (string , error ) {
109- enriched := & enrichedExecutable {
110- ID : e .ID (),
111- Spec : e ,
112- }
113- jsonBytes , err := json .MarshalIndent (enriched , "" , " " )
124+ jsonBytes , err := json .MarshalIndent (e .enriched (), "" , " " )
114125 if err != nil {
115126 return "" , fmt .Errorf ("failed to marshal executable - %w" , err )
116127 }
@@ -316,10 +327,7 @@ func (e *Executable) IsExecutableFromWorkspace(workspaceFilter string) bool {
316327func (l ExecutableList ) YAML () (string , error ) {
317328 enriched := & enrichedExecutableList {}
318329 for _ , exec := range l {
319- enriched .Executables = append (enriched .Executables , & enrichedExecutable {
320- ID : exec .ID (),
321- Spec : exec ,
322- })
330+ enriched .Executables = append (enriched .Executables , exec .enriched ())
323331 }
324332 yamlBytes , err := yaml .Marshal (enriched )
325333 if err != nil {
@@ -331,10 +339,7 @@ func (l ExecutableList) YAML() (string, error) {
331339func (l ExecutableList ) JSON () (string , error ) {
332340 enriched := & enrichedExecutableList {}
333341 for _ , exec := range l {
334- enriched .Executables = append (enriched .Executables , & enrichedExecutable {
335- ID : exec .ID (),
336- Spec : exec ,
337- })
342+ enriched .Executables = append (enriched .Executables , exec .enriched ())
338343 }
339344 jsonBytes , err := json .MarshalIndent (enriched , "" , " " )
340345 if err != nil {
@@ -526,3 +531,73 @@ func NewExecutableID(workspace, namespace, name string) string {
526531 return ""
527532 }
528533}
534+
535+ func (e * Executable ) MarshalJSON () ([]byte , error ) {
536+ type Alias Executable
537+ aux := & struct {
538+ * Alias
539+ Timeout string `json:"timeout,omitempty"`
540+ }{
541+ Alias : (* Alias )(e ),
542+ }
543+ if e .Timeout != 0 {
544+ aux .Timeout = e .Timeout .String ()
545+ }
546+ return json .Marshal (aux )
547+ }
548+
549+ func (e * Executable ) UnmarshalJSON (data []byte ) error {
550+ type Alias Executable
551+ aux := & struct {
552+ * Alias
553+ Timeout string `json:"timeout,omitempty"`
554+ }{
555+ Alias : (* Alias )(e ),
556+ }
557+ if err := json .Unmarshal (data , & aux ); err != nil {
558+ return err
559+ }
560+ if aux .Timeout != "" {
561+ duration , err := time .ParseDuration (aux .Timeout )
562+ if err != nil {
563+ return err
564+ }
565+ e .Timeout = duration
566+ }
567+ return nil
568+ }
569+
570+ func (r * RequestExecutableType ) MarshalJSON () ([]byte , error ) {
571+ type Alias RequestExecutableType
572+ aux := & struct {
573+ * Alias
574+ Timeout string `json:"timeout,omitempty"`
575+ }{
576+ Alias : (* Alias )(r ),
577+ }
578+ if r .Timeout != 0 {
579+ aux .Timeout = r .Timeout .String ()
580+ }
581+ return json .Marshal (aux )
582+ }
583+
584+ func (r * RequestExecutableType ) UnmarshalJSON (data []byte ) error {
585+ type Alias RequestExecutableType
586+ aux := & struct {
587+ * Alias
588+ Timeout string `json:"timeout,omitempty"`
589+ }{
590+ Alias : (* Alias )(r ),
591+ }
592+ if err := json .Unmarshal (data , & aux ); err != nil {
593+ return err
594+ }
595+ if aux .Timeout != "" {
596+ duration , err := time .ParseDuration (aux .Timeout )
597+ if err != nil {
598+ return err
599+ }
600+ r .Timeout = duration
601+ }
602+ return nil
603+ }
0 commit comments