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// Column query result column descriptor.
29type Column struct {
30	// Name - Column name.
31	Name *string `json:"name,omitempty"`
32	// Type - Column data type. Possible values include: 'String', 'Integer', 'Number', 'Boolean', 'Object'
33	Type ColumnDataType `json:"type,omitempty"`
34}
35
36// Error error details.
37type Error struct {
38	// Code - Error code identifying the specific error.
39	Code *string `json:"code,omitempty"`
40	// Message - A human readable error message.
41	Message *string `json:"message,omitempty"`
42	// Details - Error details
43	Details *[]ErrorDetails `json:"details,omitempty"`
44}
45
46// ErrorDetails ...
47type ErrorDetails struct {
48	// AdditionalProperties - Unmatched properties from the message are deserialized this collection
49	AdditionalProperties map[string]interface{} `json:""`
50	// Code - Error code identifying the specific error.
51	Code *string `json:"code,omitempty"`
52	// Message - A human readable error message.
53	Message *string `json:"message,omitempty"`
54}
55
56// MarshalJSON is the custom marshaler for ErrorDetails.
57func (ed ErrorDetails) MarshalJSON() ([]byte, error) {
58	objectMap := make(map[string]interface{})
59	if ed.Code != nil {
60		objectMap["code"] = ed.Code
61	}
62	if ed.Message != nil {
63		objectMap["message"] = ed.Message
64	}
65	for k, v := range ed.AdditionalProperties {
66		objectMap[k] = v
67	}
68	return json.Marshal(objectMap)
69}
70
71// UnmarshalJSON is the custom unmarshaler for ErrorDetails struct.
72func (ed *ErrorDetails) UnmarshalJSON(body []byte) error {
73	var m map[string]*json.RawMessage
74	err := json.Unmarshal(body, &m)
75	if err != nil {
76		return err
77	}
78	for k, v := range m {
79		switch k {
80		default:
81			if v != nil {
82				var additionalProperties interface{}
83				err = json.Unmarshal(*v, &additionalProperties)
84				if err != nil {
85					return err
86				}
87				if ed.AdditionalProperties == nil {
88					ed.AdditionalProperties = make(map[string]interface{})
89				}
90				ed.AdditionalProperties[k] = additionalProperties
91			}
92		case "code":
93			if v != nil {
94				var code string
95				err = json.Unmarshal(*v, &code)
96				if err != nil {
97					return err
98				}
99				ed.Code = &code
100			}
101		case "message":
102			if v != nil {
103				var message string
104				err = json.Unmarshal(*v, &message)
105				if err != nil {
106					return err
107				}
108				ed.Message = &message
109			}
110		}
111	}
112
113	return nil
114}
115
116// ErrorResponse an error response from the API.
117type ErrorResponse struct {
118	// Error - Error information.
119	Error *Error `json:"error,omitempty"`
120}
121
122// BasicFacet a facet containing additional statistics on the response of a query. Can be either FacetResult or
123// FacetError.
124type BasicFacet interface {
125	AsFacetResult() (*FacetResult, bool)
126	AsFacetError() (*FacetError, bool)
127	AsFacet() (*Facet, bool)
128}
129
130// Facet a facet containing additional statistics on the response of a query. Can be either FacetResult or
131// FacetError.
132type Facet struct {
133	// Expression - Facet expression, same as in the corresponding facet request.
134	Expression *string `json:"expression,omitempty"`
135	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
136	ResultType ResultType `json:"resultType,omitempty"`
137}
138
139func unmarshalBasicFacet(body []byte) (BasicFacet, error) {
140	var m map[string]interface{}
141	err := json.Unmarshal(body, &m)
142	if err != nil {
143		return nil, err
144	}
145
146	switch m["resultType"] {
147	case string(ResultTypeFacetResult):
148		var fr FacetResult
149		err := json.Unmarshal(body, &fr)
150		return fr, err
151	case string(ResultTypeFacetError):
152		var fe FacetError
153		err := json.Unmarshal(body, &fe)
154		return fe, err
155	default:
156		var f Facet
157		err := json.Unmarshal(body, &f)
158		return f, err
159	}
160}
161func unmarshalBasicFacetArray(body []byte) ([]BasicFacet, error) {
162	var rawMessages []*json.RawMessage
163	err := json.Unmarshal(body, &rawMessages)
164	if err != nil {
165		return nil, err
166	}
167
168	fArray := make([]BasicFacet, len(rawMessages))
169
170	for index, rawMessage := range rawMessages {
171		f, err := unmarshalBasicFacet(*rawMessage)
172		if err != nil {
173			return nil, err
174		}
175		fArray[index] = f
176	}
177	return fArray, nil
178}
179
180// MarshalJSON is the custom marshaler for Facet.
181func (f Facet) MarshalJSON() ([]byte, error) {
182	f.ResultType = ResultTypeFacet
183	objectMap := make(map[string]interface{})
184	if f.Expression != nil {
185		objectMap["expression"] = f.Expression
186	}
187	if f.ResultType != "" {
188		objectMap["resultType"] = f.ResultType
189	}
190	return json.Marshal(objectMap)
191}
192
193// AsFacetResult is the BasicFacet implementation for Facet.
194func (f Facet) AsFacetResult() (*FacetResult, bool) {
195	return nil, false
196}
197
198// AsFacetError is the BasicFacet implementation for Facet.
199func (f Facet) AsFacetError() (*FacetError, bool) {
200	return nil, false
201}
202
203// AsFacet is the BasicFacet implementation for Facet.
204func (f Facet) AsFacet() (*Facet, bool) {
205	return &f, true
206}
207
208// AsBasicFacet is the BasicFacet implementation for Facet.
209func (f Facet) AsBasicFacet() (BasicFacet, bool) {
210	return &f, true
211}
212
213// FacetError a facet whose execution resulted in an error.
214type FacetError struct {
215	// Errors - An array containing detected facet errors with details.
216	Errors *[]ErrorDetails `json:"errors,omitempty"`
217	// Expression - Facet expression, same as in the corresponding facet request.
218	Expression *string `json:"expression,omitempty"`
219	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
220	ResultType ResultType `json:"resultType,omitempty"`
221}
222
223// MarshalJSON is the custom marshaler for FacetError.
224func (fe FacetError) MarshalJSON() ([]byte, error) {
225	fe.ResultType = ResultTypeFacetError
226	objectMap := make(map[string]interface{})
227	if fe.Errors != nil {
228		objectMap["errors"] = fe.Errors
229	}
230	if fe.Expression != nil {
231		objectMap["expression"] = fe.Expression
232	}
233	if fe.ResultType != "" {
234		objectMap["resultType"] = fe.ResultType
235	}
236	return json.Marshal(objectMap)
237}
238
239// AsFacetResult is the BasicFacet implementation for FacetError.
240func (fe FacetError) AsFacetResult() (*FacetResult, bool) {
241	return nil, false
242}
243
244// AsFacetError is the BasicFacet implementation for FacetError.
245func (fe FacetError) AsFacetError() (*FacetError, bool) {
246	return &fe, true
247}
248
249// AsFacet is the BasicFacet implementation for FacetError.
250func (fe FacetError) AsFacet() (*Facet, bool) {
251	return nil, false
252}
253
254// AsBasicFacet is the BasicFacet implementation for FacetError.
255func (fe FacetError) AsBasicFacet() (BasicFacet, bool) {
256	return &fe, true
257}
258
259// FacetRequest a request to compute additional statistics (facets) over the query results.
260type FacetRequest struct {
261	// Expression - The column or list of columns to summarize by
262	Expression *string `json:"expression,omitempty"`
263	// Options - The options for facet evaluation
264	Options *FacetRequestOptions `json:"options,omitempty"`
265}
266
267// FacetRequestOptions the options for facet evaluation
268type FacetRequestOptions struct {
269	// SortBy - The column name or query expression to sort on. Defaults to count if not present.
270	SortBy *string `json:"sortBy,omitempty"`
271	// SortOrder - The sorting order by the selected column (count by default). Possible values include: 'Asc', 'Desc'
272	SortOrder FacetSortOrder `json:"sortOrder,omitempty"`
273	// Filter - Specifies the filter condition for the 'where' clause which will be run on main query's result, just before the actual faceting.
274	Filter *string `json:"filter,omitempty"`
275	// Top - The maximum number of facet rows that should be returned.
276	Top *int32 `json:"$top,omitempty"`
277}
278
279// FacetResult successfully executed facet containing additional statistics on the response of a query.
280type FacetResult struct {
281	// TotalRecords - Number of total records in the facet results.
282	TotalRecords *int64 `json:"totalRecords,omitempty"`
283	// Count - Number of records returned in the facet response.
284	Count *int32 `json:"count,omitempty"`
285	// Data - A table containing the desired facets. Only present if the facet is valid.
286	Data interface{} `json:"data,omitempty"`
287	// Expression - Facet expression, same as in the corresponding facet request.
288	Expression *string `json:"expression,omitempty"`
289	// ResultType - Possible values include: 'ResultTypeFacet', 'ResultTypeFacetResult', 'ResultTypeFacetError'
290	ResultType ResultType `json:"resultType,omitempty"`
291}
292
293// MarshalJSON is the custom marshaler for FacetResult.
294func (fr FacetResult) MarshalJSON() ([]byte, error) {
295	fr.ResultType = ResultTypeFacetResult
296	objectMap := make(map[string]interface{})
297	if fr.TotalRecords != nil {
298		objectMap["totalRecords"] = fr.TotalRecords
299	}
300	if fr.Count != nil {
301		objectMap["count"] = fr.Count
302	}
303	if fr.Data != nil {
304		objectMap["data"] = fr.Data
305	}
306	if fr.Expression != nil {
307		objectMap["expression"] = fr.Expression
308	}
309	if fr.ResultType != "" {
310		objectMap["resultType"] = fr.ResultType
311	}
312	return json.Marshal(objectMap)
313}
314
315// AsFacetResult is the BasicFacet implementation for FacetResult.
316func (fr FacetResult) AsFacetResult() (*FacetResult, bool) {
317	return &fr, true
318}
319
320// AsFacetError is the BasicFacet implementation for FacetResult.
321func (fr FacetResult) AsFacetError() (*FacetError, bool) {
322	return nil, false
323}
324
325// AsFacet is the BasicFacet implementation for FacetResult.
326func (fr FacetResult) AsFacet() (*Facet, bool) {
327	return nil, false
328}
329
330// AsBasicFacet is the BasicFacet implementation for FacetResult.
331func (fr FacetResult) AsBasicFacet() (BasicFacet, bool) {
332	return &fr, true
333}
334
335// Operation resource Graph REST API operation definition.
336type Operation struct {
337	// Name - Operation name: {provider}/{resource}/{operation}
338	Name *string `json:"name,omitempty"`
339	// Display - Display metadata associated with the operation.
340	Display *OperationDisplay `json:"display,omitempty"`
341	// Origin - The origin of operations.
342	Origin *string `json:"origin,omitempty"`
343}
344
345// OperationDisplay display metadata associated with the operation.
346type OperationDisplay struct {
347	// Provider - Service provider: Microsoft Resource Graph.
348	Provider *string `json:"provider,omitempty"`
349	// Resource - Resource on which the operation is performed etc.
350	Resource *string `json:"resource,omitempty"`
351	// Operation - Type of operation: get, read, delete, etc.
352	Operation *string `json:"operation,omitempty"`
353	// Description - Description for the operation.
354	Description *string `json:"description,omitempty"`
355}
356
357// OperationListResult result of the request to list Resource Graph operations. It contains a list of
358// operations and a URL link to get the next set of results.
359type OperationListResult struct {
360	autorest.Response `json:"-"`
361	// Value - List of Resource Graph operations supported by the Resource Graph resource provider.
362	Value *[]Operation `json:"value,omitempty"`
363}
364
365// QueryRequest describes a query to be executed.
366type QueryRequest struct {
367	// Subscriptions - Azure subscriptions against which to execute the query.
368	Subscriptions *[]string `json:"subscriptions,omitempty"`
369	// Query - The resources query.
370	Query *string `json:"query,omitempty"`
371	// Options - The query evaluation options
372	Options *QueryRequestOptions `json:"options,omitempty"`
373	// Facets - An array of facet requests to be computed against the query result.
374	Facets *[]FacetRequest `json:"facets,omitempty"`
375}
376
377// QueryRequestOptions the options for query evaluation
378type QueryRequestOptions struct {
379	// SkipToken - Continuation token for pagination, capturing the next page size and offset, as well as the context of the query.
380	SkipToken *string `json:"$skipToken,omitempty"`
381	// Top - The maximum number of rows that the query should return. Overrides the page size when ```$skipToken``` property is present.
382	Top *int32 `json:"$top,omitempty"`
383	// Skip - The number of rows to skip from the beginning of the results. Overrides the next page offset when ```$skipToken``` property is present.
384	Skip *int32 `json:"$skip,omitempty"`
385	// ResultFormat - Defines in which format query result returned. Possible values include: 'ResultFormatTable', 'ResultFormatObjectArray'
386	ResultFormat ResultFormat `json:"resultFormat,omitempty"`
387}
388
389// QueryResponse query result.
390type QueryResponse struct {
391	autorest.Response `json:"-"`
392	// TotalRecords - Number of total records matching the query.
393	TotalRecords *int64 `json:"totalRecords,omitempty"`
394	// Count - Number of records returned in the current response. In the case of paging, this is the number of records in the current page.
395	Count *int64 `json:"count,omitempty"`
396	// ResultTruncated - Indicates whether the query results are truncated. Possible values include: 'True', 'False'
397	ResultTruncated ResultTruncated `json:"resultTruncated,omitempty"`
398	// 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.
399	SkipToken *string `json:"$skipToken,omitempty"`
400	// Data - Query output in tabular format.
401	Data interface{} `json:"data,omitempty"`
402	// Facets - Query facets.
403	Facets *[]BasicFacet `json:"facets,omitempty"`
404}
405
406// UnmarshalJSON is the custom unmarshaler for QueryResponse struct.
407func (qr *QueryResponse) UnmarshalJSON(body []byte) error {
408	var m map[string]*json.RawMessage
409	err := json.Unmarshal(body, &m)
410	if err != nil {
411		return err
412	}
413	for k, v := range m {
414		switch k {
415		case "totalRecords":
416			if v != nil {
417				var totalRecords int64
418				err = json.Unmarshal(*v, &totalRecords)
419				if err != nil {
420					return err
421				}
422				qr.TotalRecords = &totalRecords
423			}
424		case "count":
425			if v != nil {
426				var count int64
427				err = json.Unmarshal(*v, &count)
428				if err != nil {
429					return err
430				}
431				qr.Count = &count
432			}
433		case "resultTruncated":
434			if v != nil {
435				var resultTruncated ResultTruncated
436				err = json.Unmarshal(*v, &resultTruncated)
437				if err != nil {
438					return err
439				}
440				qr.ResultTruncated = resultTruncated
441			}
442		case "$skipToken":
443			if v != nil {
444				var skipToken string
445				err = json.Unmarshal(*v, &skipToken)
446				if err != nil {
447					return err
448				}
449				qr.SkipToken = &skipToken
450			}
451		case "data":
452			if v != nil {
453				var data interface{}
454				err = json.Unmarshal(*v, &data)
455				if err != nil {
456					return err
457				}
458				qr.Data = data
459			}
460		case "facets":
461			if v != nil {
462				facets, err := unmarshalBasicFacetArray(*v)
463				if err != nil {
464					return err
465				}
466				qr.Facets = &facets
467			}
468		}
469	}
470
471	return nil
472}
473
474// Table query output in tabular format.
475type Table struct {
476	// Columns - Query result column descriptors.
477	Columns *[]Column `json:"columns,omitempty"`
478	// Rows - Query result rows.
479	Rows *[][]interface{} `json:"rows,omitempty"`
480}
481