Documentation ¶
Index ¶
- Constants
- func ModelOrConstant(schemaName string, schemaRef *openapi3.SchemaRef, common bool) (*Model, *Constant, error)
- func ModelsAndConstants(schemas openapi3.Schemas) (Models, Constants, error)
- func TrimRefPrefix(ref string) string
- type Constant
- type Constants
- type DataType
- type Header
- type Model
- type ModelField
- type Models
- type Operation
- type OperationType
- type Param
- type Resource
- type ResourceId
- func (r ResourceId) DataApiSdkResourceId() (*sdkModels.ResourceID, error)
- func (r ResourceId) FullyQualifiedResourceName(suffixQualification *string) (*string, bool)
- func (r ResourceId) HasUserValue() bool
- func (r ResourceId) ID() string
- func (r ResourceId) IsMatchOrAncestor(r2 ResourceId) (ResourceId, bool)
- func (r ResourceId) LastLabel() *ResourceIdSegment
- func (r ResourceId) LastLabelBeforeSegment(i int) *ResourceIdSegment
- func (r ResourceId) LastSegmentOfTypeBeforeSegment(types []ResourceIdSegmentType, i int) *ResourceIdSegment
- func (r ResourceId) ResourceIdName() (*string, bool)
- func (r ResourceId) TruncateToLastSegmentOfTypeBeforeSegment(types []ResourceIdSegmentType, i int) *ResourceId
- type ResourceIdMatch
- type ResourceIdSegment
- type ResourceIdSegmentType
- type ResourceIds
- type Resources
Constants ¶
const ( ResourceSuffix = "" ResourceIdSuffix = "Id" )
const RefPrefix = "#/components/schemas/"
Variables ¶
This section is empty.
Functions ¶
func ModelOrConstant ¶
func ModelsAndConstants ¶
func TrimRefPrefix ¶
Types ¶
type DataType ¶
type DataType uint8
const ( DataTypeUnknown DataType = iota // zero value is used for comparisons, don't remove DataTypeArray DataTypeBase64 DataTypeBinary DataTypeBool DataTypeCsv DataTypeDate DataTypeDateTime DataTypeDuration DataTypeFloat32 DataTypeFloat64 DataTypeInteger16 DataTypeInteger32 DataTypeInteger64 DataTypeInteger8 DataTypeIntegerUnsigned16 DataTypeIntegerUnsigned32 DataTypeIntegerUnsigned64 DataTypeIntegerUnsigned8 DataTypeReference DataTypeString DataTypeTime DataTypeUuid )
func FieldType ¶
FieldType parses the schemaType and schemaFormat from the OpenAPI spec for a given field, and returns the appropriate DataType
func (DataType) DataApiSdkObjectDefinitionType ¶
func (ft DataType) DataApiSdkObjectDefinitionType() sdkModels.SDKObjectDefinitionType
func (DataType) DataApiSdkOperationOptionObjectDefinitionType ¶
func (ft DataType) DataApiSdkOperationOptionObjectDefinitionType() sdkModels.SDKOperationOptionObjectDefinitionType
type Header ¶
func (Header) DataApiSdkObjectDefinition ¶
func (h Header) DataApiSdkObjectDefinition() (*sdkModels.SDKOperationOptionObjectDefinition, error)
type Model ¶
type Model struct { // The type name of this model from the spec (not normalized) Name string // Fields that comprise this model Fields map[string]*ModelField // Whether this model is a common type Common bool // Whether this model has known child models Parent bool // For parent models, the field name containing the discriminated type value TypeField *string // For child models, the type value that specifies this model TypeValue *string // For child models, the name of the parent model ParentModel *string }
func (*Model) AppendDefaultFields ¶
func (m *Model) AppendDefaultFields()
func (*Model) DataApiSdkModel ¶
DataApiSdkModel converts the internal ModelField representation to a Data API SDKModel, so it can be persisted to the Data API Definitions. It's necessary to provide Models and Constants so that references (both fields and model ancestry) can be resolved.
type ModelField ¶
type ModelField struct { // The name of this field Name string // The internal type for this field Type *DataType // The internal type for items, when this field type is DataTypeArray ItemType *DataType // Optional description which can be added to the generated SDK model as a comment Description string // The default value for this field Default any // Whether the field is required Required bool // Read-only fields should be omitted during marshalling in the generated SDK ReadOnly bool // Whether the field value can be a JSON null Nullable bool // Whether this field contains the discriminated type for a child model DiscriminatedValue bool // The name of a referenced model or constant, noting that this should be the full type name from the spec prior to normalizing ReferenceName *string // This is parsed from the spec but otherwise currently unused WriteOnly bool AllowEmptyValue bool }
func (ModelField) DataApiSdkObjectDefinition ¶
func (f ModelField) DataApiSdkObjectDefinition(models Models, constants Constants) (*sdkModels.SDKObjectDefinition, error)
DataApiSdkObjectDefinition converts the internal ModelField representation to a Data API SDKObjectDefinition, so it can be persisted to the Data API Definitions. It's necessary to provide Models and Constants so that references can be resolved.
type Operation ¶
type Operation struct { // The full name of this operation, which should be unique across resources (at least in the same category) so // prevent clobbering when resources/operations are grouped into an SDK package Name string // Optional description which can be added to the generated SDK model as a comment Description string // The type of this operation, initially determined from the HTTP method Type OperationType // The HTTP method for this operation Method string // The resource ID that comprises the first part of the URI for this operation ResourceId *ResourceId // The remainder of the URI after the resource ID UriSuffix *string // When the content type is JSON or XML, and this is a List operation, the name of the field // that specifies a URL to retrieve the next page of results PaginationField *string // The content-type of the request body RequestContentType *string // The name of the model that describes the request body, can reference either a common model or describe the ad-hoc request model RequestModelName *string // The optional ad-hoc request model, if present RequestModel *Model // Any user-specified HTTP headers supported for the request RequestHeaders *[]Header // Any user-specified query string parameters support for the request RequestParams *[]Param // The internal data type for the request, used when the content type is JSON or XML, // and the request is not described by a model RequestType *DataType // The HTTP status codes associated with this expected response ResponseStatusCodes []int // The expected content type for this resource ResponseContentType *string // Specifies a referenced model or constant for the response, noting that this // should be the full type name from the spec prior to normalizing ResponseReferenceName *string // The internal data type for the response, used when the content type is JSON or XML, // and the response is not described by a model ResponseType *DataType // Model and Constant are used internally for ad-hoc response models ResponseModel *Model ResponseConstant *Constant // OpenAPI3 tags for this operation, used to reconcile operations to services Tags []string }
type OperationType ¶
type OperationType uint8
const ( OperationTypeUnknown OperationType = iota OperationTypeList OperationTypeRead OperationTypeCreate OperationTypeCreateUpdate OperationTypeUpdate OperationTypeDelete )
func NewOperationType ¶
func NewOperationType(method string) OperationType
type Param ¶
func (Param) DataApiSdkObjectDefinition ¶
func (p Param) DataApiSdkObjectDefinition() (*sdkModels.SDKOperationOptionObjectDefinition, error)
type Resource ¶
type Resource struct { // The name of this resource Name string // The category for this resource, used to group resources together in the same SDK package Category string // The API version for this resource Version string // The name of the service associated with this resource Service string // All known paths for this resource, used for category matching between different resources Paths []ResourceId // Supported operations for this resource Operations []Operation }
type ResourceId ¶
type ResourceId struct { Name string Service string Segments []ResourceIdSegment }
ResourceId represents a unique path in Microsoft Graph that represents a resource. Resource IDs comprise a non-zero number of segments, the last of which must always be of type SegmentUserValue (i.e. specified by the user). Whilst paths in Microsoft Graph can comprise different types of object identifiers, we currently only support simple SegmentUserValue segments where the entire slug is provided. For example, these two paths are functionally equivalent:
/applications/{id}/federatedIdentityCredentials/{federatedIdentityCredentialId} /applications(appId='{appId}')/federatedIdentityCredentials/{federatedIdentityCredentialName}
however we only support the first style, where the user-provided portion of each SegmentUserValue comprises the entire slug. Complex segments such as `(appId='{appId}')` are not supported at this time.
func NewResourceId ¶
func NewResourceId(path string, tags []string) (id ResourceId)
NewResourceId analyses the provided path and returns a parsed ResourceId with typed segments. Any tags provided are used to determine the type of certain matching segments, as it is otherwise not possible to distinguish between a SegmentAction or SegmentCast because they have the same format.
func (ResourceId) DataApiSdkResourceId ¶
func (r ResourceId) DataApiSdkResourceId() (*sdkModels.ResourceID, error)
DataApiSdkResourceId converts the internal ResourceId representation to a Data API SDK ResourceID, so it can be persisted to the Data API Definitions.
func (ResourceId) FullyQualifiedResourceName ¶
func (r ResourceId) FullyQualifiedResourceName(suffixQualification *string) (*string, bool)
FullyQualifiedResourceName returns a human-readable name for the ResourceId, using all segments, each segment singularized except when the following segment is an OData reference or plural function, or the first known verb is encountered. e.g. if r represents `/applications/{applicationId}/synchronization/jobs/{synchronizationJobId}/schema`, the returned name will be `ApplicationSynchronizationJob` See unit test cases for more examples.
func (ResourceId) HasUserValue ¶
func (r ResourceId) HasUserValue() bool
HasUserValue returns true if the ResourceId contains one or more SegmentUserValue segments.
func (ResourceId) ID ¶
func (r ResourceId) ID() string
func (ResourceId) IsMatchOrAncestor ¶
func (r ResourceId) IsMatchOrAncestor(r2 ResourceId) (ResourceId, bool)
IsMatchOrAncestor compares the provided ResourceId (r2) against the current ResourceId and returns true if the two resource IDs match, or if this ResourceId is an ancestor of the provided ResourceId.
func (ResourceId) LastLabel ¶
func (r ResourceId) LastLabel() *ResourceIdSegment
LastLabel returns the last label segment from the ResourceId
func (ResourceId) LastLabelBeforeSegment ¶
func (r ResourceId) LastLabelBeforeSegment(i int) *ResourceIdSegment
LastLabelBeforeSegment returns the last label segment from the ResourceId that precedes the provided segment index
func (ResourceId) LastSegmentOfTypeBeforeSegment ¶
func (r ResourceId) LastSegmentOfTypeBeforeSegment(types []ResourceIdSegmentType, i int) *ResourceIdSegment
LastSegmentOfTypeBeforeSegment returns the last segment of the specified type from the ResourceId that precedes the provided segment index
func (ResourceId) ResourceIdName ¶
func (r ResourceId) ResourceIdName() (*string, bool)
ResourceIdName returns a name for the ResourceId. This calls FullyQualifiedResourceName with a common suffix to be appended to all words preceding a user value. For example:
/groups/{groupId}/photos/{photoId} becomes GroupIdPhotoId /users/{userId}/messages/{messageId}/attachments/{attachmentId} becomes UserIdMessageIdAttachmentId
func (ResourceId) TruncateToLastSegmentOfTypeBeforeSegment ¶
func (r ResourceId) TruncateToLastSegmentOfTypeBeforeSegment(types []ResourceIdSegmentType, i int) *ResourceId
TruncateToLastSegmentOfTypeBeforeSegment returns a new ResourceId, truncated to the last segment of the specified type from the ResourceId that precedes the provided segment index
type ResourceIdMatch ¶
type ResourceIdMatch struct { Id *ResourceId Remainder *ResourceId }
type ResourceIdSegment ¶
type ResourceIdSegment struct { Type ResourceIdSegmentType Value string // contains filtered or unexported fields }
type ResourceIdSegmentType ¶
type ResourceIdSegmentType string
const ( SegmentLabel ResourceIdSegmentType = "Label" SegmentUserValue ResourceIdSegmentType = "UserValue" SegmentODataReference ResourceIdSegmentType = "ODataReference" SegmentAction ResourceIdSegmentType = "Action" SegmentCast ResourceIdSegmentType = "Cast" SegmentFunction ResourceIdSegmentType = "Function" )
type ResourceIds ¶
type ResourceIds map[string]*ResourceId
func ResourceIDs ¶
func ResourceIDs(paths openapi3.Paths, serviceName *string) (resourceIds ResourceIds, err error)
ResourceIDs parses the provided openapi3.Paths and returns a map of ResourceId containing all possible detected resource IDs
func (ResourceIds) MatchIdOrAncestor ¶
func (ri ResourceIds) MatchIdOrAncestor(resourceId ResourceId) (*ResourceIdMatch, bool)
MatchIdOrAncestor returns a ResourceIdMatch containing a matching/ancestor ResourceId and/or a remainder value, or nil if no match/ancestor was found. A match is a ResourceId that represents the same path, and an ancestor is any ResourceId that represents a shorter matching path. Where multiple ancestors are found, the most granular (i.e. the longest) ancestor is returned.
Example 1: If resourceId represents `/users/{userId}` The returned ResourceIdMatch is likely to represent `/users/{userId}` (a match) with no remainder.
Example 2: If resourceId represents `/applications/{applicationId}/owners` The returned ResourceIdMatch is likely to represent `/applications/{applicationId}` with a remainder of `/owners`