Skip to content

Commit

Permalink
Merge pull request #90 from Tufin/add-servers-to-report
Browse files Browse the repository at this point in the history
Add servers to report
  • Loading branch information
Reuven Harrison authored Mar 25, 2022
2 parents e32fbd4 + ac28273 commit 3864f1d
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
1. Run `oasdiff <flags> -base <spec1> -revision <spec2>`
2. With <spec1-URL> or attachment
3. And <spec2-URL> or attachment
4. Recieve <snippet of incorrect diff>

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ No output means that the diff is empty, or, in other words, there are no changes
```bash
oasdiff -format text -base data/openapi-test1.yaml -revision data/openapi-test2.yaml
```
The Text/Markdown diff report provides a simplified view of the changes.
To view all details, use the default format: YAML.
The Text/Markdown diff report provides a simplified and partial view of the changes.
To view all details, use the default format: YAML.
If you'd like to see additional details in the text/markdown report, please submit a [feature request](https://github.com/Tufin/oasdiff/issues/new?assignees=&labels=&template=feature_request.md&title=).

### HTML diff of local files
```bash
oasdiff -format text -base data/openapi-test1.yaml -revision data/openapi-test2.yaml
```
The HTML diff report provides a simplified view of the changes.
To view all details, use the default format: YAML.
The HTML diff report provides a simplified and partial view of the changes.
To view all details, use the default format: YAML.
If you'd like to see additional details in the HTML report, please submit a [feature request](https://github.com/Tufin/oasdiff/issues/new?assignees=&labels=&template=feature_request.md&title=).


### Text/Markdown diff of http files

Expand Down
11 changes: 11 additions & 0 deletions diff/servers_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ type ServersDiff struct {
// ModifiedServers is map of server names to their respective diffs
type ModifiedServers map[string]*ServerDiff

// ToStringList returns the modified server names
func (modifiedServers ModifiedServers) ToStringList() StringList {
keys := make(StringList, len(modifiedServers))
i := 0
for k := range modifiedServers {
keys[i] = k
i++
}
return keys
}

// Empty indicates whether a change was found in this element
func (diff *ServersDiff) Empty() bool {
if diff == nil {
Expand Down
11 changes: 11 additions & 0 deletions diff/variables_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ type VariablesDiff struct {
// ModifiedVariables is map of variable names to their respective diffs
type ModifiedVariables map[string]*VariableDiff

// ToStringList returns the modified variable names
func (modifiedVariables ModifiedVariables) ToStringList() StringList {
keys := make(StringList, len(modifiedVariables))
i := 0
for k := range modifiedVariables {
keys[i] = k
i++
}
return keys
}

// Empty indicates whether a change was found in this element
func (diff *VariablesDiff) Empty() bool {
if diff == nil {
Expand Down
16 changes: 16 additions & 0 deletions report/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func ExampleGetTextReportAsString() {
// - Headers changed
// - Modified header: X-RateLimit-Limit
// - Description changed from 'Request limit per hour.' to 'Request limit per min.'
// - Servers changed
// - New server: https://tufin.io/securecloud
// - New server: https://www.tufin.io/securecloud
//
// POST /register
// - Callbacks changed
Expand All @@ -82,6 +85,9 @@ func ExampleGetTextReportAsString() {
//
// POST /subscribe
// - Callbacks changed
//
// Servers changed
// - Deleted server: tufin.com
}

func ExampleGetHTMLReportAsString() {
Expand Down Expand Up @@ -190,6 +196,12 @@ func ExampleGetHTMLReportAsString() {
// </li>
// </ul>
// </li>
// <li>Servers changed
// <ul>
// <li>New server: <a href="https://tufin.io/securecloud">https://tufin.io/securecloud</a></li>
// <li>New server: <a href="https://www.tufin.io/securecloud">https://www.tufin.io/securecloud</a></li>
// </ul>
// </li>
// </ul>
// <p>POST /register</p>
// <ul>
Expand All @@ -209,4 +221,8 @@ func ExampleGetHTMLReportAsString() {
// <ul>
// <li>Callbacks changed</li>
// </ul>
// <p>Servers changed</p>
// <ul>
// <li>Deleted server: tufin.com</li>
// </ul>
}
109 changes: 99 additions & 10 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,65 @@ func (r *report) output(d *diff.Diff) {

if d.EndpointsDiff.Empty() {
r.print("No endpoint changes")
return
} else {
r.printEndpoints(d.EndpointsDiff)
}

r.printTitle("New Endpoints", len(d.EndpointsDiff.Added))
sort.Sort(d.EndpointsDiff.Added)
for _, added := range d.EndpointsDiff.Added {
if !d.ServersDiff.Empty() {
r.print("Servers changed")
r.indent().printServers(d.ServersDiff)
}
}

func (r *report) printEndpoints(d *diff.EndpointsDiff) {

r.printTitle("New Endpoints", len(d.Added))
sort.Sort(d.Added)
for _, added := range d.Added {
r.print(added.Method, added.Path, " ")
}
r.print("")

r.printTitle("Deleted Endpoints", len(d.EndpointsDiff.Deleted))
sort.Sort(d.EndpointsDiff.Deleted)
for _, deleted := range d.EndpointsDiff.Deleted {
r.printTitle("Deleted Endpoints", len(d.Deleted))
sort.Sort(d.Deleted)
for _, deleted := range d.Deleted {
r.print(deleted.Method, deleted.Path, " ")
}
r.print("")

r.printTitle("Modified Endpoints", len(d.EndpointsDiff.Modified))
keys := d.EndpointsDiff.Modified.ToEndpoints()
r.printTitle("Modified Endpoints", len(d.Modified))
keys := d.Modified.ToEndpoints()
sort.Sort(keys)
for _, endpoint := range keys {
r.print(endpoint.Method, endpoint.Path)
r.indent().printMethod(d.EndpointsDiff.Modified[endpoint])
r.indent().printMethod(d.Modified[endpoint])
r.print("")
}
}

func (r *report) printServers(d *diff.ServersDiff) {
if d.Empty() {
return
}

sort.Sort(d.Added)
for _, added := range d.Added {
r.print("New server:", added)
}

sort.Sort(d.Deleted)
for _, deleted := range d.Deleted {
r.print("Deleted server:", deleted)
}

keys := d.Modified.ToStringList()
sort.Sort(keys)
for _, server := range keys {
r.print("Modified server:", server)
r.indent().printServer(d.Modified[server])
}
}

func (r *report) printMethod(d *diff.MethodDiff) {
if d.Empty() {
return
Expand All @@ -104,6 +136,11 @@ func (r *report) printMethod(d *diff.MethodDiff) {
r.print("Security changed")
r.indent().printSecurityRequirements(d.SecurityDiff)
}

if !d.ServersDiff.Empty() {
r.print("Servers changed")
r.indent().printServers(d.ServersDiff)
}
}

func (r *report) printParams(d *diff.ParametersDiff) {
Expand Down Expand Up @@ -166,6 +203,58 @@ func (r *report) printRequiredProperties(d *diff.RequiredPropertiesDiff) {
}
}

func (r *report) printServer(d *diff.ServerDiff) {
if d.Empty() {
return
}

r.printConditional(d.Added, "Server added")
r.printConditional(d.Deleted, "Server deleted")
r.printValue(d.URLDiff, "URL")
r.printValue(d.DescriptionDiff, "Description")
if !d.VariablesDiff.Empty() {
r.print("Variables changed")
r.indent().printVariables(d.VariablesDiff)
}
}

func (r *report) printVariables(d *diff.VariablesDiff) {
if d.Empty() {
return
}

sort.Sort(d.Added)
for _, variable := range d.Added {
r.print("New variable:", variable)
}

sort.Sort(d.Deleted)
for _, variable := range d.Deleted {
r.print("Deleted variable:", variable)
}

keys := d.Modified.ToStringList()
sort.Sort(keys)
for _, variable := range keys {
r.print("Modified variable:", variable)
r.indent().printVariable(d.Modified[variable])
}

}

func (r *report) printVariable(d *diff.VariableDiff) {
if d.Empty() {
return
}

if !d.EnumDiff.Empty() {
r.printConditional(len(d.EnumDiff.Added) > 0, "New enum values:", d.EnumDiff.Added)
r.printConditional(len(d.EnumDiff.Deleted) > 0, "Deleted enum values:", d.EnumDiff.Deleted)
}
r.printValue(d.DefaultDiff, "Default")
r.printValue(d.DescriptionDiff, "Description")
}

func (r *report) printSchema(d *diff.SchemaDiff) {
if d.Empty() {
return
Expand Down

0 comments on commit 3864f1d

Please sign in to comment.