Skip to content

Commit 64eb29f

Browse files
committed
feat: add normalized publiccode.yml to validation response
Reply with a normalized canonical equivalent publiccoden.yml when validation succeeds so clients don't need to deal with deprecated fields, aliases or renames on their side. Fix #42.
1 parent 7ec5032 commit 64eb29f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/handlers/validate.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func NewPubliccodeymlValidatorHandler() *PubliccodeymlValidatorHandler {
2929
}
3030

3131
func (vh *PubliccodeymlValidatorHandler) Query(ctx *fiber.Ctx) error {
32+
var normalized *string
3233
valid := true
3334
parser := vh.parser
3435

@@ -51,7 +52,7 @@ func (vh *PubliccodeymlValidatorHandler) Query(ctx *fiber.Ctx) error {
5152

5253
reader := bytes.NewReader(ctx.Body())
5354

54-
_, err := parser.ParseStream(reader)
55+
parsed, err := parser.ParseStream(reader)
5556
if err != nil {
5657
var validationResults publiccodeParser.ValidationResults
5758
if errors.As(err, &validationResults) {
@@ -66,5 +67,13 @@ func (vh *PubliccodeymlValidatorHandler) Query(ctx *fiber.Ctx) error {
6667
}
6768
}
6869

69-
return ctx.JSON(fiber.Map{"valid": valid, "results": results})
70+
if valid && parsed != nil {
71+
yaml, err := parsed.ToYAML()
72+
if err == nil {
73+
s := string(yaml)
74+
normalized = &s
75+
}
76+
}
77+
78+
return ctx.JSON(fiber.Map{"valid": valid, "results": results, "normalized": normalized})
7079
}

0 commit comments

Comments
 (0)