Bumps the minor-and-patch group with 3 updates in the / directory: [github.com/gabriel-vasile/mimetype](https://github.com/gabriel-vasile/mimetype), [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) and [github.com/rogpeppe/go-internal](https://github.com/rogpeppe/go-internal). Updates `github.com/gabriel-vasile/mimetype` from 1.4.13 to 1.4.15 - [Release notes](https://github.com/gabriel-vasile/mimetype/releases) - [Commits](https://github.com/gabriel-vasile/mimetype/compare/v1.4.13...v1.4.15) Updates `github.com/open-policy-agent/opa` from 1.18.2 to 1.19.0 - [Release notes](https://github.com/open-policy-agent/opa/releases) - [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-policy-agent/opa/compare/v1.18.2...v1.19.0) Updates `github.com/rogpeppe/go-internal` from 1.15.0 to 1.16.0 - [Release notes](https://github.com/rogpeppe/go-internal/releases) - [Commits](https://github.com/rogpeppe/go-internal/compare/v1.15.0...v1.16.0) --- updated-dependencies: - dependency-name: github.com/gabriel-vasile/mimetype dependency-version: 1.4.15 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch - dependency-name: github.com/open-policy-agent/opa dependency-version: 1.19.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch - dependency-name: github.com/rogpeppe/go-internal dependency-version: 1.16.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
125 lines
2.4 KiB
Go
125 lines
2.4 KiB
Go
//go:build !go1.27
|
|
|
|
package ast
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
astJSON "github.com/open-policy-agent/opa/v1/ast/json"
|
|
)
|
|
|
|
func (a *Annotations) MarshalJSON() ([]byte, error) {
|
|
if a == nil {
|
|
return []byte(`{"scope":""}`), nil
|
|
}
|
|
|
|
data := map[string]any{
|
|
"scope": a.Scope,
|
|
}
|
|
|
|
if a.Title != "" {
|
|
data["title"] = a.Title
|
|
}
|
|
|
|
if a.Description != "" {
|
|
data["description"] = a.Description
|
|
}
|
|
|
|
if a.Entrypoint {
|
|
data["entrypoint"] = a.Entrypoint
|
|
}
|
|
|
|
if len(a.Organizations) > 0 {
|
|
data["organizations"] = a.Organizations
|
|
}
|
|
|
|
if len(a.RelatedResources) > 0 {
|
|
data["related_resources"] = a.RelatedResources
|
|
}
|
|
|
|
if len(a.Authors) > 0 {
|
|
data["authors"] = a.Authors
|
|
}
|
|
|
|
if len(a.Schemas) > 0 {
|
|
data["schemas"] = a.Schemas
|
|
}
|
|
|
|
if a.Compile != nil {
|
|
data["compile"] = a.Compile
|
|
}
|
|
|
|
if len(a.Custom) > 0 {
|
|
data["custom"] = a.Custom
|
|
}
|
|
|
|
if len(a.Labels) > 0 {
|
|
data["labels"] = a.Labels
|
|
}
|
|
|
|
if astJSON.GetOptions().MarshalOptions.IncludeLocation.Annotations {
|
|
if a.Location != nil {
|
|
data["location"] = a.Location
|
|
}
|
|
}
|
|
|
|
return json.Marshal(data)
|
|
}
|
|
|
|
func (rr *RelatedResourceAnnotation) MarshalJSON() ([]byte, error) {
|
|
d := map[string]any{
|
|
"ref": rr.Ref.String(),
|
|
}
|
|
|
|
if len(rr.Description) > 0 {
|
|
d["description"] = rr.Description
|
|
}
|
|
|
|
return json.Marshal(d)
|
|
}
|
|
|
|
func (ar *AnnotationsRef) MarshalJSON() ([]byte, error) {
|
|
data := map[string]any{
|
|
"path": ar.Path,
|
|
}
|
|
|
|
if ar.Annotations != nil {
|
|
data["annotations"] = ar.Annotations
|
|
}
|
|
|
|
if astJSON.GetOptions().MarshalOptions.IncludeLocation.AnnotationsRef {
|
|
if ar.Location != nil {
|
|
data["location"] = ar.Location
|
|
}
|
|
}
|
|
|
|
return json.Marshal(data)
|
|
}
|
|
|
|
// schemaAnnotationJSON mirrors SchemaAnnotation's JSON tags, with location-free
|
|
// path terms.
|
|
type schemaAnnotationJSON struct {
|
|
Path []termJSON `json:"path"`
|
|
Schema Ref `json:"schema,omitempty"`
|
|
Definition *any `json:"definition,omitempty"`
|
|
}
|
|
|
|
func (s *SchemaAnnotation) MarshalJSON() ([]byte, error) {
|
|
d := schemaAnnotationJSON{
|
|
Schema: s.Schema,
|
|
Definition: s.Definition,
|
|
}
|
|
|
|
if s.Path != nil {
|
|
d.Path = make([]termJSON, len(s.Path))
|
|
for i, t := range s.Path {
|
|
// The location is omitted: path terms are parsed on their own from
|
|
// the annotation's YAML key, so their locations are offsets into that
|
|
// key (always row 1) rather than positions in the module.
|
|
d.Path[i] = termJSON{Type: ValueName(t.Value), Value: t.Value}
|
|
}
|
|
}
|
|
|
|
return json.Marshal(d)
|
|
}
|