-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add markdown format for changelog (#588)
- Loading branch information
1 parent
ca3ab5d
commit 4822df6
Showing
12 changed files
with
171 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# API Changelog 1.0.0 vs. 1.0.1 | ||
|
||
## GET /api/{domain}/{project}/badges/security-score | ||
- :warning: removed the success response with the status '200' | ||
- :warning: removed the success response with the status '201' | ||
- :warning: deleted the 'cookie' request parameter 'test' | ||
- :warning: deleted the 'header' request parameter 'user' | ||
- :warning: deleted the 'query' request parameter 'filter' | ||
- api operation id 'GetSecurityScores' removed and replaced with 'GetSecurityScore' | ||
- api tag 'security' removed | ||
- for the 'query' request parameter 'token', the maxLength was increased from '29' to '30' | ||
- removed the pattern '^(?:[\w-./:]+)$' from the 'query' request parameter 'image' | ||
- for the 'query' request parameter 'image', the type/format was generalized from 'string'/'general string' to ''/'' | ||
- removed the non-success response with the status '400' | ||
|
||
|
||
## GET /api/{domain}/{project}/install-command | ||
- :warning: deleted the 'header' request parameter 'network-policies' | ||
- added the new optional 'header' request parameter 'name' to all path's operations | ||
- added the new enum value 'test1' to the 'path' request parameter 'project' | ||
|
||
|
||
## POST /register | ||
- the endpoint scheme security 'bearerAuth' was removed from the API | ||
- the security scope 'write:pets' was added to the endpoint's security scheme 'OAuth' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package formatters | ||
|
||
import ( | ||
"bytes" | ||
"text/template" | ||
|
||
_ "embed" | ||
|
||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
"github.com/tufin/oasdiff/load" | ||
"github.com/tufin/oasdiff/report" | ||
) | ||
|
||
type MarkupFormatter struct { | ||
notImplementedFormatter | ||
Localizer checker.Localizer | ||
} | ||
|
||
func newMarkupFormatter(l checker.Localizer) MarkupFormatter { | ||
return MarkupFormatter{ | ||
Localizer: l, | ||
} | ||
} | ||
|
||
func (f MarkupFormatter) RenderDiff(diff *diff.Diff, opts RenderOpts) ([]byte, error) { | ||
return []byte(report.GetTextReportAsString(diff)), nil | ||
} | ||
|
||
//go:embed templates/changelog.md | ||
var changelogMarkdown string | ||
|
||
func (f MarkupFormatter) RenderChangelog(changes checker.Changes, opts RenderOpts, specInfoPair *load.SpecInfoPair) ([]byte, error) { | ||
tmpl := template.Must(template.New("changelog").Parse(changelogMarkdown)) | ||
return ExecuteTextTemplate(tmpl, GroupChanges(changes, f.Localizer), specInfoPair) | ||
} | ||
|
||
func ExecuteTextTemplate(tmpl *template.Template, changes ChangesByEndpoint, specInfoPair *load.SpecInfoPair) ([]byte, error) { | ||
var out bytes.Buffer | ||
if err := tmpl.Execute(&out, TemplateData{changes, specInfoPair.GetBaseVersion(), specInfoPair.GetRevisionVersion()}); err != nil { | ||
return nil, err | ||
} | ||
return out.Bytes(), nil | ||
} | ||
|
||
func (f MarkupFormatter) SupportedOutputs() []Output { | ||
return []Output{OutputDiff, OutputChangelog} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package formatters_test | ||
|
||
import ( | ||
"testing" | ||
"text/template" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/formatters" | ||
) | ||
|
||
var markupFormatter = formatters.MarkupFormatter{ | ||
Localizer: MockLocalizer, | ||
} | ||
|
||
func TestMarkupLookup(t *testing.T) { | ||
f, err := formatters.Lookup(string(formatters.FormatMarkup), formatters.DefaultFormatterOpts()) | ||
require.NoError(t, err) | ||
require.IsType(t, formatters.MarkupFormatter{}, f) | ||
} | ||
|
||
func TestMarkupFormatter_RenderDiff(t *testing.T) { | ||
out, err := markupFormatter.RenderDiff(nil, formatters.NewRenderOpts()) | ||
require.NoError(t, err) | ||
require.Equal(t, string(out), "No changes\n") | ||
} | ||
|
||
func TestMarkupFormatter_RenderChangelog(t *testing.T) { | ||
testChanges := checker.Changes{ | ||
checker.ApiChange{ | ||
Path: "/test", | ||
Operation: "GET", | ||
Id: "change_id", | ||
Level: checker.ERR, | ||
}, | ||
} | ||
|
||
out, err := markupFormatter.RenderChangelog(testChanges, formatters.NewRenderOpts(), nil) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, string(out)) | ||
} | ||
|
||
func TestMarkupFormatter_NotImplemented(t *testing.T) { | ||
var err error | ||
|
||
_, err = markupFormatter.RenderChecks(formatters.Checks{}, formatters.NewRenderOpts()) | ||
assert.Error(t, err) | ||
|
||
_, err = markupFormatter.RenderFlatten(nil, formatters.NewRenderOpts()) | ||
assert.Error(t, err) | ||
|
||
_, err = markupFormatter.RenderSummary(nil, formatters.NewRenderOpts()) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestExecuteMarkupTemplate_Err(t *testing.T) { | ||
_, err := formatters.ExecuteTextTemplate(&template.Template{}, nil, nil) | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# API Changelog {{ .BaseVersion }}{{ if ne .BaseVersion .RevisionVersion }} vs. {{ .RevisionVersion }}{{ end }} | ||
{{ range $endpoint, $changes := .APIChanges }} | ||
## {{ $endpoint.Operation }} {{ $endpoint.Path }} | ||
{{ range $changes }}- {{ if .IsBreaking }}:warning:{{ end }} {{ .Text }} | ||
{{ end }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters