Skip to content

Commit

Permalink
add yaml annotations on struct fields (#52)
Browse files Browse the repository at this point in the history
This will make the Backstage structs decode fine when unMarshalling a
yaml document. No functionality changed.
  • Loading branch information
tdabasinskas authored Jun 11, 2024
2 parents ecf92c3 + fa0f351 commit 7f78c0d
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 105 deletions.
70 changes: 35 additions & 35 deletions backstage/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,142 +13,142 @@ import (
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/Entity.schema.json
type Entity struct {
// ApiVersion is the version of specification format for this particular entity that this is written against.
ApiVersion string `json:"apiVersion"`
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`

// Kind is the high level entity type being described.
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Metadata is metadata related to the entity. Should always be "System".
Metadata EntityMeta `json:"metadata"`
Metadata EntityMeta `json:"metadata" yaml:"metadata"`

// Spec is the specification data describing the entity itself.
Spec map[string]interface{} `json:"spec,omitempty"`
Spec map[string]interface{} `json:"spec,omitempty" yaml:"spec,omitempty"`

// Relations that this entity has with other entities.
Relations []EntityRelation `json:"relations,omitempty"`
Relations []EntityRelation `json:"relations,omitempty" yaml:"relations,omitempty"`

// The current status of the entity, as claimed by various sources.
Status *EntityStatus `json:"status,omitempty"`
Status *EntityStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// EntityMeta represents metadata fields common to all versions/kinds of entity.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/EntityMeta.schema.json
type EntityMeta struct {
// UID A globally unique ID for the entity. This field can not be set by the user at creation time, and the server will reject
// an attempt to do so. The field will be populated in read operations.
UID string `json:"uid,omitempty"`
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`

// Etag is an opaque string that changes for each update operation to any part of the entity, including metadata. This field
// can not be set by the user at creation time, and the server will reject an attempt to do so. The field will be populated in read
// operations.The field can (optionally) be specified when performing update or delete operations, and the server will then reject
// the operation if it does not match the current stored value.
Etag string `json:"etag,omitempty"`
Etag string `json:"etag,omitempty" yaml:"etag,omitempty"`

// Name of the entity. Must be unique within the catalog at any given point in time, for any given namespace + kind pair.
Name string `json:"name"`
Name string `json:"name" yaml:"name"`

// Namespace that the entity belongs to.
Namespace string `json:"namespace,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`

// Title is a display name of the entity, to be presented in user interfaces instead of the name property, when available.
Title string `json:"title,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`

// Description is a short (typically relatively few words, on one line) description of the entity.
Description string `json:"description,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`

// Labels are key/value pairs of identifying information attached to the entity.
Labels map[string]string `json:"labels,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`

// Annotations are key/value pairs of non-identifying auxiliary information attached to the entity.
Annotations map[string]string `json:"annotations,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`

// Tags is a list of single-valued strings, to for example classify catalog entities in various ways.
Tags []string `json:"tags,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`

// Links is a list of external hyperlinks related to the entity. Links can provide additional contextual
// information that may be located outside of Backstage itself. For example, an admin dashboard or external CMS page.
Links []EntityLink `json:"links,omitempty"`
Links []EntityLink `json:"links,omitempty" yaml:"links,omitempty"`
}

// EntityLink represents a link to external information that is related to the entity.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/EntityMeta.schema.json
type EntityLink struct {
// URL in a standard uri format.
URL string `json:"url"`
URL string `json:"url" yaml:"url"`

// Title is a user-friendly display name for the link.
Title string `json:"title,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`

// Icon is a key representing a visual icon to be displayed in the UI.
Icon string `json:"icon,omitempty"`
Icon string `json:"icon,omitempty" yaml:"icon,omitempty"`

// Type is an optional value to categorize links into specific groups.
Type string `json:"type,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
}

// EntityRelation is a directed relation from one entity to another.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityRelation struct {
// Type of the relation.
Type string `json:"type"`
Type string `json:"type" yaml:"type"`

// TargetRef is the entity ref of the target of this relation.
TargetRef string `json:"targetRef"`
TargetRef string `json:"targetRef" yaml:"targetRef"`

// Target is the entity of the target of this relation.
Target EntityRelationTarget `json:"target"`
Target EntityRelationTarget `json:"target" yaml:"target"`
}

// EntityRelationTarget describes the target of an entity relation.
type EntityRelationTarget struct {
// Name of the target entity. Must be unique within the catalog at any given point in time, for any given namespace + kind pair.
Name string `json:"name"`
Name string `json:"name" yaml:"name"`

// Kind is the high level target entity type being described.
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Namespace that the target entity belongs to.
Namespace string `json:"namespace"`
Namespace string `json:"namespace" yaml:"namespace"`
}

// EntityStatus informs current status of the entity, as claimed by various sources.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatus struct {
// A specific status item on a well known format.
Items []EntityStatusItem `json:"items,omitempty"`
Items []EntityStatusItem `json:"items,omitempty" yaml:"items,omitempty"`
}

// EntityStatusItem contains a specific status item on a well known format.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatusItem struct {
// The item type
Type string `json:"type"`
Type string `json:"type" yaml:"type"`

// The status level / severity of the status item.
// Either ["info", "warning", "error"]
Level string `json:"level"`
Level string `json:"level" yaml:"level"`

// A brief message describing the status, intended for human consumption.
Message string `json:"message"`
Message string `json:"message" yaml:"message"`

// An optional serialized error object related to the status.
Error *EntityStatusItemError `json:"error"`
Error *EntityStatusItemError `json:"error" yaml:"error"`
}

// EntityStatusItemError has aA serialized error object.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatusItemError struct {
// The type name of the error"
Name string `json:"name"`
Name string `json:"name" yaml:"name"`

// The message of the error
Message string `json:"message"`
Message string `json:"message" yaml:"message"`

// An error code associated with the error
Code *string `json:"code"`
Code *string `json:"code" yaml:"code"`

// An error stack trace
Stack *string `json:"stack"`
Stack *string `json:"stack" yaml:"stack"`
}

// ListEntityOrder defines a condition that can be used to order entities.
Expand Down
16 changes: 8 additions & 8 deletions backstage/kind_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ type ApiEntityV1alpha1 struct {
Entity

// ApiVersion is always "backstage.io/v1alpha1".
ApiVersion string `json:"apiVersion"`
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`

// Kind is always "API".
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Spec is the specification data describing the API itself.
Spec *ApiEntityV1alpha1Spec `json:"spec"`
Spec *ApiEntityV1alpha1Spec `json:"spec" yaml:"spec"`
}

// ApiEntityV1alpha1Spec describes the specification data describing the API itself.
type ApiEntityV1alpha1Spec struct {
// Type of the API definition.
Type string `json:"type"`
Type string `json:"type" yaml:"type"`

// Lifecycle state of the API.
Lifecycle string `json:"lifecycle"`
Lifecycle string `json:"lifecycle" yaml:"lifecycle"`

// Owner is entity reference to the owner of the API.
Owner string `json:"owner"`
Owner string `json:"owner" yaml:"owner"`

// Definition of the API, based on the format defined by the type.
Definition string `json:"definition"`
Definition string `json:"definition" yaml:"definition"`

// System is entity reference to the system that the API belongs to.
System string `json:"system,omitempty"`
System string `json:"system,omitempty" yaml:"system,omitempty"`
}

// apiService handles communication with the API related methods of the Backstage Catalog API.
Expand Down
22 changes: 11 additions & 11 deletions backstage/kind_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ type ComponentEntityV1alpha1 struct {
Entity

// ApiVersion is always "backstage.io/v1alpha1".
ApiVersion string `json:"apiVersion"`
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`

// Kind is always "Component".
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Spec is the specification data describing the component itself.
Spec *ComponentEntityV1alpha1Spec `json:"spec"`
Spec *ComponentEntityV1alpha1Spec `json:"spec" yaml:"spec"`
}

// ComponentEntityV1alpha1Spec describes the specification data describing the component itself.
type ComponentEntityV1alpha1Spec struct {
// Type of component.
Type string `json:"type"`
Type string `json:"type" yaml:"type"`

// Lifecycle state of the component.
Lifecycle string `json:"lifecycle"`
Lifecycle string `json:"lifecycle" yaml:"lifecycle"`

// Owner is an entity reference to the owner of the component.
Owner string `json:"owner"`
Owner string `json:"owner" yaml:"owner"`

// SubcomponentOf is an entity reference to another component of which the component is a part.
SubcomponentOf string `json:"subcomponentOf,omitempty"`
SubcomponentOf string `json:"subcomponentOf,omitempty" yaml:"subcomponentOf,omitempty"`

// ProvidesApis is an array of entity references to the APIs that are provided by the component.
ProvidesApis []string `json:"providesApis,omitempty"`
ProvidesApis []string `json:"providesApis,omitempty" yaml:"providesApis,omitempty"`

// ConsumesApis is an array of entity references to the APIs that are consumed by the component.
ConsumesApis []string `json:"consumesApis,omitempty"`
ConsumesApis []string `json:"consumesApis,omitempty" yaml:"onsumesApis,omitempty"`

// DependsOn is an array of entity references to the components and resources that the component depends on.
DependsOn []string `json:"dependsOn,omitempty"`
DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

// System is an array of references to other entities that the component depends on to function.
System string `json:"system,omitempty"`
System string `json:"system,omitempty" yaml:"system,omitempty"`
}

// componentService handles communication with the component related methods of the Backstage Catalog API.
Expand Down
8 changes: 4 additions & 4 deletions backstage/kind_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ type DomainEntityV1alpha1 struct {
Entity

// ApiVersion is always "backstage.io/v1alpha1".
ApiVersion string `json:"apiVersion"`
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`

// Kind is always "Domain".
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Spec is the specification data describing the domain itself.
Spec *DomainEntityV1alpha1Spec `json:"spec"`
Spec *DomainEntityV1alpha1Spec `json:"spec" yaml:"spec"`
}

// DomainEntityV1alpha1Spec describes the specification data describing the domain itself.
type DomainEntityV1alpha1Spec struct {
// Owner is an entity reference to the owner of the component.
Owner string `json:"owner"`
Owner string `json:"owner" yaml:"owner"`
}

// domainService handles communication with the domain related methods of the Backstage Catalog API.
Expand Down
22 changes: 11 additions & 11 deletions backstage/kind_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,47 @@ type GroupEntityV1alpha1 struct {
Entity

// ApiVersion is always "backstage.io/v1alpha1".
ApiVersion string `json:"apiVersion"`
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`

// Kind is always "Group".
Kind string `json:"kind"`
Kind string `json:"kind" yaml:"kind"`

// Spec is the specification data describing the group itself.
Spec *GroupEntityV1alpha1Spec `json:"spec"`
Spec *GroupEntityV1alpha1Spec `json:"spec" yaml:"spec"`
}

// GroupEntityV1alpha1Spec describes the specification data describing the group itself.
type GroupEntityV1alpha1Spec struct {
// Type of group. There is currently no enforced set of values for this field, so it is left up to the adopting
// organization to choose a nomenclature that matches their org hierarchy.
Type string `json:"type"`
Type string `json:"type" yaml:"type"`

// Profile information about the group, mainly for display purposes. All fields of this structure are also optional.
// The email would be a group email of some form, that the group may wish to be used for contacting them.
// The picture is expected to be a URL pointing to an image that's representative of the group, and that a browser could
// fetch and render on a group page or similar.
Profile struct {
// DisplayName to present to users.
DisplayName string `json:"displayName,omitempty"`
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`

// Email where this entity can be reached.
Email string `json:"email,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"`

// Picture is a URL of an image that represents this entity.
Picture string `json:"picture,omitempty"`
} `json:"profile,omitempty"`
Picture string `json:"picture,omitempty" yaml:"picture,omitempty"`
} `json:"profile,omitempty" yaml:"profile,omitempty"`

// Parent is the immediate parent group in the hierarchy, if any. Not all groups must have a parent; the catalog supports
// multi-root hierarchies. Groups may however not have more than one parent. This field is an entity reference.
Parent string `json:"parent,omitempty"`
Parent string `json:"parent,omitempty" yaml:"parent,omitempty"`

// Children contains immediate child groups of this group in the hierarchy (whose parent field points to this group).
// The list must be present, but may be empty if there are no child groups. The items are not guaranteed to be ordered in
// any particular way. The entries of this array are entity references.
Children []string `json:"children"`
Children []string `json:"children" yaml:"children"`

// Members contains users that are members of this group. The entries of this array are entity references.
Members []string `json:"members,omitempty"`
Members []string `json:"members,omitempty" yaml:"members,omitempty"`
}

// groupService handles communication with the group related methods of the Backstage Catalog API.
Expand Down
Loading

0 comments on commit 7f78c0d

Please sign in to comment.