diff --git a/Samples/2b-suppressions/shell/stderr.txt b/Samples/2b-suppressions/shell/stderr.txt index 12efe2b5db..067a6f1b31 100644 --- a/Samples/2b-suppressions/shell/stderr.txt +++ b/Samples/2b-suppressions/shell/stderr.txt @@ -1,9 +1,9 @@ +ERROR (OperationsAPIImplementation/R3023/RPCViolation): Operations API must be implemented for '/providers/Microsoft.Storage/operations'. + - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:38:2 ($.paths) WARNING (NonApplicationJsonType/R2004/SDKViolation): Please make sure that media types other than 'application/json' are supported by your service. - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:14:4 ($.consumes[1]) WARNING (NonApplicationJsonType/R2004/SDKViolation): Please make sure that media types other than 'application/json' are supported by your service. - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:18:4 ($.produces[1]) -ERROR (OperationsAPIImplementation/R3023/RPCViolation): Operations API must be implemented for '/providers/Microsoft.Storage/operations'. - - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:38:2 ($.paths) WARNING (PutRequestResponseScheme/R2017/SDKViolation): A PUT operation request body schema should be the same as its 200 response schema, to allow reusing the same entity between GET and PUT. If the schema of the PUT request body is a superset of the GET response body, make sure you have a PATCH operation to make the resource updatable. Operation: 'StorageAccounts_Create' Request Model: 'StorageAccountCreateParameters' Response Model: 'StorageAccount' - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:74:6 ($.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}"].put) ERROR (XmsExamplesRequired/R2022/SDKViolation): Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations. Operation: 'StorageAccounts_CheckNameAvailability' diff --git a/Samples/3a-literate-swagger/shell/stderr.txt b/Samples/3a-literate-swagger/shell/stderr.txt index deac65c6fe..dcba9ee866 100644 --- a/Samples/3a-literate-swagger/shell/stderr.txt +++ b/Samples/3a-literate-swagger/shell/stderr.txt @@ -1,10 +1,10 @@ +WARNING (PutRequestResponseScheme/R2017/SDKViolation): A PUT operation request body schema should be the same as its 200 response schema, to allow reusing the same entity between GET and PUT. If the schema of the PUT request body is a superset of the GET response body, make sure you have a PATCH operation to make the resource updatable. Operation: 'Services_CreateOrUpdate' Request Model: 'SearchServiceCreateOrUpdateParameters' Response Model: 'SearchServiceResource' + - /Samples/3a-literate-swagger/swagger.md:139:4 ($.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}"].put) ERROR (OperationsAPIImplementation/R3023/RPCViolation): Operations API must be implemented for '/providers/Microsoft.Search/operations'. - /Samples/3a-literate-swagger/swagger.md:205:0 ($.paths) - /Samples/3a-literate-swagger/swagger.md:176:0 ($.paths) - /Samples/3a-literate-swagger/swagger.md:137:0 ($.paths) - /Samples/3a-literate-swagger/swagger.md:50:0 ($.paths) -WARNING (PutRequestResponseScheme/R2017/SDKViolation): A PUT operation request body schema should be the same as its 200 response schema, to allow reusing the same entity between GET and PUT. If the schema of the PUT request body is a superset of the GET response body, make sure you have a PATCH operation to make the resource updatable. Operation: 'Services_CreateOrUpdate' Request Model: 'SearchServiceCreateOrUpdateParameters' Response Model: 'SearchServiceResource' - - /Samples/3a-literate-swagger/swagger.md:139:4 ($.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}"].put) ERROR (XmsExamplesRequired/R2022/SDKViolation): Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations. Operation: 'QueryKeys_List' - /Samples/3a-literate-swagger/swagger.md:52:4 ($.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}/listQueryKeys"].get) ERROR (XmsExamplesRequired/R2022/SDKViolation): Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations. Operation: 'Services_CreateOrUpdate' diff --git a/Samples/3b-custom-transformations/shell/stderr.txt b/Samples/3b-custom-transformations/shell/stderr.txt index 067a6f1b31..4738ab81a8 100644 --- a/Samples/3b-custom-transformations/shell/stderr.txt +++ b/Samples/3b-custom-transformations/shell/stderr.txt @@ -1,11 +1,11 @@ -ERROR (OperationsAPIImplementation/R3023/RPCViolation): Operations API must be implemented for '/providers/Microsoft.Storage/operations'. - - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:38:2 ($.paths) WARNING (NonApplicationJsonType/R2004/SDKViolation): Please make sure that media types other than 'application/json' are supported by your service. - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:14:4 ($.consumes[1]) WARNING (NonApplicationJsonType/R2004/SDKViolation): Please make sure that media types other than 'application/json' are supported by your service. - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:18:4 ($.produces[1]) WARNING (PutRequestResponseScheme/R2017/SDKViolation): A PUT operation request body schema should be the same as its 200 response schema, to allow reusing the same entity between GET and PUT. If the schema of the PUT request body is a superset of the GET response body, make sure you have a PATCH operation to make the resource updatable. Operation: 'StorageAccounts_Create' Request Model: 'StorageAccountCreateParameters' Response Model: 'StorageAccount' - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:74:6 ($.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}"].put) +ERROR (OperationsAPIImplementation/R3023/RPCViolation): Operations API must be implemented for '/providers/Microsoft.Storage/operations'. + - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:38:2 ($.paths) ERROR (XmsExamplesRequired/R2022/SDKViolation): Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations. Operation: 'StorageAccounts_CheckNameAvailability' - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/d374d03801e97737ddb32e01f20513e7b2bbd9c3/arm-storage/2015-06-15/swagger/storage.json:40:6 ($.paths["/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability"].post) ERROR (XmsExamplesRequired/R2022/SDKViolation): Please provide x-ms-examples describing minimum/maximum property set for response/request payloads for operations. Operation: 'StorageAccounts_Create' diff --git a/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/Validation/positive/valid-resource-model-definitions.json b/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/Validation/positive/valid-resource-model-definitions.json index 7413984b46..59f186e0cf 100644 --- a/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/Validation/positive/valid-resource-model-definitions.json +++ b/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/Validation/positive/valid-resource-model-definitions.json @@ -80,6 +80,21 @@ } } } + }, + "/foo/baz": { + "post": { + "operationId": "AzureRes_Fetch", + "description": "fetches an azure res", + "parameters": [], + "responses": { + "200": { + "description": "the resource", + "schema": { + "$ref": "#/definitions/PostRespAzureResource" + } + } + } + } } }, "definitions": { @@ -218,6 +233,19 @@ "description": "Resource type" } } + }, + "PostRespAzureResource": { + "description": "resource returned by a post operation", + "allOf": [ + { + "$ref": "#/definitions/ProxyResource" + } + ], + "properties": { + "randomSampleProp": { + "type": "string" + } + } } } } \ No newline at end of file diff --git a/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerValidationTests.cs b/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerValidationTests.cs index a45075cd71..7d02e1b4b8 100644 --- a/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerValidationTests.cs +++ b/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerValidationTests.cs @@ -774,7 +774,7 @@ public void ValidResourceModels() var servDef = SwaggerParser.Parse(filePath, fileText); Uri uriPath = null; Uri.TryCreate(filePath, UriKind.RelativeOrAbsolute, out uriPath); - var context = new RuleContext(servDef, uriPath); + var context = new RuleContext(servDef, uriPath, new ServiceDefinitionMetadata() { MergeState = ServiceDefinitionDocumentState.Composed, ServiceDefinitionDocumentType = ServiceDefinitionDocumentType.ARM }); Assert.Equal(4, context.ResourceModels.Count()); Assert.Equal(1, context.TrackedResourceModels.Count()); Assert.Equal(3, context.ProxyResourceModels.Count()); diff --git a/src/modeler/AutoRest.Swagger/Model/ValidationUtilities.cs b/src/modeler/AutoRest.Swagger/Model/ValidationUtilities.cs index c9bbd493f6..c97a6bad4b 100644 --- a/src/modeler/AutoRest.Swagger/Model/ValidationUtilities.cs +++ b/src/modeler/AutoRest.Swagger/Model/ValidationUtilities.cs @@ -57,10 +57,18 @@ public static IEnumerable GetResourceModels(ServiceDefinition serviceDef .Where(modelName => !(IsBaseResourceModelName(modelName)) && serviceDefinition.Definitions.ContainsKey(modelName) && IsAllOfOnModelNames(modelName, serviceDefinition.Definitions, xmsAzureResourceModels)); - - // return the union - return resourceModels.Union(modelsAllOfOnXmsAzureResources); + var resourceCandidates = resourceModels.Union(modelsAllOfOnXmsAzureResources); + + // Now filter all the resource models that are returned from a POST operation only + var postOpResourceModels = serviceDefinition.Paths.Values.SelectMany(pathObj => pathObj.Where(opObj => opObj.Key.EqualsIgnoreCase("post")) + .SelectMany(opObj => opObj.Value.Responses?.Select(resp => resp.Value?.Schema?.Reference?.StripDefinitionPath())??Enumerable.Empty())) + .Where(model => !string.IsNullOrWhiteSpace(model)) + .Except(putOperationsResponseModels) + .Except(getOperationsResponseModels); + + // if any model is returned only by a POST operation, disregard it + return resourceCandidates.Except(postOpResourceModels); } public static bool IsODataProperty(string propName) => propName.ToLower().StartsWith("@"); diff --git a/src/modeler/AutoRest.Swagger/Validation/Core/RecursiveObjectValidator.cs b/src/modeler/AutoRest.Swagger/Validation/Core/RecursiveObjectValidator.cs index 141ab6c9f3..bad4fc74e0 100644 --- a/src/modeler/AutoRest.Swagger/Validation/Core/RecursiveObjectValidator.cs +++ b/src/modeler/AutoRest.Swagger/Validation/Core/RecursiveObjectValidator.cs @@ -39,7 +39,7 @@ public RecursiveObjectValidator(Func resolver) /// The metadata associated with serviceDefinition to which belongs to public IEnumerable GetValidationExceptions(Uri filePath, ServiceDefinition entity, ServiceDefinitionMetadata metadata) { - return RecursiveValidate(entity, ObjectPath.Empty, new RuleContext(entity, filePath), Enumerable.Empty(), metadata); + return RecursiveValidate(entity, ObjectPath.Empty, new RuleContext(entity, filePath, metadata), Enumerable.Empty(), metadata); } /// diff --git a/src/modeler/AutoRest.Swagger/Validation/Core/RuleContext.cs b/src/modeler/AutoRest.Swagger/Validation/Core/RuleContext.cs index fb575a45c4..aa17b80873 100644 --- a/src/modeler/AutoRest.Swagger/Validation/Core/RuleContext.cs +++ b/src/modeler/AutoRest.Swagger/Validation/Core/RuleContext.cs @@ -19,7 +19,7 @@ public class RuleContext /// Initializes a top level context for rules /// /// - public RuleContext(ServiceDefinition root, Uri file) : this(null) + public RuleContext(ServiceDefinition root, Uri file, ServiceDefinitionMetadata metadata) : this(null) { this.Root = root; this.Value = root;