Skip to content

Commit

Permalink
Remove default sorting, exclude default variable parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevsaddam committed Jan 25, 2022
1 parent 09aa111 commit 7727689
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 48 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
docgen
vendor
.idea
linux_386
linux_amd64
mac_amd64
windows_386.exe
windows_amd64.exe
bin/linux_386
bin/linux_amd64
bin/linux_arm64
bin/darwin_amd64
bin/darwin_arm64
bin/windows_386.exe
bin/windows_amd64.exe
2 changes: 1 addition & 1 deletion assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ <h3 class="panel-title">
<footer class="navbar-default navbar-fixed-bottom">
<div class="container-fluid">
<div class="span12 text-center">
<span data-toggle="tooltip" title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Made with <em class="love-color">&#9829;</em> by <a href="https://github.com/thedevsaddam" target="_blank" class="text-muted">thedevsaddam</a> | Generated at: @{{date_time}}@ by <a href="https://github.com/thedevsaddam/docgen" target="_blank" class="text-muted">docgen</a></span>
<span data-toggle="tooltip" title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Generated at @{{date_time}}@ by <a href="https://github.com/thedevsaddam/docgen" target="_blank" class="text-muted">docgen</a></span>
</div>
</div>
</footer>
Expand Down
35 changes: 20 additions & 15 deletions assets/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
@{{- /* End if we have more than one collection */}}@
@{{- end }}@

<!--- Variables --->
@{{ if .Data.Variables }}@
## Variables

<!--- Iterate variables -->
| Key | Value | Type |
| --- | ------|-------------|
@{{ range $ih, $v := .Data.Variables -}}@
| @{{ $v.Key }}@ | @{{ $v.Value }}@ | @{{ $v.Type }}@ |
@{{ end }}@
<!--- End Iterate headers items -->

<!--- End headers items -->
@{{ end }}@
<!--- End Variables --->

## Endpoints

<!--- If we have more than one group/collection, then display each group name heading -->
@{{- if gt $numCollections 1 }}@
@{{- range $index, $c := .Data.Collections }}@
Expand Down Expand Up @@ -284,21 +302,8 @@ URL: @{{ $item.Request.URL.Raw | trimQueryParams | e }}@
<!--- End Iterate main collection -->
@{{ end }}@

<!--- Variables --->
@{{ if .Data.Variables }}@
***Available Variables:***

<!--- Iterate variables -->
| Key | Value | Type |
| --- | ------|-------------|
@{{ range $ih, $v := .Data.Variables -}}@
| @{{ $v.Key }}@ | @{{ $v.Value }}@ | @{{ $v.Type }}@ |
@{{ end }}@
<!--- End Iterate headers items -->

<!--- End headers items -->
@{{ end }}@

---
[Back to top](#@{{ .Data.Info.Name | trim | glink }}@)
> Made with &#9829; by [thedevsaddam](https://github.com/thedevsaddam) | Generated at: @{{date_time}}@ by [docgen](https://github.com/thedevsaddam/docgen)

>Generated at @{{date_time}}@ by [docgen](https://github.com/thedevsaddam/docgen)
28 changes: 14 additions & 14 deletions assets_bin/assets.go

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
)

var (
in string
out string
env string
isMarkdown bool
envCollection = &collection.Environment{}
buildOutput = &cobra.Command{
in string
out string
env string
isMarkdown bool
includeVariable bool
sorted bool
envCollection = &collection.Environment{}
buildOutput = &cobra.Command{
Use: "build",
Short: "Build html/markdown documentation from postman collection",
Long: `Build html/markdown documentation from postman collection`,
Expand All @@ -25,6 +27,8 @@ func init() {
buildOutput.PersistentFlags().StringVarP(&in, "in", "i", "", "postman collection path")
buildOutput.PersistentFlags().StringVarP(&out, "out", "o", "", "output file path")
buildOutput.PersistentFlags().BoolVarP(&isMarkdown, "md", "m", false, "this flag will command to generate markdown")
buildOutput.PersistentFlags().BoolVarP(&includeVariable, "var", "v", false, "this flag will include variables in template")
buildOutput.PersistentFlags().BoolVarP(&sorted, "sort", "s", false, "this flag will sort the collection in ascending order")
buildOutput.PersistentFlags().StringVarP(&extraCSS, "css", "c", "", "inject a css file")
buildOutput.PersistentFlags().StringVarP(&env, "env", "e", "", "postman environment variable file path")
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ func readJSONtoHTML(str string) *bytes.Buffer {
}

// populate envCollection with collection variables
if len(rt.Variables) > 0 {
if len(rt.Variables) > 0 && includeVariable {
envCollection.SetCollectionVariables(rt.Variables)
}

if sorted {
rt.SortCollections()
}

// override collection variables by env variables
if env != "" {
if _, err := os.Stat(env); os.IsNotExist(err) {
Expand Down Expand Up @@ -175,10 +179,14 @@ func readJSONtoMarkdown(str string) *bytes.Buffer {
}

// populate envCollection with collection variables
if len(rt.Variables) > 0 {
if len(rt.Variables) > 0 && includeVariable {
envCollection.SetCollectionVariables(rt.Variables)
}

if sorted {
rt.SortCollections()
}

// override collection variables by env variables
if env != "" {
if _, err := os.Stat(env); os.IsNotExist(err) {
Expand Down Expand Up @@ -238,10 +246,14 @@ func readJSONtoMarkdownHTML(str string) *bytes.Buffer {
}

// populate envCollection with collection variables
if len(rt.Variables) > 0 {
if len(rt.Variables) > 0 && includeVariable {
envCollection.SetCollectionVariables(rt.Variables)
}

if sorted {
rt.SortCollections()
}

// override collection variables by env variables
if env != "" {
if _, err := os.Stat(env); os.IsNotExist(err) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func init() {
serveLive.PersistentFlags().IntVarP(&port, "port", "p", 9000, "port number to listen")
serveLive.PersistentFlags().StringVarP(&file, "file", "f", "", "postman collection path")
serveLive.PersistentFlags().BoolVarP(&isMarkdown, "md", "m", false, "display markdown format in preview")
serveLive.PersistentFlags().BoolVarP(&includeVariable, "var", "v", false, "this flag will include variables in template")
serveLive.PersistentFlags().BoolVarP(&sorted, "sort", "s", false, "this flag will sort the collection in ascending order")
serveLive.PersistentFlags().StringVarP(&extraCSS, "css", "c", "", "inject a css file")
serveLive.PersistentFlags().StringVarP(&env, "env", "e", "", "postman environment variable file path")
}
Expand Down
8 changes: 4 additions & 4 deletions collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (d *Documentation) Open(rdr io.Reader) error {
d.removeItemResponseRequestDisabledField()

// sort the collections in lexical order
d.sortCollections()
// d.sortCollections()

return nil
}
Expand Down Expand Up @@ -163,16 +163,16 @@ func (d *Documentation) buildSubChildItems(itm Item, c *Collection, pn string) b
return false
}

// sortCollections sorts the collections in the alphabetical order(except for the default)
func (d *Documentation) sortCollections() {
// SortCollections sorts the collections in the alphabetical order(except for the default)
func (d *Documentation) SortCollections() {
sort.Slice(d.Collections, func(i int, j int) bool {
if d.Collections[i].Name == defaultCollection {
return false
}
return d.Collections[i].Name < d.Collections[j].Name
})

for index, _ := range d.Collections {
for index := range d.Collections {
sort.Slice(d.Collections[index].Items, func(i, j int) bool {
return d.Collections[index].Items[i].Name < d.Collections[index].Items[j].Name
})
Expand Down

0 comments on commit 7727689

Please sign in to comment.