Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hub Generated] Review request for Microsoft.PolicyInsights to add version 2018-07-01-preview #5408

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
"policyEvaluationDetails": {
"evaluatedExpressions": [
{
"result": "False",
"expression": "name",
"path": "name",
"expressionValue": "myDomainName",
"targetValue": "someName",
"operator": "Equals"
"result": "True",
"expression": "tags",
"path": "tags",
"expressionValue": {},
"targetValue": "global-opco",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is declared as an object in policyStates.json, so the example doesn't match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A string is also valid for the property value since it is an object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://swagger.io/docs/specification/data-models/data-types/#object - "An object is a collection of property/value pairs".

We're using Swagger 2.0, which adheres to OpenAPI 2.0 (which takes types from JSON schema draft 4). A JSON string is not valid for a "object" type field as per the JSON schema.

Copy link
Contributor Author

@j5lim j5lim Mar 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. "any" type explained in the doc is what we need. Can I use "any" type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@praries880 can you please provide guidance on how to model a value which can be any type (string, object, array)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j5lim Ill get back to you on that shortly

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j5lim
A good way to model this will be to break up the various properties into separate types and then define targetValue and expressionValue as composite types that encapsulate those properties...

Having a single type overloaded to support more than one type will be impossible to support in languages like Go

Autorest does not support the Any type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@praries880 Does it mean we need to change the RP to return targetValue and expressionValue accordingly or can it be done by swagger changes only? Do you have some example?

How about using a directive to transform to object type similar to what OperationalInsights spec does here? Can I do that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@praries880 Pushed a new commit where a directive is used to transform the type of the properties to object for the languages that support a generic object type. This way at least those languages can handle the response without an error. Can you please review it?

"operator": "NotContainsKey"
}
],
"ifNotExistsDetails": {
Expand Down
21 changes: 21 additions & 0 deletions specification/policyinsights/resource-manager/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ csharp:
namespace: Microsoft.Azure.Management.PolicyInsights
output-folder: $(csharp-sdks-folder)/PolicyInsights/Management/Management.PolicyInsights/Generated
clear-output-folder: true
directive:
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.expressionValue
transform: $.type = "object"
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.targetValue
transform: $.type = "object"
```

## Python
Expand All @@ -162,6 +169,13 @@ python:
namespace: azure.mgmt.policyinsights
package-name: azure-mgmt-policyinsights
clear-output-folder: true
directive:
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.expressionValue
transform: $.type = "object"
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.targetValue
transform: $.type = "object"
```
``` yaml $(python) && $(python-mode) == 'update'
python:
Expand Down Expand Up @@ -190,6 +204,13 @@ namespace: com.microsoft.azure.management.policyinsights
license-header: MICROSOFT_MIT_NO_CODEGEN
payload-flattening-threshold: 1
output-folder: $(azure-libraries-for-java-folder)/azure-mgmt-policyinsights
directive:
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.expressionValue
transform: $.type = "object"
- from: swagger-document
where: $.definitions.ExpressionEvaluationDetails.properties.targetValue
transform: $.type = "object"
```

### Java multi-api
Expand Down