From 9107f0d36ec00124ef6424033a10fa4c98c17441 Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Sat, 27 Aug 2022 22:00:16 +0000 Subject: [PATCH] feat(contact): Improve Contact information with name, mail and URL --- cmd/init.go | 12 ++++++++++-- .../go_swagger/generate_api_yamls.go | 14 ++++++++++++-- models/config.go | 19 +++++++++++++------ templates/go-swagger/api.yaml.tmpl | 4 +++- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index d43a041..90bd0ac 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -130,9 +130,17 @@ func runInitAction(cmd *cobra.Command, args []string) { log.Info("Description of the project:") config.ProjectDescription = helpers.StringInput() - // ask project owner + // ask project contact + config.ProjectContact = models.ProjectContactStruct{} + log.Info("Mail address of the developer team:") - config.ProjectOwner = helpers.StringInput() + config.ProjectContact.Email = helpers.StringInput() + + log.Info("Name of the team:") + config.ProjectContact.Name = helpers.StringInput() + + log.Info("URL of the contact informatino of the team:") + config.ProjectContact.URL = helpers.StringInput() // launch GetInitializeUserInput from selected api type log.Debug("Get user input for the selected API type") diff --git a/helpers/api_types/go_swagger/generate_api_yamls.go b/helpers/api_types/go_swagger/generate_api_yamls.go index a7369a9..91d32b1 100644 --- a/helpers/api_types/go_swagger/generate_api_yamls.go +++ b/helpers/api_types/go_swagger/generate_api_yamls.go @@ -14,7 +14,13 @@ import ( type apiYamlTemplate struct { ProjectDescription string ProjectName string - ProjectOwner string + ProjectContact apiYamlContact +} + +type apiYamlContact struct { + Email string + Name string + URL string } // generateAPIYamls will generate a readme based on the given config. @@ -45,7 +51,11 @@ func (a APIType) generateAPIYamls(path string, config *models.Config) error { data := apiYamlTemplate{ ProjectDescription: config.ProjectDescription, ProjectName: config.ProjectName, - ProjectOwner: config.ProjectOwner, + ProjectContact: apiYamlContact{ + Email: config.ProjectContact.Email, + Name: config.ProjectContact.Name, + URL: config.ProjectContact.URL, + }, } for _, templateFile := range templateFileList { diff --git a/models/config.go b/models/config.go index 6c2cb94..4d5af1b 100644 --- a/models/config.go +++ b/models/config.go @@ -2,12 +2,19 @@ package models // Config structure represent the main configuration of the project. type Config struct { - ProjectName string `yaml:"project_name"` - ProjectDescription string `yaml:"project_description"` - ProjectOwner string `yaml:"project_owner"` - ProjectType APITypeName `yaml:"project_type"` - ModulePath *string `yaml:"module_name"` - Features FeaturesConfig `yaml:"features"` + ProjectName string `yaml:"project_name"` + ProjectDescription string `yaml:"project_description"` + ProjectContact ProjectContactStruct `yaml:"project_contact"` + ProjectType APITypeName `yaml:"project_type"` + ModulePath *string `yaml:"module_name"` + Features FeaturesConfig `yaml:"features"` +} + +// ProjectContactStruct contain all contact information for that project. +type ProjectContactStruct struct { + Name string `yaml:"name"` + Email string `yaml:"email"` + URL string `yaml:"url"` } // FeaturesConfig structure represent the configuration of all possible features. diff --git a/templates/go-swagger/api.yaml.tmpl b/templates/go-swagger/api.yaml.tmpl index 1112775..7bf7eb6 100644 --- a/templates/go-swagger/api.yaml.tmpl +++ b/templates/go-swagger/api.yaml.tmpl @@ -5,7 +5,9 @@ info: title: "{{ .ProjectName }}" description: "{{ .ProjectDescription }}" contact: - email: "{{ .ProjectOwner }}" + name: "{{ .ProjectContact.Name }}" + email: "{{ .ProjectContact.Email }}" + url: "{{ .ProjectContact.URL }}" consumes: - "application/json" produces: