-
Notifications
You must be signed in to change notification settings - Fork 742
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
Linter Validation rules #1751
Linter Validation rules #1751
Changes from 18 commits
7fc7d03
aa24132
abad3fd
876787a
f2a0b54
3606a82
eea33c1
63770af
ab73fdf
efc0890
fb5b638
d781245
bcd2366
00426cb
6d9d811
d3769c9
4506ec7
2630213
ffd031a
22b4a27
81d7efd
c943203
312b726
d9760e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,41 @@ | |
<data name="MsdnReferencesDiscouraged" xml:space="preserve"> | ||
<value>For better generated code quality, remove all references to "msdn.microsoft.com".</value> | ||
</data> | ||
<data name="APIVersionFormatIsNotValid" xml:space="preserve"> | ||
<value>API Version must be in the format: yyyy-MM-dd, optionally followed by -preview, -alpha, -beta, -rc, -privatepreview.</value> | ||
</data> | ||
<data name="HttpVerbIsNotValid" xml:space="preserve"> | ||
<value>Permissible values for HTTP Verb are delete,get,put,patch,head,options,post. </value> | ||
</data> | ||
<data name="ResourceModelIsNotValid" xml:space="preserve"> | ||
<value>The id, name, type, location and tags properties of the Resource must be present with id, name and type as read-only</value> | ||
</data> | ||
<data name="ResourceIsMsResourceNotValid" xml:space="preserve"> | ||
<value>A 'Resource' definition must have x-ms-azure-resource extension enabled and set to true.</value> | ||
</data> | ||
<data name="XmsClientNameInValid" xml:space="preserve"> | ||
<value>Value of 'x-ms-client-name' cannot be the same as the property/model name.</value> | ||
</data> | ||
<data name="DeleteMustHaveEmptyBody" xml:space="preserve"> | ||
<value>'Delete' operation cannot have parameters in body.</value> | ||
</data> | ||
<data name="SkuModelIsNotValid" xml:space="preserve"> | ||
<value>Sku Model is not valid. A Sku model must have name property. It can also have tier, size, family, capacity as optional properties.</value> | ||
</data> | ||
<data name="PutGetPatchResponseInvalid" xml:space="preserve"> | ||
<value>{0} has different responses for PUT/GET/PATCH operations. The PUT/GET/PATCH operations must have same schema response.</value> | ||
</data> | ||
<data name="OperationsAPINotImplemented" xml:space="preserve"> | ||
<value>Operations API must be implemented for the service.</value> | ||
</data> | ||
<data name="TrackedResourceIsNotValid" xml:space="preserve"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule does not accurately represent whether the tracked resource is valid or not. So the rule name /description can be misleading. Ex- The listByResourceGroup and listBySubscription need not be present for tracked nested resources. So we should Run 2. and 3. checks only for tracked parents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synched and cleared offline |
||
<value>Tracked Resource failing validation is: {0}. Validation Failed: {1}. | ||
A Tracked Resource must have: | ||
1. A Get Operation | ||
2. A ListByResourceGroup operation with x-ms-pageable extension and | ||
3. A ListBySubscriptionId operation with x-ms-pageable extension. | ||
4. Type, Location, Tags should not be used in the properties.</value> | ||
</data> | ||
<data name="BodyMustHaveSchema" xml:space="preserve"> | ||
<value>Each body parameter must have a schema</value> | ||
</data> | ||
|
@@ -273,6 +308,9 @@ | |
<data name="PathCannotBeNullOrEmpty" xml:space="preserve"> | ||
<value>path cannot be null or an empty string or a string with white spaces while getting the parent directory</value> | ||
</data> | ||
<data name="GuidUsageNotValid" xml:space="preserve"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GuidUsageNotRecommended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
<value>Guid used at the #/Definitions/{1}/.../{0}. Usage of Guid is not recommanded</value> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add -"If GUIDs are absolutely required in your service, please get sign off from the Azure API review board." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
</data> | ||
<data name="OperationNameNotValid" xml:space="preserve"> | ||
<value>'GET' operation must use method name 'Get' or Method name start with 'List', 'PUT' operation must use method name 'Create', 'PATCH' operation must use method name 'Update' and 'DELETE' operation must use method name 'Delete'.</value> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add "Operation {0} is called {1}. It should be one of allowed values" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant to the rules in this PR. Please add it to the backlog |
||
</data> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using AutoRest.Core.Logging; | ||
using AutoRest.Core.Properties; | ||
using AutoRest.Core.Validation; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace AutoRest.Swagger.Validation | ||
{ | ||
/// <summary> | ||
/// Validates the version of the swagger. API version must follow the date pattern | ||
/// yyyy-MM-dd and allowed prefixes are -preview, -alpha, -beta, -rc, -privatepreview. | ||
/// </summary> | ||
public class APIVersionPattern : TypedRule<string> | ||
{ | ||
private static readonly Regex VersionRegex = new Regex(@"^(20\d{2})-(0[1-9]|1[0-2])-((0[1-9])|[12][0-9]|3[01])(-(preview|alpha|beta|rc|privatepreview))?$"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @sarangan12 @ravbhatnagar - Please check this out "version": "2017-01-01.4.0", The api-version format is a little different. I think the regex will not accommodate that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amarzavery @sarangan12 - This is the required pattern for API version - YYYY-MM-DD[-preview|-alpha|-beta|-rc|-privatepreview] |
||
|
||
/// <summary> | ||
/// The template message for this Rule. | ||
/// </summary> | ||
/// <remarks> | ||
/// This may contain placeholders '{0}' for parameterized messages. | ||
/// </remarks> | ||
public override string MessageTemplate => Resources.APIVersionFormatIsNotValid; | ||
|
||
/// <summary> | ||
/// The severity of this message (ie, debug/info/warning/error/fatal, etc) | ||
/// </summary> | ||
public override Category Severity => Category.Warning; | ||
|
||
/// <summary> | ||
/// An <paramref name="version"/> fails this rule if it does not have the required format. | ||
/// </summary> | ||
/// <param name="version">Version to validate</param> | ||
/// <returns>true if the version is valid. false otherwise.</returns> | ||
public override bool IsValid(string version) => !string.IsNullOrEmpty(version) && VersionRegex.IsMatch(version); | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule does not accurately represent whether the tracked resource is valid or not. So the rule name /description can be misleading. Ex- The listByResourceGroup and listBySubscription need not be present for tracked nested resources. So we should Run 2. and 3. checks only for tracked parents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synched and cleared offline