1package resourcegraph
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"encoding/json"
22	"github.com/Azure/go-autorest/autorest"
23)
24
25// The package's fully qualified name.
26const fqdn = "github.com/Azure/azure-sdk-for-go/services/resourcegraph/mgmt/2019-04-01/resourcegraph"
27
28// ColumnDataType enumerates the values for column data type.
29type ColumnDataType string
30
31const (
32	// Boolean ...
33	Boolean ColumnDataType = "boolean"
34	// Integer ...
35	Integer ColumnDataType = "integer"
36	// Number ...
37	Number ColumnDataType = "number"
38	// Object ...
39	Object ColumnDataType = "object"
40	// String ...
41	String ColumnDataType = "string"
42)
43
44// PossibleColumnDataTypeValues returns an array of possible values for the ColumnDataType const type.
45func PossibleColumnDataTypeValues() []ColumnDataType {
46	return []ColumnDataType{Boolean, Integer, Number, Object, String}
47}
48
49// FacetSortOrder enumerates the values for facet sort order.
50type FacetSortOrder string
51
52const (
53	// Asc ...
54	Asc FacetSortOrder = "asc"
55	// Desc ...
56	Desc FacetSortOrder = "desc"
57)
58
59// PossibleFacetSortOrderValues returns an array of possible values for the FacetSortOrder const type.
60func PossibleFacetSortOrderValues() []FacetSortOrder {
61	return []FacetSortOrder{Asc, Desc}
62}
63
64// ResultFormat enumerates the values for result format.
65type ResultFormat string
66
67const (
68	// ResultFormatObjectArray ...
69	ResultFormatObjectArray ResultFormat = "objectArray"
70	// ResultFormatTable ...
71	ResultFormatTable ResultFormat = "table"
72)
73
74// PossibleResultFormatValues returns an array of possible values for the ResultFormat const type.
75func PossibleResultFormatValues() []ResultFormat {
76	return []ResultFormat{ResultFormatObjectArray, ResultFormatTable}
77}
78
79// ResultTruncated enumerates the values for result truncated.
80type ResultTruncated string
81
82const (
83	// False ...
84	False ResultTruncated = "false"
85	// True ...
86	True ResultTruncated = "true"
87)
88
89// PossibleResultTruncatedValues returns an array of possible values for the ResultTruncated const type.
90func PossibleResultTruncatedValues() []ResultTruncated {
91	return []ResultTruncated{False, True}
92}
93
94// ResultType enumerates the values for result type.
95type ResultType string
96
97const (
98	// ResultTypeFacet ...
99	ResultTypeFacet ResultType = "Facet"
100	// ResultTypeFacetError ...
101	ResultTypeFacetError ResultType = "FacetError"
102	// ResultTypeFacetResult ...
103	ResultTypeFacetResult ResultType = "FacetResult"
104)
105
106// PossibleResultTypeValues returns an array of possible values for the ResultType const type.
107func PossibleResultTypeValues() []ResultType {
108	return []ResultType{ResultTypeFacet, ResultTypeFacetError, ResultTypeFacetResult}
109}
110
111// Column query result column descriptor.
112type Column struct {
113	// Name - Column name.
114	Name *string `json:"name,omitempty"`
115	// Type - Column data type. Possible values include: 'String', 'Integer', 'Number', 'Boolean', 'Object'
116	Type ColumnDataType `json:"type,omitempty"`
117}
118
119// Error error details.
120type Error struct {
121	// Code - Error code identifying the specific error.
122	Code *string `json:"code,omitempty"`
123	// Message - A human readable error message.
124	Message *string `json:"message,omitempty"`
125	// Details - Error details
126	Details *[]ErrorDetails `json:"details,omitempty"`
127}
128
129// ErrorDetails ...
130type ErrorDetails struct {
131	// AdditionalProperties - Unmatched properties from the message are deserialized this collection
132	AdditionalProperties map[string]interface{} `json:""`
133	// Code - Error code identifying the specific error.
134	Code *string `json:"code,omitempty"`
135	// Message - A human readable error message.
136	Message *string `json:"message,omitempty"`
137}
138
139// MarshalJSON is the custom marshaler for ErrorDetails.
140func (ed ErrorDetails) MarshalJSON() ([]byte, error) {
141	objectMap := make(map[string]interface{})
142	if ed.Code != nil {
143		objectMap["code"] = ed.Code
144	}
145	if ed.Message != nil {
146		objectMap["message"] = ed.Message
147	}
148	for k, v := range ed.AdditionalProperties {
149		objectMap[k] = v
150	}
151	return json.Marshal(objectMap)
152}
153
154// UnmarshalJSON is the custom unmarshaler for ErrorDetails struct.
155func (ed *ErrorDetails) UnmarshalJSON(body []byte) error {
156	var m map[string]*json.RawMessage
157	err := json.Unmarshal(body, &m)
158	if err != nil {
159		return err
160	}
161	for k, v := range m {
162		switch k {
163		default:
164			if v != nil {
165				var additionalProperties interface{}
166				err = json.Unmarshal(*v, &additionalProperties)
167				if err != nil {
168					return err
169				}
170				if ed.AdditionalProperties == nil {
171					ed.AdditionalProperties = make(map[string]interface{})
172				}
173				ed.AdditionalProperties[k] = additionalProperties
174			}
175		case "code":
176			if v != nil {
177				var code string
178				err = json.Unmarshal(*v, &code)
179				if err != nil {
180					return err
181				}
182				ed.Code = &code
183			}
184		case "message":
185			if v != nil {
186				var message string
187				err = json.Unmarshal(*v, &message)
188				if err != nil {
189					return err
190				}
191				ed.Message = &message
192			}
193		}
194	}
195
196	return nil
197}
198
199// ErrorResponse an error response from the API.
200type ErrorResponse struct {
201	// Error - Error information.
202	Error *Error `json:"error,omitempty"`
203}
204
205// BasicFacet a facet containing additional statistics on the response of a query. Can be either FacetResult or
206// FacetError.
207type BasicFacet interface {
208	AsFacetResult() (*FacetResult, bool)
209	AsFacetError() (*FacetError, bool)
210	AsFacet() (*Facet, bool)
211}
212
213// Facet a facet containing additional statistics on the response of a query. Can be either FacetResult or
214// FacetError.
215type Facet struct {
216	// Expression - Facet expression, same as in the corresponding facet request.
217	Expression *string `json:"expression,omitempty"`
218	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
219	ResultType ResultType `json:"resultType,omitempty"`
220}
221
222func unmarshalBasicFacet(body []byte) (BasicFacet, error) {
223	var m map[string]interface{}
224	err := json.Unmarshal(body, &m)
225	if err != nil {
226		return nil, err
227	}
228
229	switch m["resultType"] {
230	case string(ResultTypeFacetResult):
231		var fr FacetResult
232		err := json.Unmarshal(body, &fr)
233		return fr, err
234	case string(ResultTypeFacetError):
235		var fe FacetError
236		err := json.Unmarshal(body, &fe)
237		return fe, err
238	default:
239		var f Facet
240		err := json.Unmarshal(body, &f)
241		return f, err
242	}
243}
244func unmarshalBasicFacetArray(body []byte) ([]BasicFacet, error) {
245	var rawMessages []*json.RawMessage
246	err := json.Unmarshal(body, &rawMessages)
247	if err != nil {
248		return nil, err
249	}
250
251	fArray := make([]BasicFacet, len(rawMessages))
252
253	for index, rawMessage := range rawMessages {
254		f, err := unmarshalBasicFacet(*rawMessage)
255		if err != nil {
256			return nil, err
257		}
258		fArray[index] = f
259	}
260	return fArray, nil
261}
262
263// MarshalJSON is the custom marshaler for Facet.
264func (f Facet) MarshalJSON() ([]byte, error) {
265	f.ResultType = ResultTypeFacet
266	objectMap := make(map[string]interface{})
267	if f.Expression != nil {
268		objectMap["expression"] = f.Expression
269	}
270	if f.ResultType != "" {
271		objectMap["resultType"] = f.ResultType
272	}
273	return json.Marshal(objectMap)
274}
275
276// AsFacetResult is the BasicFacet implementation for Facet.
277func (f Facet) AsFacetResult() (*FacetResult, bool) {
278	return nil, false
279}
280
281// AsFacetError is the BasicFacet implementation for Facet.
282func (f Facet) AsFacetError() (*FacetError, bool) {
283	return nil, false
284}
285
286// AsFacet is the BasicFacet implementation for Facet.
287func (f Facet) AsFacet() (*Facet, bool) {
288	return &f, true
289}
290
291// AsBasicFacet is the BasicFacet implementation for Facet.
292func (f Facet) AsBasicFacet() (BasicFacet, bool) {
293	return &f, true
294}
295
296// FacetError a facet whose execution resulted in an error.
297type FacetError struct {
298	// Errors - An array containing detected facet errors with details.
299	Errors *[]ErrorDetails `json:"errors,omitempty"`
300	// Expression - Facet expression, same as in the corresponding facet request.
301	Expression *string `json:"expression,omitempty"`
302	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
303	ResultType ResultType `json:"resultType,omitempty"`
304}
305
306// MarshalJSON is the custom marshaler for FacetError.
307func (fe FacetError) MarshalJSON() ([]byte, error) {
308	fe.ResultType = ResultTypeFacetError
309	objectMap := make(map[string]interface{})
310	if fe.Errors != nil {
311		objectMap["errors"] = fe.Errors
312	}
313	if fe.Expression != nil {
314		objectMap["expression"] = fe.Expression
315	}
316	if fe.ResultType != "" {
317		objectMap["resultType"] = fe.ResultType
318	}
319	return json.Marshal(objectMap)
320}
321
322// AsFacetResult is the BasicFacet implementation for FacetError.
323func (fe FacetError) AsFacetResult() (*FacetResult, bool) {
324	return nil, false
325}
326
327// AsFacetError is the BasicFacet implementation for FacetError.
328func (fe FacetError) AsFacetError() (*FacetError, bool) {
329	return &fe, true
330}
331
332// AsFacet is the BasicFacet implementation for FacetError.
333func (fe FacetError) AsFacet() (*Facet, bool) {
334	return nil, false
335}
336
337// AsBasicFacet is the BasicFacet implementation for FacetError.
338func (fe FacetError) AsBasicFacet() (BasicFacet, bool) {
339	return &fe, true
340}
341
342// FacetRequest a request to compute additional statistics (facets) over the query results.
343type FacetRequest struct {
344	// Expression - The column or list of columns to summarize by
345	Expression *string `json:"expression,omitempty"`
346	// Options - The options for facet evaluation
347	Options *FacetRequestOptions `json:"options,omitempty"`
348}
349
350// FacetRequestOptions the options for facet evaluation
351type FacetRequestOptions struct {
352	// SortBy - The column name or query expression to sort on. Defaults to count if not present.
353	SortBy *string `json:"sortBy,omitempty"`
354	// SortOrder - The sorting order by the selected column (count by default). Possible values include: 'Asc', 'Desc'
355	SortOrder FacetSortOrder `json:"sortOrder,omitempty"`
356	// Filter - Specifies the filter condition for the 'where' clause which will be run on main query's result, just before the actual faceting.
357	Filter *string `json:"filter,omitempty"`
358	// Top - The maximum number of facet rows that should be returned.
359	Top *int32 `json:"$top,omitempty"`
360}
361
362// FacetResult successfully executed facet containing additional statistics on the response of a query.
363type FacetResult struct {
364	// TotalRecords - Number of total records in the facet results.
365	TotalRecords *int64 `json:"totalRecords,omitempty"`
366	// Count - Number of records returned in the facet response.
367	Count *int32 `json:"count,omitempty"`
368	// Data - A table containing the desired facets. Only present if the facet is valid.
369	Data interface{} `json:"data,omitempty"`
370	// Expression - Facet expression, same as in the corresponding facet request.
371	Expression *string `json:"expression,omitempty"`
372	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
373	ResultType ResultType `json:"resultType,omitempty"`
374}
375
376// MarshalJSON is the custom marshaler for FacetResult.
377func (fr FacetResult) MarshalJSON() ([]byte, error) {
378	fr.ResultType = ResultTypeFacetResult
379	objectMap := make(map[string]interface{})
380	if fr.TotalRecords != nil {
381		objectMap["totalRecords"] = fr.TotalRecords
382	}
383	if fr.Count != nil {
384		objectMap["count"] = fr.Count
385	}
386	if fr.Data != nil {
387		objectMap["data"] = fr.Data
388	}
389	if fr.Expression != nil {
390		objectMap["expression"] = fr.Expression
391	}
392	if fr.ResultType != "" {
393		objectMap["resultType"] = fr.ResultType
394	}
395	return json.Marshal(objectMap)
396}
397
398// AsFacetResult is the BasicFacet implementation for FacetResult.
399func (fr FacetResult) AsFacetResult() (*FacetResult, bool) {
400	return &fr, true
401}
402
403// AsFacetError is the BasicFacet implementation for FacetResult.
404func (fr FacetResult) AsFacetError() (*FacetError, bool) {
405	return nil, false
406}
407
408// AsFacet is the BasicFacet implementation for FacetResult.
409func (fr FacetResult) AsFacet() (*Facet, bool) {
410	return nil, false
411}
412
413// AsBasicFacet is the BasicFacet implementation for FacetResult.
414func (fr FacetResult) AsBasicFacet() (BasicFacet, bool) {
415	return &fr, true
416}
417
418// Operation resource Graph REST API operation definition.
419type Operation struct {
420	// Name - Operation name: {provider}/{resource}/{operation}
421	Name *string `json:"name,omitempty"`
422	// Display - Display metadata associated with the operation.
423	Display *OperationDisplay `json:"display,omitempty"`
424	// Origin - The origin of operations.
425	Origin *string `json:"origin,omitempty"`
426}
427
428// OperationDisplay display metadata associated with the operation.
429type OperationDisplay struct {
430	// Provider - Service provider: Microsoft Resource Graph.
431	Provider *string `json:"provider,omitempty"`
432	// Resource - Resource on which the operation is performed etc.
433	Resource *string `json:"resource,omitempty"`
434	// Operation - Type of operation: get, read, delete, etc.
435	Operation *string `json:"operation,omitempty"`
436	// Description - Description for the operation.
437	Description *string `json:"description,omitempty"`
438}
439
440// OperationListResult result of the request to list Resource Graph operations. It contains a list of
441// operations and a URL link to get the next set of results.
442type OperationListResult struct {
443	autorest.Response `json:"-"`
444	// Value - List of Resource Graph operations supported by the Resource Graph resource provider.
445	Value *[]Operation `json:"value,omitempty"`
446}
447
448// QueryRequest describes a query to be executed.
449type QueryRequest struct {
450	// Subscriptions - Azure subscriptions against which to execute the query.
451	Subscriptions *[]string `json:"subscriptions,omitempty"`
452	// Query - The resources query.
453	Query *string `json:"query,omitempty"`
454	// Options - The query evaluation options
455	Options *QueryRequestOptions `json:"options,omitempty"`
456	// Facets - An array of facet requests to be computed against the query result.
457	Facets *[]FacetRequest `json:"facets,omitempty"`
458}
459
460// QueryRequestOptions the options for query evaluation
461type QueryRequestOptions struct {
462	// SkipToken - Continuation token for pagination, capturing the next page size and offset, as well as the context of the query.
463	SkipToken *string `json:"$skipToken,omitempty"`
464	// Top - The maximum number of rows that the query should return. Overrides the page size when ```$skipToken``` property is present.
465	Top *int32 `json:"$top,omitempty"`
466	// Skip - The number of rows to skip from the beginning of the results. Overrides the next page offset when ```$skipToken``` property is present.
467	Skip *int32 `json:"$skip,omitempty"`
468	// ResultFormat - Defines in which format query result returned. Possible values include: 'ResultFormatTable', 'ResultFormatObjectArray'
469	ResultFormat ResultFormat `json:"resultFormat,omitempty"`
470}
471
472// QueryResponse query result.
473type QueryResponse struct {
474	autorest.Response `json:"-"`
475	// TotalRecords - Number of total records matching the query.
476	TotalRecords *int64 `json:"totalRecords,omitempty"`
477	// Count - Number of records returned in the current response. In the case of paging, this is the number of records in the current page.
478	Count *int64 `json:"count,omitempty"`
479	// ResultTruncated - Indicates whether the query results are truncated. Possible values include: 'True', 'False'
480	ResultTruncated ResultTruncated `json:"resultTruncated,omitempty"`
481	// SkipToken - When present, the value can be passed to a subsequent query call (together with the same query and subscriptions used in the current request) to retrieve the next page of data.
482	SkipToken *string `json:"$skipToken,omitempty"`
483	// Data - Query output in tabular format.
484	Data interface{} `json:"data,omitempty"`
485	// Facets - Query facets.
486	Facets *[]BasicFacet `json:"facets,omitempty"`
487}
488
489// UnmarshalJSON is the custom unmarshaler for QueryResponse struct.
490func (qr *QueryResponse) UnmarshalJSON(body []byte) error {
491	var m map[string]*json.RawMessage
492	err := json.Unmarshal(body, &m)
493	if err != nil {
494		return err
495	}
496	for k, v := range m {
497		switch k {
498		case "totalRecords":
499			if v != nil {
500				var totalRecords int64
501				err = json.Unmarshal(*v, &totalRecords)
502				if err != nil {
503					return err
504				}
505				qr.TotalRecords = &totalRecords
506			}
507		case "count":
508			if v != nil {
509				var count int64
510				err = json.Unmarshal(*v, &count)
511				if err != nil {
512					return err
513				}
514				qr.Count = &count
515			}
516		case "resultTruncated":
517			if v != nil {
518				var resultTruncated ResultTruncated
519				err = json.Unmarshal(*v, &resultTruncated)
520				if err != nil {
521					return err
522				}
523				qr.ResultTruncated = resultTruncated
524			}
525		case "$skipToken":
526			if v != nil {
527				var skipToken string
528				err = json.Unmarshal(*v, &skipToken)
529				if err != nil {
530					return err
531				}
532				qr.SkipToken = &skipToken
533			}
534		case "data":
535			if v != nil {
536				var data interface{}
537				err = json.Unmarshal(*v, &data)
538				if err != nil {
539					return err
540				}
541				qr.Data = data
542			}
543		case "facets":
544			if v != nil {
545				facets, err := unmarshalBasicFacetArray(*v)
546				if err != nil {
547					return err
548				}
549				qr.Facets = &facets
550			}
551		}
552	}
553
554	return nil
555}
556
557// Table query output in tabular format.
558type Table struct {
559	// Columns - Query result column descriptors.
560	Columns *[]Column `json:"columns,omitempty"`
561	// Rows - Query result rows.
562	Rows *[][]interface{} `json:"rows,omitempty"`
563}
564