Skip to content

Commit

Permalink
implement disable of 'Models' section
Browse files Browse the repository at this point in the history
The section of 'Models' always is created if there is any model
used during the Api definition, with this change we enable the
tool to not to add this section if the user wants.
'models' parameter which default value is true indicates whether
you want the models section to be generated or not, if you pass the
'-models=false' parameter then the models section will not bee added
to the generated output.

Signed-off-by: Leoswaldo Macias <lmaciasm10@gmail.com>
  • Loading branch information
leoswaldo committed Aug 10, 2016
1 parent 49962d8 commit 869c750
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func InitParser(controllerClass, ignore string) *parser.Parser {

type Params struct {
ApiPackage, MainApiFile, OutputFormat, OutputSpec, ControllerClass, Ignore string
ContentsTable bool
ContentsTable, Models bool
}

func Run(params Params) error {
Expand Down Expand Up @@ -170,13 +170,13 @@ func Run(params Params) error {
err = generateSwaggerDocs(parser, params.OutputSpec)
confirmMsg = "Doc file generated"
case "asciidoc":
err = markup.GenerateMarkup(parser, new(markup.MarkupAsciiDoc), &params.OutputSpec, ".adoc", params.ContentsTable)
err = markup.GenerateMarkup(parser, new(markup.MarkupAsciiDoc), &params.OutputSpec, ".adoc", params.ContentsTable, params.Models)
confirmMsg = "AsciiDoc file generated"
case "markdown":
err = markup.GenerateMarkup(parser, new(markup.MarkupMarkDown), &params.OutputSpec, ".md", params.ContentsTable)
err = markup.GenerateMarkup(parser, new(markup.MarkupMarkDown), &params.OutputSpec, ".md", params.ContentsTable, params.Models)
confirmMsg = "MarkDown file generated"
case "confluence":
err = markup.GenerateMarkup(parser, new(markup.MarkupConfluence), &params.OutputSpec, ".confluence", params.ContentsTable)
err = markup.GenerateMarkup(parser, new(markup.MarkupConfluence), &params.OutputSpec, ".confluence", params.ContentsTable, params.Models)
confirmMsg = "Confluence file generated"
case "swagger":
err = generateSwaggerUiFiles(parser, params.OutputSpec)
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var outputSpec = flag.String("output", "", "Output (path) for the generated file
var controllerClass = flag.String("controllerClass", "", "Speed up parsing by specifying which receiver objects have the controller methods")
var ignore = flag.String("ignore", "^$", "Ignore packages that satisfy this match")
var contentsTable = flag.Bool("contentsTable", true, "Generate the section Table of Contents")
var models = flag.Bool("models", true, "Generate the section models if any defined")

func main() {
flag.Parse()
Expand All @@ -35,6 +36,7 @@ func main() {
ControllerClass: *controllerClass,
Ignore: *ignore,
ContentsTable: *contentsTable,
Models: *models,
}

err := generator.Run(params)
Expand Down
34 changes: 16 additions & 18 deletions markup/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Markup interface {
colorSpan(content, foregroundColor, backgroundColor string) string
}

func GenerateMarkup(parser *parser.Parser, markup Markup, outputSpec *string, defaultFileExtension string, tableContents bool) error {
func GenerateMarkup(parser *parser.Parser, markup Markup, outputSpec *string, defaultFileExtension string, tableContents bool, models bool) error {
var filename string
if *outputSpec == "" {
filename = path.Join("./", "API") + defaultFileExtension
Expand Down Expand Up @@ -149,28 +149,26 @@ func GenerateMarkup(parser *parser.Parser, markup Markup, outputSpec *string, de
/***************************************************************
* Models
***************************************************************/
if len(apiDescription.Models) > 0 {
if len(apiDescription.Models) > 0 && models {
buf.WriteString("\n")
buf.WriteString(markup.sectionHeader(3, "Models"))
buf.WriteString("\n")
}

for _, modelKey := range alphabeticalKeysOfModels(apiDescription.Models) {
model := apiDescription.Models[modelKey]
if tableContents {
buf.WriteString(markup.anchor(modelKey))
}
buf.WriteString(markup.sectionHeader(4, markup.colorSpan(shortModelName(modelKey), color_MODEL_TEXT, color_NORMAL_BACKGROUND)))
buf.WriteString(markup.tableHeader(""))
buf.WriteString(markup.tableHeaderRow("Field Name (alphabetical)", "Field Type", "Description"))
for _, fieldName := range alphabeticalKeysOfFields(model.Properties) {
fieldProps := model.Properties[fieldName]
buf.WriteString(markup.tableRow(fieldName, fieldProps.Type, fieldProps.Description))
for _, modelKey := range alphabeticalKeysOfModels(apiDescription.Models) {
model := apiDescription.Models[modelKey]
if tableContents {
buf.WriteString(markup.anchor(modelKey))
}
buf.WriteString(markup.sectionHeader(4, markup.colorSpan(shortModelName(modelKey), color_MODEL_TEXT, color_NORMAL_BACKGROUND)))
buf.WriteString(markup.tableHeader(""))
buf.WriteString(markup.tableHeaderRow("Field Name (alphabetical)", "Field Type", "Description"))
for _, fieldName := range alphabeticalKeysOfFields(model.Properties) {
fieldProps := model.Properties[fieldName]
buf.WriteString(markup.tableRow(fieldName, fieldProps.Type, fieldProps.Description))
}
buf.WriteString(markup.tableFooter())
}
buf.WriteString(markup.tableFooter())
buf.WriteString("\n")
}
buf.WriteString("\n")

}

fd.WriteString(buf.String())
Expand Down

0 comments on commit 869c750

Please sign in to comment.