├── CNAME ├── .gitattributes ├── ApiDoctor.Publishing ├── CSDL │ └── ObjectGraphMerger.cs ├── ApiDoctor.Publishing.nuspec ├── ApiDoctor.Publishing.csproj ├── Properties │ └── AssemblyInfo.cs ├── PathExtensionMethods.cs └── Html │ ├── ExtendedElseTag.cs │ ├── FileTagDefinition.cs │ └── IfMatchTagDefinition.cs ├── .vscode ├── settings.json ├── launch.json └── tasks.json ├── apidoc.sh ├── ApiDoctor-300.png ├── example-console.png ├── ApiDoctor.Console ├── 35MSSharedLib1024.snk ├── ApiDoctor.ConsoleApp.nuspec ├── Properties │ └── AssemblyInfo.cs ├── Constants.cs ├── Auth │ ├── OAuthAccountException.cs │ └── BasicAccount.cs ├── WildcardExtensions.cs ├── AppConfigFile.cs └── ApiDoctor.ConsoleApp.csproj ├── .gitmodules ├── ApiDoctor.Validation.UnitTests ├── test-docs │ ├── ExampleRequest.md │ ├── IndentedCodeBlock │ │ ├── IndentedCodeBlock.md │ │ ├── NonIndentedExample.md │ │ ├── ComplexExample.md │ │ └── SimpleBuLists.md │ ├── ExampleValidateResponse.md │ ├── ExampleValidationSelectStatementFailure.md │ ├── ExampleValidationSelectStatement.md │ └── ExampleResources.md ├── Properties │ └── AssemblyInfo.cs ├── ExtensionMethods.cs ├── DocFileForTesting.cs ├── ApiDoctor.Validation.UnitTests.csproj ├── JsonRewriteTests.cs ├── MultipartMimeTests.cs ├── HttpParserTests.cs └── YamlParserTests.cs ├── ObjectGraphMergeUtility ├── Class1.cs ├── ObjectGraphMergeUtility.csproj └── Properties │ └── AssemblyInfo.cs ├── .github ├── dependabot.yml └── workflows │ └── dotnet.yml ├── ApiDoctor.Validation ├── OData │ ├── XmlBackedObject.cs │ ├── XmlParseHelper.cs │ ├── IODataNamedElement.cs │ ├── ISet.cs │ ├── IOdataAnnotatable.cs │ ├── Transformation │ │ └── ITransformable.cs │ ├── DataServices.cs │ ├── PropertyRef.cs │ ├── Key.cs │ ├── record.cs │ ├── Action.cs │ ├── Function.cs │ ├── Annotations.cs │ ├── Singleton.cs │ ├── NavigationProperty.cs │ ├── annotation.cs │ ├── propertyvalue.cs │ ├── ReturnType.cs │ ├── EntitySet.cs │ └── EntityFramework.cs ├── ObjectGraph │ └── ExtensionMethods.cs ├── ApiDoctor.Validation.nuspec ├── AuthScopeDefinition.cs ├── ErrorDefinition.cs ├── Properties │ └── AssemblyInfo.cs ├── SchemaBuildException.cs ├── SingleOrArrayConverter.cs ├── ApiDoctor.Validation.csproj ├── Json │ └── JsonExample.cs ├── Config │ ├── ConfigFile.cs │ ├── LinkValidationConfigFile.cs │ ├── MetadataValidationConfigFile.cs │ └── ApiRequirementsFile.cs ├── ItemDefinition.cs ├── Error │ ├── ValidationMessage.cs │ ├── ValidationWarning.cs │ └── ValidationResult.cs ├── SamplesDefinition.cs ├── TableSpec │ ├── TableDefinition.cs │ └── TableAndHeaderConfig.json ├── Http │ └── HttpParserRequestException.cs ├── Params │ ├── PlaceholderValueNotFoundException.cs │ └── PlaceholderValue.cs ├── MetadataTransforms.cs ├── EnumerationDefinition.cs ├── Writers │ ├── outlinepublisher.cs │ └── MarkdownPublisher.cs.cs ├── ValidationConfig.cs ├── logging.cs ├── DocumentHeader.cs ├── BackoffHelper.cs ├── MultipartMime │ └── MimeContentType.cs └── IServiceAccount.cs ├── ApiDoctor.DocumentationGeneration ├── Templates │ └── resource.md.mustache ├── ApiDoctor.DocumentationGeneration.csproj ├── Model │ ├── DocumentationNavigationProperty.cs │ ├── DocumentationEntityType.cs │ ├── DocumentationProperty.cs │ └── DocumentationComplexType.cs └── Properties │ ├── AssemblyInfo.cs │ └── Templates.Designer.cs ├── OpenSourceNotes.md ├── license.txt ├── ApiDoctor.DocumentationGeneration.UnitTests ├── ApiDoctor.DocumentationGeneration.UnitTests.csproj └── Properties │ └── AssemblyInfo.cs ├── CONTRIBUTING.md ├── TableAndHeaderConfig.json └── .gitignore /CNAME: -------------------------------------------------------------------------------- 1 | apidoctor.md -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /ApiDoctor.Publishing/CSDL/ObjectGraphMerger.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dotnet.defaultSolution": "ApiDoctor.sln" 3 | } 4 | -------------------------------------------------------------------------------- /apidoc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mono ApiDoctor.Console/bin/Debug/apidoc.exe "$@" 4 | -------------------------------------------------------------------------------- /ApiDoctor-300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneDrive/apidoctor/HEAD/ApiDoctor-300.png -------------------------------------------------------------------------------- /example-console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneDrive/apidoctor/HEAD/example-console.png -------------------------------------------------------------------------------- /ApiDoctor.Console/35MSSharedLib1024.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneDrive/apidoctor/HEAD/ApiDoctor.Console/35MSSharedLib1024.snk -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "OSS/markdowndeep"] 2 | path = OSS/markdowndeep 3 | url = https://github.com/OneDrive/markdowndeep.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/ExampleRequest.md: -------------------------------------------------------------------------------- 1 | POST https://graph.microsoft.com/beta/accessReviews('2b83cc42-09db-46f6-8c6e-16fec466a82d')/reviewers 2 | Content-Type: application/json 3 | 4 | { 5 | "id":"006111db-0810-4494-a6df-904d368bd81b" 6 | } -------------------------------------------------------------------------------- /ObjectGraphMergeUtility/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectGraphMergeUtility 8 | { 9 | public class Class1 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/IndentedCodeBlock/IndentedCodeBlock.md: -------------------------------------------------------------------------------- 1 | # Indented Code Blocks 2 | 3 | 1. List item 1 4 | 5 | ```http 6 | Code under list item 1 7 | ``` 8 | 9 | 2. List item 2, continued from list item 1. 10 | 11 | 12 | More text here 13 | 14 | ## another heading 15 | 16 | ```xml 17 | Badly indented code here. What happens now? 18 | ``` 19 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/IndentedCodeBlock/NonIndentedExample.md: -------------------------------------------------------------------------------- 1 | # Another code block sample 2 | 3 | 1. list item 1 4 | 2. list item 2 5 | 6 | ```xml 7 | 8 | ``` 9 | 10 | 1. new list item 1 11 | 12 | 13 | # Start another list 14 | 15 | 1. list item 1 16 | 2. list item 2 17 | 18 | Paragraph text that is not part of the list. 19 | 20 | 1. new list item 1 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: nuget 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | - package-ecosystem: github-actions 9 | directory: "/" 10 | schedule: 11 | interval: daily 12 | open-pull-requests-limit: 10 13 | - package-ecosystem: gitsubmodule 14 | directory: "/" 15 | schedule: 16 | interval: daily 17 | open-pull-requests-limit: 1 18 | -------------------------------------------------------------------------------- /ObjectGraphMergeUtility/ObjectGraphMergeUtility.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | Library 5 | false 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4.2.2 16 | with: 17 | submodules: recursive 18 | - name: Setup .NET 19 | uses: actions/setup-dotnet@v4.3.1 20 | with: 21 | dotnet-version: 8.0.x 22 | - name: Restore dependencies 23 | run: dotnet restore ./ApiDoctor.sln 24 | - name: Build 25 | run: dotnet build ./ApiDoctor.sln --no-restore 26 | - name: Test 27 | run: dotnet test ./ApiDoctor.sln --no-build --verbosity normal 28 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/IndentedCodeBlock/ComplexExample.md: -------------------------------------------------------------------------------- 1 | # Complex indented example 2 | 3 | 1. item 1 4 | 2. item 2 5 | ``` 6 | item 2 code 7 | ``` 8 | 9 | 3. item 3 10 | 11 | 12 | ## Another example, where code is not indented 13 | 14 | 1. item 1 15 | 16 | ``` 17 | code for item 1 18 | ``` 19 | 20 | 2. item 2 21 | 22 | 23 | ## A deeper example 24 | 25 | 1. item 1 26 | * bullet 1 27 | ``` 28 | code under bullet 1 29 | ``` 30 | 31 | * bullet 2 32 | 2. item 2 33 | 34 | ``` 35 | code under item 2 36 | ``` 37 | 38 | 3. item 3 39 | 40 | ## An example without line breaks 41 | 42 | 1. item 1 43 | ``` 44 | code under item 1 45 | ``` 46 | 2. item 2 47 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/IndentedCodeBlock/SimpleBuLists.md: -------------------------------------------------------------------------------- 1 | # Simple bulleted list samples 2 | 3 | * One 4 | * Two 5 | * Two Point One 6 | * Two Point Two 7 | * Two Point Two Point One 8 | * Three 9 | 10 | 11 | # Simple numbered list example 12 | 13 | 1. One 14 | 1. One Point One 15 | 2. One Point Two 16 | 1. One Point Two Point One 17 | 2. Two 18 | 1. Two Point One 19 | 3. Three 20 | 21 | 22 | # Mixed numbered and bulleted list 23 | 24 | * One 25 | * Two 26 | 1. Two Point One 27 | 2. Two Point Two 28 | 1. Two Point Two Point One 29 | * Three 30 | 31 | 32 | # Mixed the other way 33 | 34 | 1. One 35 | 2. Two 36 | * Two bullet one 37 | * Two bullet Two 38 | 3. Three 39 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/XmlBackedObject.cs: -------------------------------------------------------------------------------- 1 | using ApiDoctor.Validation.OData.Transformation; 2 | using ApiDoctor.Validation.Utility; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Xml; 9 | using System.Xml.Serialization; 10 | 11 | namespace ApiDoctor.Validation.OData 12 | { 13 | public abstract class XmlBackedObject 14 | { 15 | [XmlAnyElement, MergePolicy(MergePolicy.MustBeNull)] 16 | public List ExtraElements { get; set; } 17 | 18 | [XmlAnyAttribute, MergePolicy(MergePolicy.MustBeNull)] 19 | public List ExtraAttributes { get; set; } 20 | 21 | public bool HasUnknownMembers { get { return (null != ExtraElements && ExtraElements.Any()) || 22 | (null != ExtraAttributes && ExtraAttributes.Any()); } } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/ObjectGraph/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApiDoctor.Validation.Utility 8 | { 9 | internal static class ExtensionMethods 10 | { 11 | 12 | public static void AddToList(this Dictionary> dict, TKey key, params TValue[] values) 13 | { 14 | lock (dict) 15 | { 16 | List existingList = null; 17 | if (dict.TryGetValue(key, out existingList)) 18 | { 19 | existingList.AddRange(values); 20 | } 21 | else 22 | { 23 | var list = new List(); 24 | list.AddRange(values); 25 | dict.Add(key, list); 26 | } 27 | } 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Templates/resource.md.mustache: -------------------------------------------------------------------------------- 1 | # {{Name}} resource type 2 | 3 | {{Description}}{{#if BaseType}} Inherits from [{{BaseType}}]({{BaseType}}.md).{{/if}} 4 | {{#if Methods}} 5 | ## Methods 6 | 7 | | Method | Return Type| Description | 8 | |:---|:---|:---| 9 | {{#each Methods}}|{{Name}}|{{ReturnType}}|{{Description}}| 10 | {{/each}}{{/if}}{{#if Properties}} 11 | ## Properties 12 | 13 | | Name | Type | Description | 14 | |:---|:---|:---| 15 | {{#each Properties}}|{{Name}}|{{TypeMarkDown}}|{{Description}}| 16 | {{/each}}{{/if}}{{#if NavigationProperties}} 17 | ## Relationships 18 | 19 | | Name | Type | Description | 20 | |:---|:---|:---| 21 | {{#each NavigationProperties}}|{{Name}}|{{TypeMarkDown}}|{{Description}}| 22 | {{/each}}{{/if}} 23 | ## JSON representation 24 | 25 | Here is a JSON representation of the resource. 26 | 27 | ```json 28 | {{Json}} 29 | ``` -------------------------------------------------------------------------------- /ApiDoctor.Console/ApiDoctor.ConsoleApp.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ApiDoctor 5 | $version$ 6 | Microsoft 7 | dspektor@microsoft.com 8 | false 9 | Tool for validating API documentation 10 | Check http://github.com/onedrive/apidoctor for details. 11 | © Microsoft Corporation. All rights reserved. 12 | http://msdn.microsoft.com/en-US/cc300389 13 | http://github.com/onedrive/apidoctor 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /OpenSourceNotes.md: -------------------------------------------------------------------------------- 1 | # Open Source 2 | The API Documentation Tool uses the following open source components: 3 | 4 | * [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) - Json parser for .NET apps. MIT license, Copyright (c) 2007 James Newton-King. 5 | * [CommandLineParser](https://commandline.codeplex.com/) - Command line parser library. MIT license, Copyright (c) 2005 - 2012 Giacomo Stelluti Scala. 6 | * [mustache-sharp](https://github.com/jehugaleahsa/mustache-sharp) - An extension of the mustache text template engine for .NET. Public domain. 7 | * [MarkdownDeep](https://github.com/toptensoftware/MarkdownDeep) - Markdown for C# parser. Apache 2.0 license, Copyright (C) 2010-2011 Topten Software. 8 | 9 | ## Markdown Deep 10 | 11 | Markdown Deep has been modified from the original version. The modifications provide access to more of the internals 12 | of the library, such as the Block class, to enable the tool to parse the documentation block by block. 13 | 14 | The HTML conversion code has also been modified to enable richer HTML output from the Markdown source. 15 | 16 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/ApiDoctor.Console/bin/Debug/net8.0/apidoc.dll", 13 | "args": [ 14 | "generate-snippets", 15 | "--ignore-warnings", 16 | "--path", 17 | "/home/codespace/workspace/microsoft-graph-docs", 18 | "--snippet-generator-path", 19 | "/home/codespace/workspace/microsoft-graph-explorer-api/CodeSnippetsReflection.App/bin/Debug/net8.0/CodeSnippetsReflection.App", 20 | "--lang", 21 | "Java", 22 | "--git-path", 23 | "/bin/git" 24 | ], 25 | "cwd": "${workspaceFolder}/ApiDoctor.Console", 26 | "console": "internalConsole", 27 | "stopAtEntry": false 28 | }, 29 | { 30 | "name": ".NET Core Attach", 31 | "type": "coreclr", 32 | "request": "attach", 33 | "processId": "${command:pickProcess}" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | API Doctor 2 | Copyright (c) Microsoft Corporation 3 | All rights reserved. 4 | 5 | MIT License 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the ""Software""), to deal in 9 | the Software without restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 11 | Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/XmlParseHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Xml.Serialization; 7 | 8 | namespace ApiDoctor.Validation.OData 9 | { 10 | internal static class XmlParseHelper 11 | { 12 | public static void ThrowIfWrongElement(this Type t, System.Xml.Linq.XElement xml) 13 | { 14 | var name = t.XmlElementName(); 15 | if (name != xml.Name.LocalName) 16 | throw new InvalidOperationException( 17 | string.Format("Invalid XML element name. Expected {0} but was {1}", 18 | name, 19 | xml.Name.LocalName)); 20 | } 21 | 22 | public static string XmlElementName(this Type t) 23 | { 24 | var attributes = t.GetCustomAttributes(typeof(XmlRootAttribute), true); 25 | var value = attributes.FirstOrDefault() as XmlRootAttribute; 26 | if (null == value) 27 | throw new InvalidOperationException("Missing XmlTagName attribute on type"); 28 | 29 | return value.ElementName; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/ApiDoctor.Publishing.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ApiDoctor.Publishing 5 | $version$ 6 | API Doctor API documentation publishing extension 7 | Microsoft 8 | dspektor@microsoft.com 9 | false 10 | Toolkit to enable publishing from markdown to other formats. 11 | Check http://github.com/onedrive/apidoctor for details. 12 | http://msdn.microsoft.com/en-US/cc300389 13 | © Microsoft Corporation. All rights reserved. 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/ExampleValidateResponse.md: -------------------------------------------------------------------------------- 1 | 2 | ```json 3 | { 4 | "prop1": "testing", 5 | "prop2": "simple", 6 | "prop3": "waterbottle" 7 | } 8 | ``` 9 | 10 | Here's an example where the server response should be verified against 11 | properties in the sample, even though we're truncating the results: 12 | 13 | 14 | ```http 15 | GET /test_resource 16 | ``` 17 | 18 | Here's the expected response, as written in the documentation. No validation errors 19 | occur here because truncated: true. 20 | 21 | 22 | ```http 23 | HTTP/1.1 200 OK 24 | Content-Type: application/json 25 | 26 | { 27 | "prop1": "foobar", 28 | "prop2": "another something" 29 | } 30 | ``` 31 | 32 | Here's the simulated server response. Even though truncated: true is set for the expected response 33 | this should error because the set of properties in this example doesn't match the expected 34 | response. 35 | 36 | All properties in the expected response are always required. 37 | 38 | 39 | ```http 40 | HTTP/1.1 200 OK 41 | Content-Type: application/json 42 | 43 | { 44 | "prop1": "foobar", 45 | } 46 | ``` -------------------------------------------------------------------------------- /ApiDoctor.Validation/ApiDoctor.Validation.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ApiDoctor.Validation 5 | $version$ 6 | API Doctor API documentation validation class library 7 | Microsoft 8 | dspektor@microsoft.com 9 | false 10 | Toolkit to enable validation of markdown-based documentation. 11 | Check http://github.com/onedrive/apidoctor for details. 12 | http://msdn.microsoft.com/en-US/cc300389 13 | http://github.com/onedrive/apidoctor 14 | © Microsoft Corporation. All rights reserved. 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/ApiDoctor.Publishing.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Library 5 | ..\ 6 | true 7 | false 8 | $(NuspecProperties);version=$(PackageVersion) 9 | 10 | 11 | ..\ApiDoctor.Console\35MSSharedLib1024.snk 12 | 13 | 14 | false 15 | false 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 35MSSharedLib1024.snk 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/ApiDoctor.Console/ApiDoctor.ConsoleApp.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/ApiDoctor.Console/ApiDoctor.ConsoleApp.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/ApiDoctor.Console/ApiDoctor.ConsoleApp.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation/AuthScopeDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | public class AuthScopeDefinition : ItemDefinition 29 | { 30 | public string Scope { get; set; } 31 | 32 | public bool Required { get; set; } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration.UnitTests/ApiDoctor.DocumentationGeneration.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Library 5 | false 6 | 7 | 8 | ..\ApiDoctor.Console\35MSSharedLib1024.snk 9 | 10 | 11 | false 12 | false 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 35MSSharedLib1024.snk 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/IODataNamedElement.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | /// 29 | /// Interface for name OData elements 30 | /// 31 | public interface IODataNamedElement 32 | { 33 | string Name { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /ApiDoctor.Console/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("API Doctor")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("OneDrive.ApiDocumentation.ConsoleApp")] 12 | [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("260abe67-51ea-4c9a-8b30-fc43ce7596d9")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("OneDrive.ApiDocumentation.Publishing")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("OneDrive.ApiDocumentation.Publishing")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("bfe2ae47-5cef-43f5-9473-9501ecad50b4")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ApiDoctor.Validation.UnitTests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("ApiDoctor.Validation.UnitTests")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("0b5eb022-8261-4a25-b1ab-ec87f9c184b4")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /ObjectGraphMergeUtility/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ObjectGraphMergeUtility")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ObjectGraphMergeUtility")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("54edb13a-6cd1-4696-abdf-6f1bcfbea13d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/ISet.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.Collections.Generic; 29 | 30 | public interface ISet: IODataAnnotatable 31 | { 32 | List NavigationPropertyBinding { get; set; } 33 | object SourceMethods { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/ApiDoctor.DocumentationGeneration.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Library 5 | false 6 | 7 | 8 | ..\ApiDoctor.Console\35MSSharedLib1024.snk 9 | 10 | 11 | false 12 | false 13 | 14 | 15 | 16 | True 17 | True 18 | Templates.resx 19 | 20 | 21 | 22 | 23 | 35MSSharedLib1024.snk 24 | 25 | 26 | ResXFileCodeGenerator 27 | Templates.Designer.cs 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/ErrorDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | public class ErrorDefinition : ItemDefinition 29 | { 30 | public string HttpStatusCode { get; set; } 31 | 32 | public string HttpStatusMessage { get; set; } 33 | 34 | public string ErrorCode { get; set; } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration.UnitTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ApiDoctor.DocumentationGeneration.UnitTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ApiDoctor.DocumentationGeneration.UnitTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("32323786-6b69-4a7a-a5da-dbbbf1148387")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ApiDoctor.Validation")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ApiDoctor.Validation")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a493935b-c420-4227-89ea-9b11381a2318")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | 38 | [assembly: InternalsVisibleTo("ApiDoctor.Validation.UnitTests")] 39 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/SchemaBuildException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System; 29 | 30 | [Serializable] 31 | public class SchemaBuildException : Exception 32 | { 33 | public SchemaBuildException(string message, Exception innerException) 34 | : base(message, innerException) 35 | { 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/SingleOrArrayConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace ApiDoctor.Validation 7 | { 8 | /// 9 | /// Handle converting JSON properties that can either be a single value or an array of values. 10 | /// Obtained from https://stackoverflow.com/questions/18994685/how-to-handle-both-a-single-item-and-an-array-for-the-same-property-using-json-n, 9/15/2017 11 | /// 12 | /// 13 | class SingleOrArrayConverter : JsonConverter 14 | { 15 | public override bool CanConvert(Type objectType) 16 | { 17 | return (objectType == typeof(List)); 18 | } 19 | 20 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 21 | { 22 | JToken token = JToken.Load(reader); 23 | if (token.Type == JTokenType.Array) 24 | { 25 | return token.ToObject>(); 26 | } 27 | return new List { token.ToObject() }; 28 | } 29 | 30 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 31 | { 32 | List list = (List)value; 33 | if (list.Count == 1) 34 | { 35 | value = list[0]; 36 | } 37 | serializer.Serialize(writer, value); 38 | } 39 | 40 | public override bool CanWrite 41 | { 42 | get { return true; } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/IOdataAnnotatable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.Collections.Generic; 29 | 30 | /// 31 | /// Interface for elements that can be annotated; 32 | /// 33 | public interface IODataAnnotatable : IODataNamedElement 34 | { 35 | List Annotation { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Transformation/ITransformable.cs: -------------------------------------------------------------------------------- 1 | using ApiDoctor.Validation.Utility; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Xml.Serialization; 8 | 9 | namespace ApiDoctor.Validation.OData.Transformation 10 | { 11 | public interface ITransformable 12 | { 13 | [XmlIgnore] 14 | string ElementIdentifier { get; set; } 15 | 16 | void ApplyTransformation(BaseModifications value, EntityFramework edmx, string[] versions); 17 | } 18 | 19 | public abstract class XmlBackedTransformableObject : XmlBackedObject, ITransformable 20 | { 21 | [XmlIgnore] 22 | public abstract string ElementIdentifier { get; set; } 23 | 24 | public virtual void ApplyTransformation(BaseModifications value, EntityFramework edmx, string[] versions) 25 | { 26 | TransformationHelper.ApplyTransformation(this, value, edmx, versions); 27 | } 28 | 29 | /// 30 | /// Specify a parameter index so that parameter order can be maintained even if we sort the collections. 31 | /// This would come from a transform rule and not from CSDL 32 | /// 33 | [XmlIgnore, SortBy(0), MergePolicy(MergePolicy.Ignore)] 34 | public int? CollectionIndex { get; set; } 35 | } 36 | 37 | 38 | [AttributeUsage(AttributeTargets.Property)] 39 | public class ContainsTypeAttribute : Attribute 40 | { 41 | 42 | } 43 | 44 | 45 | public enum RenameableType 46 | { 47 | EntityType, 48 | ComplexType 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ApiDoctor.Console/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace ApiDoctor.ConsoleApp 5 | { 6 | public static class Constants 7 | { 8 | public static class PermissionsConstants 9 | { 10 | public const string DefaultBoilerPlateText = "Choose the permission or permissions marked as least privileged for this API." + 11 | " Use a higher privileged permission or permissions [only if your app requires it](/graph/permissions-overview#best-practices-for-using-microsoft-graph-permissions)." + 12 | " For details about delegated and application permissions, see [Permission types](/graph/permissions-overview#permission-types). To learn more about these permissions, see the [permissions reference](/graph/permissions-reference)."; 13 | public const string MultipleTableBoilerPlateText = "The following tables show the least privileged permission or permissions required to call this API on each supported resource type." + 14 | " Follow [best practices](/graph/permissions-overview#best-practices-for-using-microsoft-graph-permissions) to request least privileged permissions." + 15 | " For details about delegated and application permissions, see [Permission types](/graph/permissions-overview#permission-types). To learn more about these permissions, see the [permissions reference](/graph/permissions-reference)."; 16 | } 17 | public static readonly Regex FunctionParameterRegex = new(@"(?<=\=)[^)]+(?=\))", RegexOptions.Compiled, TimeSpan.FromSeconds(5)); 18 | public static readonly Regex QueryOptionSegementRegex = new(@"(\$.*)", RegexOptions.Compiled, TimeSpan.FromSeconds(5)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/ApiDoctor.Validation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Library 5 | ..\ 6 | true 7 | false 8 | $(NuspecProperties);version=$(PackageVersion) 9 | 10 | 11 | ..\ApiDoctor.Console\35MSSharedLib1024.snk 12 | 13 | 14 | false 15 | false 16 | 17 | 18 | 19 | 35MSSharedLib1024.snk 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Json/JsonExample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Json 27 | { 28 | public class JsonExample 29 | { 30 | 31 | public JsonExample(string json, CodeBlockAnnotation annotation = null) 32 | { 33 | this.JsonData = json; 34 | this.Annotation = annotation ?? new CodeBlockAnnotation(); 35 | } 36 | 37 | public string JsonData { get; set; } 38 | public CodeBlockAnnotation Annotation { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Config/ConfigFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Config 27 | { 28 | public abstract class ConfigFile 29 | { 30 | public abstract bool IsValid { get; } 31 | public string SourcePath { get; set; } 32 | 33 | /// 34 | /// Provide opportunity to post-process a valid configuration after the file is loaded. 35 | /// 36 | public virtual void LoadComplete() 37 | { 38 | 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/ItemDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System.Collections.Generic; 29 | 30 | public class ItemDefinition 31 | { 32 | public string Title { get; set; } 33 | public string Description { get; set; } 34 | 35 | public List Parameters { get; set; } 36 | 37 | public ItemDefinition() 38 | { 39 | this.Parameters = new List(); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Config/LinkValidationConfigFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Config 27 | { 28 | using Newtonsoft.Json; 29 | 30 | public class LinkValidationConfigFile : ConfigFile 31 | { 32 | [JsonProperty("pathsToIgnore")] 33 | public string[] IgnoredPaths { get; set; } 34 | 35 | public override bool IsValid 36 | { 37 | get 38 | { 39 | return this.IgnoredPaths != null; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/DataServices.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using System.Collections.Generic; 30 | using System.Xml.Serialization; 31 | 32 | [XmlRoot("DataServices", Namespace = ODataParser.EdmNamespace)] 33 | [Mergable] 34 | public class DataServices : XmlBackedObject 35 | { 36 | [XmlElement("Schema", Namespace = ODataParser.EdmNamespace)] 37 | [Sortable] 38 | public List Schemas { get; set; } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Error/ValidationMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | namespace ApiDoctor.Validation.Error 28 | { 29 | public class ValidationMessage : ValidationError 30 | { 31 | public ValidationMessage(string source, string format, params object[] formatParams) 32 | : base(ValidationErrorCode.Unknown, source, format, formatParams) 33 | { 34 | 35 | } 36 | 37 | public override bool IsWarning { get { return false; } } 38 | public override bool IsError { get { return false; } } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Model/DocumentationNavigationProperty.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.DocumentationGeneration.Model 27 | { 28 | using System.Collections.Generic; 29 | 30 | using ApiDoctor.Validation.OData; 31 | 32 | public class DocumentationNavigationProperty : DocumentationProperty 33 | { 34 | public DocumentationNavigationProperty(EntityFramework entityFramework, EntityType entityType, NavigationProperty property) 35 | : base(entityFramework, entityType, property) 36 | { 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.UnitTests 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | using ApiDoctor.Validation.Error; 31 | 32 | static class ExtensionMethods 33 | { 34 | internal static IEnumerable WarningsOrErrorsOnly(this IEnumerable errors) 35 | { 36 | return from e in errors 37 | where e.IsWarning || e.IsError 38 | select e; 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/SamplesDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System; 29 | 30 | public partial class DocFile 31 | { 32 | public class SamplesDefinition : ItemDefinition 33 | { 34 | public SamplesDefinition(CodeBlockAnnotation annotation, string content) 35 | { 36 | this.Samples = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); 37 | } 38 | 39 | public string[] Samples { get; private set; } 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/PropertyRef.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System; 29 | using System.Xml.Serialization; 30 | using Transformation; 31 | using Utility; 32 | 33 | [XmlRoot("PropertyRef", Namespace = ODataParser.EdmNamespace)] 34 | [Mergable] 35 | public class PropertyRef : XmlBackedTransformableObject 36 | { 37 | [XmlAttribute("Name")] 38 | public string Name { get; set; } 39 | 40 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 41 | public override string ElementIdentifier { get { return this.Name; } set { this.Name = value; } } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Key.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System; 29 | using System.Xml.Serialization; 30 | using Transformation; 31 | using Utility; 32 | 33 | [XmlRoot("Key", Namespace = ODataParser.EdmNamespace)] 34 | [Mergable] 35 | public class Key : XmlBackedTransformableObject 36 | { 37 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 38 | public override string ElementIdentifier { get { return null; } set { } } 39 | 40 | [XmlElement("PropertyRef", Namespace = ODataParser.EdmNamespace)] 41 | public PropertyRef PropertyRef { get; set; } 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/record.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) Microsoft Corporation 3 | * All rights reserved. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the ""Software""), to deal in 9 | * the Software without restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 11 | * Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | * PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | namespace ApiDoctor.Validation.OData 26 | { 27 | using Utility; 28 | using System.Collections.Generic; 29 | using System.ComponentModel; 30 | using System.Xml.Serialization; 31 | 32 | [XmlRoot("Record", Namespace = ODataParser.EdmNamespace)] 33 | [Mergable(CollectionIdentifier = "PropertyValue")] 34 | public class Record : XmlBackedObject 35 | { 36 | [XmlElement("PropertyValue", Namespace = ODataParser.EdmNamespace), DefaultValue(null), SortBy] 37 | public List PropertyValues { get; set; } 38 | 39 | [XmlAttribute("Type"), MergePolicy(MergePolicy.EqualOrNull)] 40 | public string Type { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Action.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.Xml; 29 | using System.Xml.Serialization; 30 | using Utility; 31 | 32 | /// 33 | /// Action in OData is allowed to modify data on the 34 | /// server (can have side-effects). Action does not have to 35 | /// return data. 36 | /// 37 | [XmlRoot("Action", Namespace = ODataParser.EdmNamespace)] 38 | public class Action : ActionOrFunctionBase 39 | { 40 | public Action() : base() 41 | { 42 | } 43 | 44 | [XmlAttribute("EntitySetPath"), MergePolicy(MergePolicy.EqualOrNull)] 45 | public string EntitySetPath { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // 3 | // Copyright © Microsoft Corporation. All rights reserved. 4 | // 5 | // --------------------------------------------------------------------------- 6 | 7 | using System.Reflection; 8 | using System.Runtime.CompilerServices; 9 | using System.Runtime.InteropServices; 10 | 11 | // General Information about an assembly is controlled through the following 12 | // set of attributes. Change these attribute values to modify the information 13 | // associated with an assembly. 14 | [assembly: AssemblyTitle("ApiDoctor.DocumentationGeneration")] 15 | [assembly: AssemblyDescription("")] 16 | [assembly: AssemblyConfiguration("")] 17 | [assembly: AssemblyCompany("")] 18 | [assembly: AssemblyProduct("ApiDoctor.DocumentationGeneration")] 19 | [assembly: AssemblyCopyright("Copyright © 2017")] 20 | [assembly: AssemblyTrademark("")] 21 | [assembly: AssemblyCulture("")] 22 | 23 | // Setting ComVisible to false makes the types in this assembly not visible 24 | // to COM components. If you need to access a type in this assembly from 25 | // COM, set the ComVisible attribute to true on that type. 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | [assembly: Guid("cd27998c-4021-4299-970b-91be877fd01b")] 30 | 31 | // Version information for an assembly consists of the following four values: 32 | // Major Version 33 | // Minor Version 34 | // Build Number 35 | // Revision 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | 42 | [assembly: InternalsVisibleTo("ApiDoctor.DocumentationGeneration.UnitTests")] 43 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/TableSpec/TableDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.TableSpec 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | 31 | public class TableDefinition 32 | { 33 | public TableBlockType Type { get; set; } 34 | 35 | public ItemDefinition[] Rows { get; set; } 36 | 37 | public string Title { get; set; } 38 | 39 | public List UsedIn { get; } = new List(); 40 | 41 | public TableDefinition(TableBlockType type, IEnumerable rows, string headerText) 42 | { 43 | this.Type = type; 44 | this.Rows = rows.ToArray(); 45 | this.Title = headerText; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ApiDoctor.Console/Auth/OAuthAccountException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Markdown File Handler - Sample Code 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.ConsoleApp.Auth 27 | { 28 | using System; 29 | using System.Runtime.Serialization; 30 | 31 | [Serializable] 32 | internal class OAuthAccountException : Exception 33 | { 34 | public OAuthAccountException() 35 | { 36 | } 37 | 38 | public OAuthAccountException(string message) : base(message) 39 | { 40 | } 41 | 42 | public OAuthAccountException(string message, Exception innerException) : base(message, innerException) 43 | { 44 | } 45 | 46 | protected OAuthAccountException(SerializationInfo info, StreamingContext context) : base(info, context) 47 | { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/DocFileForTesting.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.UnitTests 27 | { 28 | using Error; 29 | public class DocFileForTesting : DocFile 30 | { 31 | private readonly string contentsOfFile; 32 | public DocFileForTesting(string contentsOfFile, string fullPath, string displayName, DocSet parent) 33 | : base() 34 | { 35 | this.contentsOfFile = contentsOfFile; 36 | this.FullPath = fullPath; 37 | this.DisplayName = displayName; 38 | this.Parent = parent; 39 | } 40 | 41 | protected override string GetContentsOfFile(string tags, IssueLogger issues = default) 42 | { 43 | return this.contentsOfFile; 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Http/HttpParserRequestException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Markdown File Handler - Sample Code 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Http 27 | { 28 | using System; 29 | using System.Runtime.Serialization; 30 | 31 | [Serializable] 32 | internal class HttpParserRequestException : Exception 33 | { 34 | public HttpParserRequestException() 35 | { 36 | } 37 | 38 | public HttpParserRequestException(string message) : base(message) 39 | { 40 | } 41 | 42 | public HttpParserRequestException(string message, Exception innerException) : base(message, innerException) 43 | { 44 | } 45 | 46 | protected HttpParserRequestException(SerializationInfo info, StreamingContext context) : base(info, context) 47 | { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/ExampleValidationSelectStatementFailure.md: -------------------------------------------------------------------------------- 1 | 2 | ```json 3 | { 4 | "id": "string", 5 | "lastModifiedDateTime": "datetime", 6 | "name": "string", 7 | "size": 218753122201, 8 | "webUrl": "url", 9 | "children": [ 10 | { "@odata.type": "oneDrive.item" } 11 | ] 12 | } 13 | ``` 14 | 15 | 16 | ```http 17 | GET /drive/root?expand=children(select=id,name) 18 | ``` 19 | 20 | The request returns the collection items, with the children collection expanded. 21 | 22 | 23 | ```http 24 | HTTP/1.1 200 OK 25 | Content-Type: application/json 26 | 27 | { 28 | "id": "root", 29 | "lastModifiedDateTime": "2013-06-20T02:54:44.547Z", 30 | "name": "root", 31 | "size": 218753122201, 32 | "webUrl": "https://onedrive.live.com/?cid=0f040...", 33 | "children": [ 34 | { 35 | "id": "F04AA961744A809!48443", 36 | "name": "Applications", 37 | }, 38 | { 39 | "id": "F04AA961744A809!92647", 40 | "name": "Attachments", 41 | }, 42 | { 43 | "id": "F04AA961744A809!93269", 44 | "name": "Balsmiq Sketches", 45 | }, 46 | { 47 | "id": "F04AA961744A809!65191", 48 | "name": "Camera imports", 49 | } 50 | ] 51 | } 52 | ``` 53 | 54 | 55 | 56 | ```http 57 | HTTP/1.1 200 OK 58 | Content-Type: application/json 59 | 60 | { 61 | "id": "root", 62 | "lastModifiedDateTime": "2013-06-20T02:54:44.547Z", 63 | "name": "root", 64 | "size": 218753122201, 65 | "webUrl": "https://onedrive.live.com/?cid=0f040...", 66 | "children": [ 67 | { 68 | "id": "F04AA961744A809!48443" 69 | }, 70 | { 71 | "id": "F04AA961744A809!92647" 72 | }, 73 | { 74 | "id": "F04AA961744A809!93269" 75 | }, 76 | { 77 | "id": "F04AA961744A809!65191" 78 | } 79 | ] 80 | } 81 | ``` 82 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Function.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using System.Xml.Serialization; 30 | 31 | /// 32 | /// Function in OData is not allowed to modify data 33 | /// or have side effects (must be idempotent). A 34 | /// function must return data back to the caller (ReturnType). 35 | /// 36 | [XmlRoot("Function", Namespace = ODataParser.EdmNamespace)] 37 | public class Function : ActionOrFunctionBase 38 | { 39 | public Function() : base() 40 | { 41 | } 42 | 43 | [XmlAttribute("IsComposable"), MergePolicy(MergePolicy.PreferLesserValue)] 44 | public bool IsComposable { get; set; } 45 | 46 | [XmlIgnore] 47 | public bool IsComposableSpecified => this.IsComposable; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Params/PlaceholderValueNotFoundException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Markdown File Handler - Sample Code 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Params 27 | { 28 | using System; 29 | using System.Runtime.Serialization; 30 | 31 | [Serializable] 32 | internal class PlaceholderValueNotFoundException : Exception 33 | { 34 | public PlaceholderValueNotFoundException() 35 | { 36 | } 37 | 38 | public PlaceholderValueNotFoundException(string message) : base(message) 39 | { 40 | } 41 | 42 | public PlaceholderValueNotFoundException(string message, Exception innerException) : base(message, innerException) 43 | { 44 | } 45 | 46 | protected PlaceholderValueNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) 47 | { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ApiDoctor.Console/WildcardExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | namespace ApiDoctor.ConsoleApp 28 | { 29 | using System.Text.RegularExpressions; 30 | 31 | internal static class WildcardExtensions 32 | { 33 | /// 34 | /// Convert a wildcard string pattern to a RegEx. 35 | /// 36 | /// 37 | /// 38 | private static string WildcardToRegex(string pattern) 39 | { 40 | return "^" + Regex.Escape(pattern) 41 | .Replace(@"\*", ".*") 42 | .Replace(@"\?", ".") 43 | + "$"; 44 | } 45 | 46 | public static bool IsWildcardMatch(this string source, string pattern) 47 | { 48 | return Regex.IsMatch(source, WildcardToRegex(pattern)); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/MetadataTransforms.cs: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * API Doctor 4 | * Copyright (c) Microsoft Corporation 5 | * All rights reserved. 6 | * 7 | * MIT License 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | * this software and associated documentation files (the ""Software""), to deal in 11 | * the Software without restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 13 | * Software, and to permit persons to whom the Software is furnished to do so, 14 | * subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in all 17 | * copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 20 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | namespace ApiDoctor.Validation 28 | { 29 | using Newtonsoft.Json; 30 | using System.Collections.Generic; 31 | 32 | public class AccountTransforms 33 | { 34 | [JsonProperty("request")] 35 | public MetadataTransforms Request { get; set; } 36 | 37 | [JsonProperty("response")] 38 | public MetadataTransforms Response { get; set; } 39 | 40 | } 41 | 42 | public class MetadataTransforms 43 | { 44 | [JsonProperty("properties")] 45 | public Dictionary Properties { get; set; } 46 | 47 | [JsonProperty("actions")] 48 | public ActionTransforms Actions { get; set; } 49 | 50 | } 51 | 52 | public class ActionTransforms 53 | { 54 | [JsonProperty("prefix")] 55 | public string Prefix { get; set; } 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/PathExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Publishing 27 | { 28 | internal static class PathExtensionMethods 29 | { 30 | 31 | public static string LastPathComponent(this string path) 32 | { 33 | if (null == path) return null; 34 | var parts = path.Split(new char[] { '\\', '/' }); 35 | if (parts.Length > 0) 36 | { 37 | return parts[parts.Length - 1]; 38 | } 39 | return null; 40 | } 41 | 42 | public static string FirstPathComponent(this string path) 43 | { 44 | if (null == path) return null; 45 | 46 | var parts = path.Split(new char[] { '\\', '/' }); 47 | if (parts.Length > 0) 48 | { 49 | return parts[0]; 50 | } 51 | return null; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/ApiDoctor.Validation.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | Library 5 | ..\ 6 | true 7 | false 8 | 9 | 10 | ..\ApiDoctor.Console\35MSSharedLib1024.snk 11 | 12 | 13 | false 14 | false 15 | 16 | 17 | 18 | True 19 | True 20 | Resources.resx 21 | 22 | 23 | 24 | 25 | 35MSSharedLib1024.snk 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ResXFileCodeGenerator 38 | Resources.Designer.cs 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Model/DocumentationEntityType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.DocumentationGeneration.Model 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | 31 | using ApiDoctor.DocumentationGeneration.Extensions; 32 | using ApiDoctor.Validation.OData; 33 | 34 | public class DocumentationEntityType : DocumentationComplexType 35 | { 36 | public DocumentationEntityType(EntityFramework entityFramework, EntityType entity) 37 | : base(entityFramework, entity) 38 | { 39 | this.IsEntity = true; 40 | this.NavigationProperties = entity.NavigationProperties.Select(p => p.ToDocumentationNavigationProperty(entityFramework, entity)).ToList().AsReadOnly(); 41 | } 42 | 43 | public bool IsEntity { get; private set; } 44 | 45 | public IReadOnlyCollection NavigationProperties { get; private set; } 46 | } 47 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/ExampleValidationSelectStatement.md: -------------------------------------------------------------------------------- 1 | 2 | ```json 3 | { 4 | "id": "string", 5 | "lastModifiedDateTime": "datetime", 6 | "name": "string", 7 | "size": 218753122201, 8 | "webUrl": "url", 9 | "children": [ 10 | { "@odata.type": "oneDrive.item" } 11 | ] 12 | } 13 | ``` 14 | 15 | 16 | ```http 17 | GET /drive/root?expand=children(select=id,name) 18 | ``` 19 | 20 | The request returns the collection items, with the children collection expanded. 21 | 22 | 23 | ```http 24 | HTTP/1.1 200 OK 25 | Content-Type: application/json 26 | 27 | { 28 | "id": "root", 29 | "lastModifiedDateTime": "2013-06-20T02:54:44.547Z", 30 | "name": "root", 31 | "size": 218753122201, 32 | "webUrl": "https://onedrive.live.com/?cid=0f040...", 33 | "children": [ 34 | { 35 | "id": "F04AA961744A809!48443", 36 | "name": "Applications", 37 | }, 38 | { 39 | "id": "F04AA961744A809!92647", 40 | "name": "Attachments", 41 | }, 42 | { 43 | "id": "F04AA961744A809!93269", 44 | "name": "Balsmiq Sketches", 45 | }, 46 | { 47 | "id": "F04AA961744A809!65191", 48 | "name": "Camera imports", 49 | } 50 | ] 51 | } 52 | ``` 53 | 54 | 55 | 56 | ```http 57 | HTTP/1.1 200 OK 58 | Content-Type: application/json 59 | 60 | { 61 | "id": "root", 62 | "lastModifiedDateTime": "2013-06-20T02:54:44.547Z", 63 | "name": "root", 64 | "size": 218753122201, 65 | "webUrl": "https://onedrive.live.com/?cid=0f040...", 66 | "children": [ 67 | { 68 | "id": "F04AA961744A809!48443", 69 | "name": "Applications", 70 | }, 71 | { 72 | "id": "F04AA961744A809!92647", 73 | "name": "Attachments", 74 | }, 75 | { 76 | "id": "F04AA961744A809!93269", 77 | "name": "Balsmiq Sketches", 78 | }, 79 | { 80 | "id": "F04AA961744A809!65191", 81 | "name": "Camera imports", 82 | } 83 | ] 84 | } 85 | ``` 86 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/EnumerationDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | public class EnumerationDefinition : ItemDefinition 29 | { 30 | /// 31 | /// Enumerated member name 32 | /// 33 | public string MemberName { get; set; } 34 | 35 | /// 36 | /// Enumerated type name 37 | /// 38 | public string TypeName { get; set; } 39 | 40 | /// 41 | /// Attribute for IsFlags 42 | /// 43 | public bool IsFlags { get; set; } 44 | 45 | /// 46 | /// Attribute for IsFlags 47 | /// 48 | public int? NumericValue { get; set; } 49 | 50 | /// 51 | /// The namespace of the enum type e.g. microsoft.graph, microsoft.graph.callRecords 52 | /// 53 | public string Namespace { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/JsonRewriteTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Threading.Tasks; 31 | using Newtonsoft.Json; 32 | using NUnit.Framework; 33 | using ApiDoctor.Validation.Json; 34 | using System.Collections.Specialized; 35 | 36 | namespace ApiDoctor.Validation.UnitTests 37 | { 38 | [TestFixture] 39 | public class JsonRewriteTests 40 | { 41 | [Test] 42 | public void BasicRewrite() 43 | { 44 | var json = "{ \"name\": \"foo\", \"@microsoft.graph.downloadUrl\": \"https://foo/bar/baz\", \"@microsoft.graph.conflictBehavior\": \"fail\" }"; 45 | var map = new Dictionary(); 46 | map.Add("@microsoft.graph.downloadUrl", "@oneDrive.downloadUrl"); 47 | map.Add("@microsoft.graph.", "@oneDrive."); 48 | var output = JsonRewriter.RewriteJsonProperties(json, map, new Error.IssueLogger()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Annotations.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using Transformation; 30 | using System.Collections.Generic; 31 | using System.Xml.Serialization; 32 | 33 | 34 | [XmlRoot("Annotations", Namespace = ODataParser.EdmNamespace)] 35 | [Mergable(CollectionIdentifier ="ElementIdentifier")] 36 | public class Annotations : XmlBackedTransformableObject 37 | { 38 | public Annotations() 39 | { 40 | this.AnnotationList = new List(); 41 | } 42 | 43 | [XmlElement("Annotation")] 44 | public List AnnotationList { get; set; } 45 | 46 | [XmlAttribute("Target"), SortBy, MergePolicy(MergePolicy.EqualOrNull)] 47 | public string Target { get; set; } 48 | 49 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 50 | public override string ElementIdentifier { get { return this.Target; } set { this.Target = value; } } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Writers/outlinepublisher.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Writers 27 | { 28 | using System.IO; 29 | using System.Threading.Tasks; 30 | using ApiDoctor.Validation.Error; 31 | 32 | public class OutlinePublisher : DocumentPublisher 33 | { 34 | 35 | public OutlinePublisher(DocSet docset) 36 | : base(docset) 37 | { 38 | 39 | } 40 | 41 | public override async Task PublishToFolderAsync(string outputFolder, IssueLogger issues) 42 | { 43 | StreamWriter writer = new StreamWriter(Path.Combine(outputFolder, "outline.txt")) { AutoFlush = true }; 44 | foreach (var doc in this.Documents.Files) 45 | { 46 | await writer.WriteLineAsync("### File: " + doc.DisplayName + " ###"); 47 | foreach (var topic in doc.ContentOutline) 48 | { 49 | await writer.WriteLineAsync(topic); 50 | } 51 | await writer.WriteLineAsync(); 52 | } 53 | writer.Flush(); 54 | writer.Dispose(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ApiDoctor.Console/AppConfigFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.ConsoleApp 27 | { 28 | using ApiDoctor.ConsoleApp.Auth; 29 | using ApiDoctor.Validation.Config; 30 | using Newtonsoft.Json; 31 | using ApiDoctor.Validation; 32 | 33 | public class AppConfigFile : ConfigFile 34 | { 35 | [JsonProperty("accounts")] 36 | public OAuthAccount[] Accounts { get; set; } 37 | 38 | [JsonProperty("checkServiceEnabledBranches")] 39 | public string[] CheckServiceEnabledBranches { get; set; } 40 | 41 | public override bool IsValid 42 | { 43 | get { return null != this.Accounts || null != this.CheckServiceEnabledBranches; } 44 | } 45 | 46 | public override void LoadComplete() 47 | { 48 | AppConfigFile.ReplaceEnvironmentVariablesInAccounts(this.Accounts); 49 | } 50 | 51 | private static void ReplaceEnvironmentVariablesInAccounts(OAuthAccount[] accounts) 52 | { 53 | foreach(var account in accounts) 54 | { 55 | account.ReplaceEnvironmentVariables(); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribute to Markdown Scanner 2 | 3 | Thank you for your interest in Markdown Scanner! 4 | 5 | * [Ways to contribute](#ways-to-contribute) 6 | * [Before we can accept your pull request](#before-we-can-accept-your-pull-request) 7 | * [Contribute feature or bug fix](#contribute-feature-or-bug-fix) 8 | 9 | ## Ways to contribute 10 | 11 | You can contribute to Markdown Scanner in these ways: 12 | 13 | * Create issues based on bugs you've found when using API Doctor. 14 | * Create issues based on desired but missing functionality for API Doctor. 15 | * Contribute additional unit test cases that increase code coverage and validation of key scenarios for API Doctor. Tests should always pass on the latest master codebase. 16 | * Contribute bug fixes and unit tests that validate the bug fix. 17 | * Contribute new functionality and appropriate test scenarios. 18 | 19 | ## Before we can accept your pull request 20 | 21 | If our automated process determines that the pull request is significant, you will be required to 22 | sign the Contribution License Agreement (CLA) before the pull request can be reviewed. 23 | 24 | Signing the Contribution License Agreement (CLA) does not grant you rights to commit to the main 25 | repository, but it does mean we can review your pull request and consider your contributions to the project. 26 | 27 | You can view, download, and/or sign the [Contribution License Agreement](https://cla.microsoft.com/). This is only 28 | required if you wish to have your pull request considered. 29 | 30 | ## Use GitHub, Git, and this repository 31 | 32 | For details of how to use GitHub to contribute to a project most effectively, see the [Contributing to open source](https://guides.github.com/activities/contributing-to-open-source/) articles. 33 | 34 | ### Contribute feature or bug fix 35 | 36 | To make the contribution process as seamless as possible for you, follow this procedure. 37 | 38 | 1. **Fork** the repository into your own account. 39 | 2. **Create a new branch** for the bug/feature you are working on. 40 | 3. Implement the new functionality / bug fixes and add approriate test scenarios. 41 | 4. Submit a pull request to the main repository **master** branch. 42 | 43 | Limit each branch to a single concept/feature to streamline the workflow and reduce the 44 | chance of merge conflicts. 45 | 46 | Multiple small bug fixes may be combined in a single pull request, although if they 47 | become significant you may be requested to separate them into multiple branches / requests. 48 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/MultipartMimeTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.UnitTests 27 | { 28 | using NUnit.Framework; 29 | using MultipartMime; 30 | 31 | [TestFixture] 32 | public class MultipartMimeTests 33 | { 34 | [Test] 35 | public void RoundtripTest() 36 | { 37 | MultipartMime.MultipartMimeContent message = new MultipartMime.MultipartMimeContent(); 38 | message.Parts.Add(new MultipartMime.MessagePart { Id = "", ContentType = new MimeContentType("application/json"), Body = "{\"foo\": \"bar\"}" }); 39 | message.Parts.Add(new MultipartMime.MessagePart { Id = " 38 | /// Validatation requires that properties shown in the documentation's expected response are 39 | /// found when testing the service or simulatedResponse. 40 | /// 41 | public static bool ExpectedResponseAsRequiredProperties { get; set; } 42 | 43 | /// 44 | /// Instead of using the default OData metadata settings, force the odata metadata parameters to none. 45 | /// 46 | public static string ODataMetadataLevel { get; set; } 47 | 48 | /// 49 | /// An array of additional HTTP headers that are added to outgoing requests to the service. 50 | /// 51 | public static string[] AdditionalHttpHeaders { get; set; } 52 | 53 | public static int RetryAttemptsOnServiceUnavailableResponse { get; set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Config/MetadataValidationConfigFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Config 27 | { 28 | using Newtonsoft.Json; 29 | 30 | public class MetadataValidationConfigFile : ConfigFile 31 | { 32 | [JsonProperty("metadata-validation-configs")] 33 | public MetadataValidationConfigs MetadataValidationConfigs { get;set;} 34 | 35 | public override bool IsValid 36 | { 37 | get 38 | { 39 | return this.MetadataValidationConfigs != null; 40 | } 41 | } 42 | } 43 | 44 | public class MetadataValidationConfigs 45 | { 46 | [JsonProperty("modelConfigs")] 47 | public ModelConfigs ModelConfigs { get;set;} 48 | 49 | [JsonProperty("ignorableModels")] 50 | public string[] IgnorableModels { get; set; } 51 | 52 | } 53 | 54 | public class ModelConfigs 55 | { 56 | [JsonProperty("validateNamespace")] 57 | public bool ValidateNamespace { get;set;} 58 | 59 | [JsonProperty("aliasNamespace")] 60 | public string AliasNamespace { get; set; } 61 | 62 | [JsonProperty("truncatedPropertiesValidation")] 63 | public bool TruncatedPropertiesValidation { get; set; } 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /ApiDoctor.Console/Auth/BasicAccount.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.ConsoleApp.Auth 27 | { 28 | using System.Threading.Tasks; 29 | using System.Collections.Generic; 30 | using ApiDoctor.Validation; 31 | 32 | public class BasicAccount : IServiceAccount 33 | { 34 | public BasicAccount() 35 | { 36 | } 37 | 38 | public string BaseUrl { get; set; } 39 | public bool Enabled { get; set; } 40 | public string Name { get; set; } 41 | public string[] AdditionalHeaders { get; set; } 42 | public string Username { get; set; } 43 | public string Password { get; set; } 44 | public string[] Scopes { get; set; } 45 | public string[] ApiVersions { get; set; } 46 | public string[] Tags { get; set; } 47 | public AccountTransforms Transformations { get; } 48 | 49 | public Task PrepareForRequestAsync() 50 | { 51 | return Task.FromResult(true); 52 | } 53 | 54 | public AuthenicationCredentials CreateCredentials() 55 | { 56 | return new BasicCredentials { Username = this.Username, Password = this.Password }; 57 | } 58 | 59 | public void OverrideBaseUrl(string newBaseUrl) 60 | { 61 | this.BaseUrl = newBaseUrl; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Error/ValidationWarning.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Error 27 | { 28 | public class ValidationWarning : ValidationError 29 | { 30 | 31 | public ValidationWarning(ValidationErrorCode code, string source, string format, params object[] formatParams) 32 | : base(code, source, format, formatParams) 33 | { 34 | 35 | } 36 | 37 | public override bool IsWarning { get { return true; } } 38 | 39 | public override bool IsError { get { return false; } } 40 | } 41 | 42 | 43 | public class UndocumentedPropertyWarning : ValidationWarning 44 | { 45 | public UndocumentedPropertyWarning(string source, string propertyName, ParameterDataType propertyType, string resourceName) 46 | : base(ValidationErrorCode.AdditionalPropertyDetected, source, "Undocumented property '{0}' [{1}] was not expected on resource {2}.", propertyName, propertyType, resourceName) 47 | { 48 | this.PropertyName = propertyName; 49 | this.PropertyType = propertyType; 50 | this.ResourceName = resourceName; 51 | } 52 | 53 | public string PropertyName { get; private set; } 54 | public ParameterDataType PropertyType { get; private set; } 55 | public string ResourceName { get; private set; } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Params/PlaceholderValue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Params 27 | { 28 | using System.ComponentModel; 29 | using System.Runtime.CompilerServices; 30 | 31 | public class PlaceholderValue : INotifyPropertyChanged 32 | { 33 | private string placeholderText; 34 | 35 | public string PlaceholderKey 36 | { 37 | get { return this.placeholderText; } 38 | set 39 | { 40 | if (value != this.placeholderText) 41 | { 42 | this.placeholderText = value; 43 | this.RaisePropertyChanged(); 44 | } 45 | } 46 | } 47 | 48 | public PlaceholderLocation Location { get; set; } 49 | 50 | public string Value { get; set; } 51 | 52 | public string DefinedValue { get; set; } 53 | 54 | #region INotifyPropertyChanged 55 | 56 | public event PropertyChangedEventHandler PropertyChanged; 57 | 58 | protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) 59 | { 60 | var evt = this.PropertyChanged; 61 | if (null != evt) 62 | { 63 | evt(this, new PropertyChangedEventArgs(propertyName)); 64 | } 65 | } 66 | 67 | #endregion 68 | 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/HttpParserTests.cs: -------------------------------------------------------------------------------- 1 | using ApiDoctor.Validation.Http; 2 | using ApiDoctor.Validation.UnitTests.Properties; 3 | using NUnit.Framework; 4 | 5 | namespace ApiDoctor.Validation.UnitTests 6 | { 7 | [TestFixture] 8 | public class HttpParserTests 9 | { 10 | public static string FullHttpRequest => Resources.ExampleRequest; 11 | 12 | 13 | [Theory] 14 | [TestCase( 15 | @"GET https://graph.microsoft.com/beta/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'", 16 | "https://graph.microsoft.com/beta/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'")] 17 | public void ParseOdataUrl(string odataUrl, string actualUrl) 18 | { 19 | var request = HttpParser.ParseHttpRequest(odataUrl); 20 | Assert.That(actualUrl, Is.EqualTo(request.Url), "Parsed Url should be equal to request header url"); 21 | } 22 | 23 | [Test] 24 | [TestCase( 25 | @"GET HTTP/2.0 https://graph.microsoft.com/beta/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'", 26 | "HTTP/2.0")] 27 | public void HttpVersionShouldBeRespected(string odataUrl, string httpVersion) 28 | { 29 | var request = HttpParser.ParseHttpRequest(odataUrl); 30 | Assert.That(httpVersion, Is.EqualTo(request.HttpVersion), "When HttpVersion is specified, should be respected"); 31 | } 32 | 33 | [Test] 34 | [TestCase( 35 | @"GET https://graph.microsoft.com/beta/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'")] 36 | public void HttpVersionShouldDefaultToHttp1(string odataUrl) 37 | { 38 | var request = HttpParser.ParseHttpRequest(odataUrl); 39 | Assert.That("HTTP/1.1", Is.EqualTo(request.HttpVersion), "When HttpVersion is not specified, default to HTTP/1.1"); 40 | } 41 | 42 | [Test] 43 | public void ParseHttpRequest() 44 | { 45 | var exampleRequest = FullHttpRequest; 46 | var parsedRequest = HttpParser.ParseHttpRequest(exampleRequest); 47 | Assert.That(parsedRequest, Is.Not.Null); 48 | } 49 | 50 | [Test] 51 | [TestCase( 52 | @"GET https://graph.microsoft.com/beta/riskyUsers?$filter=riskLevel eq microsoft.graph.riskLevel'medium'", 53 | "GET")] 54 | public void ParseOdataMethod(string odataUrl, string method) 55 | { 56 | var request = HttpParser.ParseHttpRequest(odataUrl); 57 | Assert.That(method, Is.EqualTo(request.Method), "Parsed Method should be equal to request header method"); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /TableAndHeaderConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "tableDefinitions": { 3 | "tables": [ 4 | { 5 | "type": "AuthScopes", 6 | "titles": [ "Authentication Scopes" ], 7 | "parseAs": "AuthScopeDefinition" 8 | }, 9 | { 10 | "type": "EnumerationValues", 11 | "titles": [ "Enumerated Values", "{x} values" ], 12 | "parseAs": "EnumerationDefinition" 13 | }, 14 | { 15 | "type": "ErrorCodes", 16 | "parseAs": "ErrorDefinition", 17 | "titles": [ "Error Response" ] 18 | }, 19 | { 20 | "type": "HttpHeaders", 21 | "titles": [ "Request Headers", "Response Headers" ], 22 | "parseAs": "ParameterDefinition" 23 | }, 24 | { 25 | "type": "PathParameters", 26 | "titles": [ "Path Parameters" ], 27 | "parseAs": "ParameterDefinition" 28 | }, 29 | { 30 | "type": "QueryStringParameters", 31 | "titles": [ "Query String Parameters" ], 32 | "parseAs": "ParameterDefinition" 33 | }, 34 | { 35 | "type": "RequestObjectProperties", 36 | "titles": [ "Request Body" ], 37 | "parseAs": "ParameterDefinition" 38 | }, 39 | { 40 | "type": "ResourceNavigationPropertyDescriptions", 41 | "titles": [ "Relationships" ], 42 | "parseAs": "ParameterDefinition" 43 | }, 44 | { 45 | "type": "ResourcePropertyDescriptions", 46 | "titles": [ "Properties", "Instance Attributes" ], 47 | "parseAs": "ParameterDefinition" 48 | } 49 | ], 50 | "parsingRules": [ 51 | { 52 | "type": "ErrorDefinition", 53 | "columns": { 54 | "httpStatusCode": [ "HTTP Code" ], 55 | "httpStatusMessage": [ "Http Error Message" ], 56 | "errorCode": [ "Error Code" ], 57 | "description": [ "Error Message" ] 58 | } 59 | }, 60 | { 61 | "type": "ParameterDefinition", 62 | "columns": { 63 | "name": [ "Parameter Name", "Property Name", "Name", "Relationship name" ], 64 | "type": [ "Type", "Value" ], 65 | "description": [ "Description" ], 66 | "required": [ "Description" ] 67 | } 68 | }, 69 | { 70 | "type": "EnumerationDefinition", 71 | "columns": { 72 | "value": [ "Value" ], 73 | "description": [ "Description" ] 74 | } 75 | }, 76 | { 77 | "type": "AuthScopeDefinition", 78 | "columns": { 79 | "scope": [ "Scope Name" ], 80 | "title": [ "Title" ], 81 | "description": [ "Description" ], 82 | "required": [ "Required" ] 83 | } 84 | } 85 | ] 86 | } 87 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation/TableSpec/TableAndHeaderConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "tableDefinitions": { 3 | "tables": [ 4 | { 5 | "type": "AuthScopes", 6 | "titles": [ "Authentication Scopes" ], 7 | "parseAs": "AuthScopeDefinition" 8 | }, 9 | { 10 | "type": "EnumerationValues", 11 | "titles": [ "Enumerated Values" ], 12 | "parseAs": "EnumerationDefinition" 13 | }, 14 | { 15 | "type": "ErrorCodes", 16 | "parseAs": "ErrorDefinition", 17 | "titles": [ "Error Response" ] 18 | }, 19 | { 20 | "type": "HttpHeaders", 21 | "titles": [ "Request Headers", "Response Headers" ], 22 | "parseAs": "ParameterDefinition" 23 | }, 24 | { 25 | "type": "PathParameters", 26 | "titles": [ "Path Parameters" ], 27 | "parseAs": "ParameterDefinition" 28 | }, 29 | { 30 | "type": "QueryStringParameters", 31 | "titles": [ "Query String Parameters" ], 32 | "parseAs": "ParameterDefinition" 33 | }, 34 | { 35 | "type": "RequestObjectProperties", 36 | "titles": [ "Request Body" ], 37 | "parseAs": "ParameterDefinition" 38 | }, 39 | { 40 | "type": "ResourceNavigationPropertyDescriptions", 41 | "titles": [ "Relationships" ], 42 | "parseAs": "ParameterDefinition" 43 | }, 44 | { 45 | "type": "ResourcePropertyDescriptions", 46 | "titles": [ "Properties", "Instance Attributes" ], 47 | "parseAs": "ParameterDefinition" 48 | } 49 | ], 50 | "parsingRules": [ 51 | { 52 | "type": "ErrorDefinition", 53 | "columns": { 54 | "httpStatusCode": [ "HTTP Code" ], 55 | "httpStatusMessage": [ "Http Error Message" ], 56 | "errorCode": [ "Error Code" ], 57 | "description": [ "Error Message" ] 58 | } 59 | }, 60 | { 61 | "type": "ParameterDefinition", 62 | "columns": { 63 | "name": [ "Parameter Name", "Property Name", "Name", "Relationship name" ], 64 | "type": [ "Type", "Value" ], 65 | "description": [ "Description" ], 66 | "required": [ "Description" ] 67 | } 68 | }, 69 | { 70 | "type": "EnumerationDefinition", 71 | "columns": { 72 | "value": [ "Value" ], 73 | "description": [ "Description" ] 74 | } 75 | }, 76 | { 77 | "type": "AuthScopeDefinition", 78 | "columns": { 79 | "scope": [ "Scope Name" ], 80 | "title": [ "Title" ], 81 | "description": [ "Description" ], 82 | "required": [ "Required" ] 83 | } 84 | } 85 | ] 86 | } 87 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/Singleton.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Xml.Serialization; 32 | using Transformation; 33 | 34 | [XmlRoot("Singleton", Namespace = ODataParser.EdmNamespace)] 35 | [Mergable(CollectionIdentifier = "Name")] 36 | public class Singleton : XmlBackedTransformableObject, ISet 37 | { 38 | public Singleton() 39 | { 40 | this.NavigationPropertyBinding = new List(); 41 | } 42 | 43 | [XmlAttribute("Name"), SortBy] 44 | public string Name { get; set; } 45 | 46 | [XmlAttribute("Type"), ContainsType, MergePolicy(MergePolicy.EqualOrNull)] 47 | public string Type { get; set; } 48 | 49 | [XmlElement("NavigationPropertyBinding"), Sortable] 50 | public List NavigationPropertyBinding { get; set; } 51 | 52 | [XmlElement("Annotation", Namespace = ODataParser.EdmNamespace), MergePolicy(MergePolicy.EqualOrNull)] 53 | public List Annotation { get; set; } 54 | 55 | [XmlIgnore] 56 | public override string ElementIdentifier 57 | { 58 | get { return this.Name; } 59 | set { this.Name = value; } 60 | } 61 | 62 | [XmlIgnore] 63 | public object SourceMethods { get; set; } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Error/ValidationResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Error 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | 31 | public class ValidationResult 32 | { 33 | public T Value { get; private set; } 34 | public ValidationError[] Messages { get; private set; } 35 | 36 | public bool IsError 37 | { 38 | get 39 | { 40 | var query = from m in this.Messages where m.IsError select m; 41 | return query.FirstOrDefault() != null; 42 | } 43 | } 44 | 45 | public bool IsWarningOrError 46 | { 47 | get 48 | { 49 | var query = from m in this.Messages where m.IsError || m.IsWarning select m; 50 | return query.FirstOrDefault() != null; 51 | } 52 | } 53 | 54 | public ValidationResult(T result) 55 | { 56 | this.Value = result; 57 | this.Messages = new ValidationError[0]; 58 | } 59 | 60 | public ValidationResult(T result, IEnumerable messages) 61 | { 62 | this.Value = result; 63 | this.Messages = messages.ToArray(); 64 | } 65 | 66 | public ValidationResult(T result, ValidationError error) 67 | { 68 | this.Value = result; 69 | this.Messages = new ValidationError[] { error }; 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/logging.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System; 29 | using ApiDoctor.Validation.Error; 30 | 31 | /// 32 | /// Provides an accessible Logger for use throughout the library and callers to the library 33 | /// 34 | public static class Logging 35 | { 36 | private static ILogHelper StaticLogHelper { get; set; } 37 | 38 | public static void ProviderLogger(ILogHelper helper) 39 | { 40 | StaticLogHelper = helper; 41 | } 42 | 43 | private static ILogHelper GetLogger() 44 | { 45 | if (null == StaticLogHelper) 46 | { 47 | StaticLogHelper = new ConsoleLogHelper(); 48 | } 49 | 50 | // Make sure we always return something, evne if StaticLogHelper ended up being null due to a race condition. 51 | return StaticLogHelper ?? new ConsoleLogHelper(); 52 | } 53 | 54 | public static void LogMessage(ValidationError error) 55 | { 56 | var helper = GetLogger(); 57 | helper.RecordError(error); 58 | } 59 | } 60 | 61 | public interface ILogHelper 62 | { 63 | void RecordError(ValidationError error); 64 | 65 | } 66 | 67 | internal class ConsoleLogHelper : ILogHelper 68 | { 69 | public void RecordError(ValidationError error) 70 | { 71 | if (null != error) 72 | System.Diagnostics.Debug.WriteLine(error.ErrorText); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/Html/ExtendedElseTag.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Publishing.Html 27 | { 28 | using Mustache; 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Linq; 32 | using System.Text; 33 | using System.Threading.Tasks; 34 | 35 | internal class ExtendedElseTagDefinition : ContentTagDefinition 36 | { 37 | /// 38 | /// Initializes a new instance of a ElseTagDefinition. 39 | /// 40 | public ExtendedElseTagDefinition() 41 | : base("elsematch") 42 | { 43 | } 44 | 45 | /// 46 | /// Gets whether the tag only exists within the scope of its parent. 47 | /// 48 | protected override bool GetIsContextSensitive() 49 | { 50 | return true; 51 | } 52 | 53 | /// 54 | /// Gets the tags that indicate the end of the current tag's content. 55 | /// 56 | protected override IEnumerable GetClosingTags() 57 | { 58 | var tags = new List(base.GetClosingTags()) { "ifmatch" }; 59 | return tags; 60 | } 61 | 62 | /// 63 | /// Gets the parameters that are used to create a new child context. 64 | /// 65 | /// The parameters that are used to create a new child context. 66 | public override IEnumerable GetChildContextParameters() 67 | { 68 | return new TagParameter[0]; 69 | } 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /ApiDoctor.Publishing/Html/FileTagDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Publishing.Html 27 | { 28 | using System.Collections.Generic; 29 | using System.IO; 30 | using ApiDoctor.Validation; 31 | using Mustache; 32 | 33 | public class FileTagDefinition : TagDefinition 34 | { 35 | public FileTagDefinition() 36 | : base("url") 37 | { 38 | } 39 | 40 | public string RootDestinationFolder { get; set; } 41 | public string DestinationFile { get; set; } 42 | 43 | public override void GetText(TextWriter writer, Dictionary arguments, Scope context) 44 | { 45 | var filenameToReplace = arguments["filename"] as string; 46 | if (null != filenameToReplace) 47 | { 48 | var relativeFileUrl = DocSet.RelativePathToRootFromFile( 49 | this.DestinationFile, 50 | Path.Combine(this.RootDestinationFolder, filenameToReplace), 51 | true); 52 | writer.Write(relativeFileUrl); 53 | } 54 | } 55 | 56 | protected override bool GetHasContent() 57 | { 58 | return false; 59 | } 60 | 61 | protected override IEnumerable GetParameters() 62 | { 63 | return new TagParameter[] { new TagParameter("filename") { IsRequired = true } }; 64 | } 65 | 66 | 67 | public override IEnumerable GetChildContextParameters() 68 | { 69 | return new TagParameter[] { new TagParameter("filename") }; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Model/DocumentationProperty.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | using ApiDoctor.Validation; 27 | 28 | namespace ApiDoctor.DocumentationGeneration.Model 29 | { 30 | using System.Collections.Generic; 31 | 32 | using ApiDoctor.DocumentationGeneration.Extensions; 33 | using ApiDoctor.Validation.OData; 34 | 35 | public class DocumentationProperty 36 | { 37 | public DocumentationProperty(EntityFramework entityFramework, ComplexType complexType, Property property) 38 | { 39 | this.Name = property.Name; 40 | 41 | string typeName = property.Type; 42 | bool isCollection = property.Type.IsCollection(); 43 | if (isCollection) 44 | { 45 | typeName = property.Type.ElementName(); 46 | } 47 | 48 | var simpleType = typeName.ToODataSimpleType(); 49 | if (simpleType != SimpleDataType.None && 50 | simpleType != SimpleDataType.Object) 51 | { 52 | this.Type = new ParameterDataType(simpleType, isCollection); 53 | } 54 | else 55 | { 56 | this.Type = new ParameterDataType(typeName, isCollection); 57 | } 58 | this.TypeMarkDown = this.Type.GetMarkDown(); 59 | this.Description = property.GetDescription(entityFramework, complexType); 60 | } 61 | 62 | public string Description { get; private set; } 63 | 64 | public string Name { get; private set; } 65 | 66 | public ParameterDataType Type { get; private set; } 67 | 68 | public string TypeMarkDown { get; private set; } 69 | } 70 | } -------------------------------------------------------------------------------- /ApiDoctor.Publishing/Html/IfMatchTagDefinition.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Publishing.Html 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | using Mustache; 31 | 32 | public class IfMatchTagDefinition : TagDefinition 33 | { 34 | public IfMatchTagDefinition() 35 | : base("ifmatch") 36 | { 37 | 38 | } 39 | 40 | protected override IEnumerable GetParameters() 41 | { 42 | return new TagParameter[] { new TagParameter("currentValue") { IsRequired = true }, 43 | new TagParameter("expectedValue") { IsRequired = true } }; 44 | } 45 | 46 | 47 | public override bool ShouldGeneratePrimaryGroup(Dictionary arguments) 48 | { 49 | var currentValue = arguments["currentValue"] as string; 50 | var expectedValue = arguments["expectedValue"] as string; 51 | 52 | return (currentValue == expectedValue); 53 | } 54 | 55 | protected override bool GetHasContent() 56 | { 57 | return true; 58 | } 59 | 60 | protected override IEnumerable GetChildTags() 61 | { 62 | return new string[] { "elsematch" }; 63 | } 64 | 65 | public override bool ShouldCreateSecondaryGroup(TagDefinition definition) 66 | { 67 | return this.GetChildTags().Contains(definition.Name); 68 | } 69 | 70 | public override IEnumerable GetChildContextParameters() 71 | { 72 | return new TagParameter[0]; 73 | } 74 | } 75 | 76 | 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/test-docs/ExampleResources.md: -------------------------------------------------------------------------------- 1 | ## Resource with ISO 8601 timestamp, URL, and enumerated values. 2 | 3 | 4 | ```json 5 | { 6 | "year": 1234, 7 | "downloadUrl": "url", 8 | "createdDateTime": "timestamp", 9 | "season": "summer | fall | winter | spring", 10 | "ownerName": "rgregg", 11 | "contentType": "string" 12 | } 13 | ``` 14 | 15 | ### Properties 16 | 17 | | Name | Type | Description 18 | |:----------------|:----------|:-------------- 19 | | year | int | the year 20 | | downloadUrl | string | download url 21 | | createdDateTime | timestamp | created date time 22 | | season | season | season enum 23 | | ownerName | string | name of the owner 24 | | contentType | string | mimetype 25 | 26 | #### season values 27 | 28 | | Value 29 | |:--------- 30 | | summer 31 | | fall 32 | | winter 33 | | spring 34 | 35 | ## Example request/response that's completely valid 36 | 37 | 38 | ```http 39 | GET /timestamp 40 | ``` 41 | 42 | 43 | ```http 44 | HTTP/1.1 200 OK 45 | Content-Type: application/json 46 | 47 | { 48 | "year": 2015, 49 | "downloadUrl": "https://foobar.com/something/another", 50 | "createdDateTime": "2015-07-08T15:46:00Z", 51 | "season": "summer", 52 | "ownerName": "Ryan Gregg", 53 | "contentType": "text/plain" 54 | } 55 | ``` 56 | 57 | ## Example request/response that has invalid date format 58 | 59 | 60 | ```http 61 | GET /timestamp 62 | ``` 63 | 64 | 65 | ```http 66 | HTTP/1.1 200 OK 67 | Content-Type: application/json 68 | 69 | { 70 | "createdDateTime": "July 8, 2015 3:48 PM" 71 | } 72 | ``` 73 | 74 | ## Example request/response that has invalid URL format 75 | 76 | 77 | ```http 78 | GET /timestamp 79 | ``` 80 | 81 | 82 | ```http 83 | HTTP/1.1 200 OK 84 | Content-Type: application/json 85 | 86 | { 87 | "downloadUrl": "../something/another" 88 | } 89 | ``` 90 | 91 | 92 | ## Example request/response that has invalid enumerated value 93 | 94 | 95 | ```http 96 | GET /timestamp 97 | ``` 98 | 99 | 100 | ```http 101 | HTTP/1.1 200 OK 102 | Content-Type: application/json 103 | 104 | { 105 | "season": "jupiter" 106 | } 107 | ``` -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/NavigationProperty.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.Collections.Generic; 29 | using System.ComponentModel; 30 | using System.Xml.Serialization; 31 | using Transformation; 32 | using Utility; 33 | 34 | [XmlRoot("NavigationProperty", Namespace = ODataParser.EdmNamespace), Mergable(CollectionIdentifier = "Name")] 35 | public class NavigationProperty : Property 36 | { 37 | public NavigationProperty() 38 | { 39 | ContainsTarget = false; 40 | this.Annotation = new List(); 41 | } 42 | 43 | [XmlAttribute("ContainsTarget"), DefaultValue(false)] 44 | public bool ContainsTarget { get; set; } 45 | 46 | /// 47 | /// Indicates that this property can be included in a $expand query 48 | /// 49 | [XmlIgnore] 50 | public bool Expandable { get; set; } 51 | 52 | /// 53 | /// Indicates that the target of this property can be enumerated (e.g. GET /items) 54 | /// 55 | [XmlIgnore] 56 | public bool Enumerable { get; set; } 57 | 58 | /// 59 | /// Indicates how this property can be navigated via the URL. 60 | /// 61 | [XmlIgnore] 62 | public Navigability Navigation { get; set; } 63 | 64 | /// 65 | /// Indicates that change tracking can be used on this target. 66 | /// 67 | [XmlIgnore] 68 | public bool ChangeTracking { get; set; } 69 | } 70 | 71 | public enum Navigability 72 | { 73 | Recursive, 74 | Single, 75 | None 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Model/DocumentationComplexType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.DocumentationGeneration.Model 27 | { 28 | using System.Collections.Generic; 29 | using System.Linq; 30 | 31 | using ApiDoctor.DocumentationGeneration.Extensions; 32 | using ApiDoctor.Validation.OData; 33 | 34 | using Newtonsoft.Json; 35 | 36 | public class DocumentationComplexType 37 | { 38 | public DocumentationComplexType(EntityFramework entityFramework, ComplexType complexType) 39 | { 40 | this.Name = complexType.Name; 41 | this.Description = complexType.GetDescription(entityFramework); 42 | this.Namespace = complexType.Namespace; 43 | this.Properties = complexType.Properties.Select(p => p.ToDocumentationProperty(entityFramework, complexType)).ToList(); 44 | this.Json = ODataParser.BuildJsonExample(complexType, entityFramework.DataServices.Schemas);//SampleJsonGenerator.GetSampleJson(entityFramework, complexType).ToString(Formatting.Indented); 45 | 46 | 47 | if (complexType.BaseType != null) 48 | { 49 | var baseComplexType = entityFramework.DataServices.Schemas.FindTypeWithIdentifier(complexType.BaseType) as ComplexType; 50 | if (baseComplexType != null) 51 | { 52 | this.BaseType = baseComplexType.Name; 53 | } 54 | } 55 | } 56 | 57 | public string Namespace { get; private set; } 58 | 59 | public string BaseType { get; private set; } 60 | 61 | public string Description { get; private set; } 62 | 63 | public string Json { get; private set; } 64 | 65 | public string Name { get; private set; } 66 | 67 | public IList Properties { get; private set; } 68 | } 69 | } -------------------------------------------------------------------------------- /ApiDoctor.Validation/Writers/MarkdownPublisher.cs.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Writers 27 | { 28 | using System.IO; 29 | using System.Text; 30 | using System.Threading.Tasks; 31 | using ApiDoctor.Validation.Error; 32 | 33 | public class MarkdownPublisher : DocumentPublisher 34 | { 35 | public MarkdownPublisher(DocSet docset) : base (docset) 36 | { 37 | this.SourceFileExtensions = ".md,.mdown"; 38 | this.SkipPaths = "\\internal;\\.git;\\legacy;\\generate_html_docs;\\.gitignore;\\.gitattributes"; 39 | } 40 | 41 | /// 42 | /// Scans the text content of a file and removes any "internal" comments/references 43 | /// 44 | /// File. 45 | /// 46 | /// 47 | protected override async Task PublishFileToDestinationAsync(FileInfo sourceFile, DirectoryInfo destinationRoot, DocFile page, IssueLogger issues) 48 | { 49 | this.LogMessage(new ValidationMessage(sourceFile.Name, "Scanning text file for internal content.")); 50 | 51 | var outputPath = this.GetPublishedFilePath(sourceFile, destinationRoot); 52 | var writer = new StreamWriter(outputPath, false, Encoding.UTF8) { AutoFlush = true }; 53 | 54 | StreamReader reader = new StreamReader(sourceFile.OpenRead()); 55 | 56 | long lineNumber = 0; 57 | string nextLine; 58 | while ( (nextLine = await reader.ReadLineAsync()) != null) 59 | { 60 | lineNumber++; 61 | if (this.IsDoubleBlockQuote(nextLine)) 62 | { 63 | this.LogMessage(new ValidationMessage(string.Concat(sourceFile, ":", lineNumber), "Removing DoubleBlockQuote: {0}", nextLine)); 64 | continue; 65 | } 66 | await writer.WriteLineAsync(nextLine); 67 | } 68 | writer.Close(); 69 | reader.Close(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/DocumentHeader.cs: -------------------------------------------------------------------------------- 1 | using Fastenshtein; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace ApiDoctor.Validation 7 | { 8 | public class DocumentHeader 9 | { 10 | /// 11 | /// Represents the header level using markdown formatting (1=#, 2=##, 3=###, 4=####, 5=#####, 6=######) 12 | /// 13 | [JsonProperty("level")] 14 | public int Level { get; set; } 15 | 16 | /// 17 | /// Indicates that a header at this level is required. 18 | /// 19 | [JsonProperty("required")] 20 | public bool Required { get; set; } 21 | 22 | /// 23 | /// The expected value of a title or empty to indicate any value 24 | /// 25 | [JsonProperty("title")] 26 | public string Title { get; set; } 27 | 28 | /// 29 | /// Specifies the headers that are allowed/found under this header. 30 | /// 31 | [JsonProperty("headers")] 32 | public List ChildHeaders { get; set; } = new List(); 33 | 34 | public DocumentHeader() { } 35 | 36 | public DocumentHeader(DocumentHeader original) 37 | { 38 | Level = original.Level; 39 | Required = original.Required; 40 | Title = original.Title; 41 | 42 | if (original.ChildHeaders != null) 43 | { 44 | ChildHeaders = []; 45 | foreach (var header in original.ChildHeaders) 46 | { 47 | ChildHeaders.Add(new DocumentHeader(header)); 48 | } 49 | } 50 | } 51 | 52 | internal bool Matches(DocumentHeader found, bool ignoreCase = false, bool checkStringDistance = false) 53 | { 54 | if (checkStringDistance) 55 | return IsMisspelt(found); 56 | 57 | return this.Level == found.Level && DoTitlesMatch(this.Title, found.Title, ignoreCase); 58 | } 59 | 60 | private static bool DoTitlesMatch(string expectedTitle, string foundTitle, bool ignoreCase) 61 | { 62 | StringComparison comparisonType = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; 63 | 64 | if (expectedTitle.Equals(foundTitle, comparisonType)) 65 | return true; 66 | 67 | if (string.IsNullOrEmpty(expectedTitle) || expectedTitle == "*") 68 | return true; 69 | 70 | if (expectedTitle.StartsWith("* ") && foundTitle.EndsWith(expectedTitle[2..], comparisonType)) 71 | return true; 72 | 73 | if (expectedTitle.EndsWith(" *") && foundTitle.StartsWith(expectedTitle[..^2], comparisonType)) 74 | return true; 75 | 76 | return false; 77 | } 78 | 79 | internal bool IsMisspelt(DocumentHeader found) 80 | { 81 | return this.Level == found.Level && Levenshtein.Distance(this.Title, found.Title) < 3; 82 | } 83 | 84 | public override string ToString() 85 | { 86 | return this.Title; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/annotation.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using System; 30 | using System.Collections.Generic; 31 | using System.ComponentModel; 32 | using System.Xml.Serialization; 33 | using Transformation; 34 | 35 | [XmlRoot("Annotation", Namespace = ODataParser.EdmNamespace)] 36 | [Mergable(CollectionIdentifier = "Term")] 37 | public class Annotation : XmlBackedTransformableObject 38 | { 39 | private bool boolValue; 40 | private bool boolSpecified; 41 | 42 | [XmlAttribute("Term"), SortBy] 43 | public string Term { get; set; } 44 | 45 | [XmlAttribute("String"), DefaultValue(null), MergePolicy(MergePolicy.PreferGreaterValue)] 46 | public string String { get; set; } 47 | 48 | [XmlAttribute("Bool"), MergePolicy(MergePolicy.EqualOrNull)] 49 | public bool Bool 50 | { 51 | get 52 | { 53 | return this.boolValue; 54 | } 55 | 56 | set 57 | { 58 | this.boolValue = value; 59 | this.boolSpecified = true; 60 | } 61 | } 62 | 63 | [XmlIgnore] 64 | public bool BoolSpecified => this.Bool || this.boolSpecified; 65 | 66 | [XmlElement("EnumMember", Namespace = ODataParser.EdmNamespace), DefaultValue(null), MergePolicy(MergePolicy.EqualOrNull)] 67 | public string EnumMember { get; set; } 68 | 69 | [XmlElement("Record", Namespace = ODataParser.EdmNamespace), DefaultValue(null), Sortable] 70 | public List Records { get; set; } 71 | 72 | [XmlElement("Collection")] 73 | public RecordCollection Collection { get; set; } 74 | 75 | #region ITransformable 76 | 77 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 78 | public override string ElementIdentifier { get { return this.Term; } set { this.Term = value; } } 79 | #endregion 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/propertyvalue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) Microsoft Corporation 3 | * All rights reserved. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the ""Software""), to deal in 9 | * the Software without restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 11 | * Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | * PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | namespace ApiDoctor.Validation.OData 26 | { 27 | using System.Collections.Generic; 28 | using System.ComponentModel; 29 | using System.Xml.Serialization; 30 | using ApiDoctor.Validation.Utility; 31 | 32 | [XmlRoot("PropertyValue", Namespace = ODataParser.EdmNamespace)] 33 | [Mergable(CollectionIdentifier = "Property")] 34 | public class PropertyValue : XmlBackedObject 35 | { 36 | private bool boolValue; 37 | private bool boolSpecified; 38 | 39 | [XmlAttribute("Property"), MergePolicy(MergePolicy.EqualOrNull)] 40 | public string Property { get; set; } 41 | 42 | [XmlElement("EnumMember", Namespace = ODataParser.EdmNamespace), DefaultValue(null), MergePolicy(MergePolicy.EqualOrNull)] 43 | public string EnumMember { get; set; } 44 | 45 | [XmlAttribute("Bool"), MergePolicy(MergePolicy.EqualOrNull)] 46 | public bool Bool 47 | { 48 | get 49 | { 50 | return this.boolValue; 51 | } 52 | 53 | set 54 | { 55 | this.boolValue = value; 56 | this.boolSpecified = true; 57 | } 58 | } 59 | 60 | [XmlIgnore] 61 | public bool BoolSpecified => this.Bool || this.boolSpecified; 62 | 63 | [XmlAttribute("String"), DefaultValue(null), MergePolicy(MergePolicy.EqualOrNull)] 64 | public string String { get; set; } 65 | 66 | [XmlElement("Annotation")] 67 | public List AnnotationList { get; set; } 68 | 69 | [XmlElement("Record")] 70 | public List Records { get; set; } 71 | 72 | [XmlElement("Collection")] 73 | public RecordCollection Collection { get; set; } 74 | } 75 | 76 | public class RecordCollection 77 | { 78 | [XmlElement("Record")] 79 | public List Records { get; set; } 80 | 81 | [XmlElement("String")] 82 | public List Strings { get; set; } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/BackoffHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System; 29 | using System.Diagnostics; 30 | using System.Threading.Tasks; 31 | 32 | public class BackoffHelper 33 | { 34 | public int MaximumTimeMilliseconds { get; set; } 35 | 36 | public int BaseTimeMilliseconds { get; set; } 37 | 38 | private readonly Random random = new Random(); 39 | 40 | public BackoffHelper() 41 | { 42 | this.MaximumTimeMilliseconds = 30000; 43 | this.BaseTimeMilliseconds = 1000; 44 | } 45 | 46 | /// 47 | /// Implements the full jitter backoff algorithm as defined here: http://www.awsarchitectureblog.com/2015/03/backoff.html 48 | /// 49 | /// A task that completes after the duration of the delay. 50 | /// The number of times an error has occured for this particular command / session. 51 | public async Task FullJitterBackoffDelayAsync(int errorCount) 52 | { 53 | double expectedBackoffTime = Math.Min(this.MaximumTimeMilliseconds, this.BaseTimeMilliseconds * Math.Pow(2 , errorCount)); 54 | 55 | var sleepDuration = Between(this.random, 0, (int)expectedBackoffTime); 56 | 57 | Debug.WriteLine("Waiting for: {0} milliseconds", sleepDuration); 58 | await Task.Delay(sleepDuration); 59 | } 60 | 61 | private static int Between(Random rnd, int lowNumber, int highNumber) 62 | { 63 | var dbl = rnd.NextDouble(); 64 | int range = highNumber - lowNumber; 65 | double selectedValue = (dbl * range); 66 | return (int)(lowNumber + selectedValue); 67 | } 68 | 69 | 70 | private static BackoffHelper defaultInstance; 71 | public static BackoffHelper Default 72 | { 73 | get { return defaultInstance ?? (defaultInstance = new BackoffHelper()); } 74 | } 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/MultipartMime/MimeContentType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.MultipartMime 27 | { 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using Tags; 32 | 33 | public class MimeContentType 34 | { 35 | public MimeContentType() 36 | { 37 | this.Arguments = new Dictionary(StringComparer.OrdinalIgnoreCase); 38 | } 39 | 40 | public MimeContentType(string contentType) 41 | { 42 | this.Arguments = new Dictionary(StringComparer.OrdinalIgnoreCase); 43 | ParseContentTypeString(contentType); 44 | } 45 | 46 | public string MimeType { get; set; } 47 | 48 | public Dictionary Arguments { get; private set; } 49 | 50 | public void ParseContentTypeString(string input) 51 | { 52 | if (input == null) 53 | return; 54 | 55 | string[] contentTypeParts = input.Split(';'); 56 | if (contentTypeParts.Length > 0) 57 | MimeType = contentTypeParts[0]; 58 | for(int i=1; i 0) 64 | { 65 | Arguments[argument.Substring(0, index).Trim()] = argument.Substring(index + 1).Trim(); 66 | } 67 | else 68 | { 69 | Arguments[argument] = string.Empty; 70 | } 71 | } 72 | } 73 | 74 | public override string ToString() 75 | { 76 | StringBuilder args = new StringBuilder(); 77 | foreach(var arg in Arguments) 78 | { 79 | args.Append($"; {arg.Key}={arg.Value}"); 80 | } 81 | 82 | return MimeType + args.ToString(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/ReturnType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.ComponentModel; 29 | using System.Xml.Serialization; 30 | using Transformation; 31 | using Utility; 32 | 33 | [XmlRoot("ReturnType", Namespace = ODataParser.EdmNamespace), Mergable] 34 | public class ReturnType : XmlBackedTransformableObject 35 | { 36 | private bool isNullable; 37 | 38 | public ReturnType() 39 | { 40 | this.Unicode = true; 41 | } 42 | 43 | [XmlAttribute("Type"), ContainsType] 44 | public string Type { get; set; } 45 | 46 | [XmlAttribute("Nullable"), MergePolicy(MergePolicy.PreferFalseValue)] 47 | public bool Nullable 48 | { 49 | get { return this.isNullable; } 50 | set 51 | { 52 | this.isNullable = value; 53 | this.NullableSpecified = true; 54 | } 55 | } 56 | 57 | [XmlIgnore] 58 | public bool NullableSpecified { get; set; } 59 | 60 | [XmlAttribute("Unicode"), DefaultValue(true)] 61 | public bool Unicode { get; set; } 62 | 63 | public override string ElementIdentifier 64 | { 65 | get 66 | { 67 | return null; 68 | } 69 | 70 | set 71 | { 72 | 73 | } 74 | } 75 | 76 | public override bool Equals(object obj) 77 | { 78 | var other = obj as ReturnType; 79 | if (other != null) 80 | { 81 | return 82 | string.Equals(this.Type, other.Type) && 83 | this.Nullable == other.Nullable && 84 | this.Unicode == other.Unicode; 85 | } 86 | 87 | return false; 88 | } 89 | 90 | public override int GetHashCode() 91 | { 92 | return this.Type.GetHashCode() ^ this.Nullable.GetHashCode() ^ this.Unicode.GetHashCode(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/Config/ApiRequirementsFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.Config 27 | { 28 | using Newtonsoft.Json; 29 | 30 | public class ApiRequirementsFile : ConfigFile 31 | { 32 | [JsonProperty("api-requirements")] 33 | public ApiRequirements ApiRequirements {get;set;} 34 | 35 | public override bool IsValid 36 | { 37 | get 38 | { 39 | return this.ApiRequirements != null; 40 | } 41 | } 42 | } 43 | 44 | public class ApiRequirements 45 | { 46 | [JsonProperty("httpRequest")] 47 | public HttpRequestRequirements HttpRequest {get;set;} 48 | 49 | [JsonProperty("httpResponse")] 50 | public HttpResponseRequirements HttpResponse {get;set;} 51 | 52 | [JsonProperty("jsonSerialization")] 53 | public JsonSerializationRequirements JsonSerialization {get;set;} 54 | 55 | [JsonProperty("ignorableProperties")] 56 | 57 | public string[] IgnorableProperties { get; set; } 58 | [JsonProperty("caseSensativeHeaders")] 59 | public bool CaseSensativeHeaders { get; set; } 60 | } 61 | 62 | public class HttpRequestRequirements 63 | { 64 | [JsonProperty("maxUrlLength")] 65 | public int MaxUrlLength {get;set;} 66 | [JsonProperty("httpMethods")] 67 | public string[] HttpMethods {get;set;} 68 | [JsonProperty("standardHeaders")] 69 | public string[] StandardHeaders {get;set;} 70 | [JsonProperty("contentTypes")] 71 | public string[] ContentTypes {get;set;} 72 | } 73 | 74 | public class HttpResponseRequirements 75 | { 76 | [JsonProperty("contentTypes")] 77 | public string[] ContentTypes {get;set;} 78 | } 79 | 80 | public class JsonSerializationRequirements 81 | { 82 | [JsonProperty("collectionPropertyNames")] 83 | public string[] CollectionPropertyNames {get;set;} 84 | [JsonProperty("dateTimeFormats")] 85 | public string[] DateTimeFormats {get;set;} 86 | } 87 | 88 | } 89 | 90 | -------------------------------------------------------------------------------- /ApiDoctor.Console/ApiDoctor.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | true 5 | Exe 6 | apidoc 7 | ..\ 8 | true 9 | false 10 | publish\ 11 | true 12 | Disk 13 | false 14 | Foreground 15 | 7 16 | Days 17 | false 18 | false 19 | true 20 | 0 21 | 1.0.0.%2a 22 | false 23 | true 24 | false 25 | $(NuspecProperties);version=$(PackageVersion) 26 | 27 | 28 | check-docs --path /Users/dspektor/src/graphdocs2 29 | true 30 | 31 | 32 | ApiDoctor.ConsoleApp.Program 33 | 34 | 35 | false 36 | false 37 | 38 | 39 | 35MSSharedLib1024.snk 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | False 49 | Microsoft .NET Framework 4.5 %28x86 and x64%29 50 | true 51 | 52 | 53 | False 54 | .NET Framework 3.5 SP1 Client Profile 55 | false 56 | 57 | 58 | False 59 | .NET Framework 3.5 SP1 60 | false 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /ApiDoctor.Validation.UnitTests/YamlParserTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.UnitTests 27 | { 28 | using System.Linq; 29 | using ApiDoctor.Validation; 30 | using ApiDoctor.Validation.Error; 31 | using NUnit.Framework; 32 | 33 | [TestFixture] 34 | public class YamlParserTests 35 | { 36 | private static readonly string yamlWithMultiLineArray = @"title: ""Define the /me as singleton"" 37 | description: ""These are things I had to add in the docs to make sure the Markdown-Scanner"" 38 | ms.localizationpriority: medium 39 | author: """" 40 | ms.prod: """" 41 | doc_type: conceptualPageType 42 | toc.keywords: 43 | - foo 44 | - bar 45 | "; 46 | 47 | // Missing closing double-quote on title property 48 | private static readonly string malformedYaml = @"title: ""Define the /me as singleton 49 | description: ""These are things I had to add in the docs to make sure the Markdown-Scanner"" 50 | ms.localizationpriority: medium 51 | author: """" 52 | ms.prod: """" 53 | doc_type: conceptualPageType 54 | toc.keywords: 55 | - foo 56 | - bar 57 | "; 58 | 59 | [Test] 60 | public void YamlWithMultiLineArrayParses() 61 | { 62 | // Arrange 63 | _ = new DocSet(); 64 | var issues = new IssueLogger(); 65 | 66 | // Act 67 | DocFile.ParseYamlMetadata(yamlWithMultiLineArray, issues); 68 | 69 | // Assert 70 | Assert.That(!issues.Issues.WereErrors()); 71 | } 72 | 73 | [Test] 74 | public void MalformedYamlGeneratesError() 75 | { 76 | // Arrange 77 | _ = new DocSet(); 78 | var issues = new IssueLogger(); 79 | 80 | // Act 81 | DocFile.ParseYamlMetadata(malformedYaml, issues); 82 | 83 | // Assert 84 | Assert.That(issues.Issues.WereErrors()); 85 | var error = issues.Issues.FirstOrDefault(); 86 | Assert.That(error != null); 87 | Assert.That(error.IsError); 88 | Assert.That(error.Message.FirstLineOnly() == "Incorrect YAML header format"); 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /ApiDoctor.DocumentationGeneration/Properties/Templates.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ApiDoctor.DocumentationGeneration.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Templates { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Templates() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ApiDoctor.DocumentationGeneration.Properties.Templates", typeof(Templates).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Byte[]. 65 | /// 66 | internal static byte[] resourceMarkDown { 67 | get { 68 | object obj = ResourceManager.GetObject("resourceMarkDown", resourceCulture); 69 | return ((byte[])(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/EntitySet.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using System.Collections.Generic; 29 | using System.Xml.Serialization; 30 | using Transformation; 31 | using Utility; 32 | 33 | [XmlRoot("EntitySet", Namespace = ODataParser.EdmNamespace)] 34 | [Mergable(CollectionIdentifier = "Name")] 35 | public class EntitySet : XmlBackedTransformableObject, ISet 36 | { 37 | public EntitySet() 38 | { 39 | this.NavigationPropertyBinding = new List(); 40 | } 41 | 42 | [XmlAttribute("Name"), SortBy] 43 | public string Name { get; set; } 44 | 45 | [XmlAttribute("EntityType"), ContainsType, MergePolicy(MergePolicy.EqualOrNull)] 46 | public string EntityType { get; set; } 47 | 48 | [XmlElement("NavigationPropertyBinding"), Sortable] 49 | public List NavigationPropertyBinding { get; set; } 50 | 51 | [XmlElement("Annotation", Namespace = ODataParser.EdmNamespace), MergePolicy(MergePolicy.EqualOrNull)] 52 | public List Annotation { get; set; } 53 | 54 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 55 | public override string ElementIdentifier { get { return this.Name; } set { this.Name = value; } } 56 | 57 | [XmlIgnore, MergePolicy(MergePolicy.Ignore)] 58 | public object SourceMethods { get; set; } 59 | } 60 | 61 | [Mergable(CollectionIdentifier = "Path")] 62 | public class NavigationPropertyBinding: ITransformable 63 | { 64 | [XmlAttribute("Path"), SortBy] 65 | public string Path { get; set; } 66 | 67 | [XmlAttribute("Target"), ContainsType, MergePolicy(MergePolicy.EqualOrNull)] 68 | public string Target { get; set; } 69 | 70 | [XmlIgnore] 71 | public string ElementIdentifier 72 | { 73 | get { return this.Path; } 74 | set { this.Path = value; } 75 | } 76 | 77 | public void ApplyTransformation(BaseModifications mods, EntityFramework edmx, string[] versions) 78 | { 79 | TransformationHelper.ApplyTransformation(this, mods, edmx, versions); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/OData/EntityFramework.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation.OData 27 | { 28 | using Utility; 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Linq; 32 | using System.Text; 33 | using System.Threading.Tasks; 34 | using System.Xml.Linq; 35 | using System.Xml.Serialization; 36 | using Transformation; 37 | 38 | /// 39 | /// Holds a representation of an entity framework model (EDMX) 40 | /// 41 | [XmlRoot("Edmx", Namespace = ODataParser.EdmxNamespace)] 42 | [Mergable] 43 | public class EntityFramework : XmlBackedObject 44 | { 45 | [XmlAttribute("Version")] 46 | [MergePolicy(Policy = MergePolicy.EqualOrNull)] 47 | public string Version { get; set; } 48 | 49 | [XmlElement("DataServices")] 50 | public DataServices DataServices { get; set; } 51 | 52 | public EntityFramework() 53 | { 54 | this.DataServices = new DataServices(); 55 | this.DataServices.Schemas = new List(); 56 | this.Version = "4.0"; 57 | } 58 | 59 | public EntityFramework(IEnumerable schemas) 60 | { 61 | this.DataServices = new DataServices(); 62 | this.DataServices.Schemas = new List(schemas); 63 | this.Version = "4.0"; 64 | } 65 | 66 | /// 67 | /// Apply schema / publishing changes to the EntityFramework 68 | /// 69 | /// 70 | public void ApplyTransformation(PublishSchemaChanges changes, string[] versions) 71 | { 72 | if (changes.NamespacesToPublish != null && changes.NamespacesToPublish.Any()) 73 | { 74 | DataServices.Schemas.RemoveAll(x => !changes.NamespacesToPublish.Contains(x.Namespace)); 75 | } 76 | 77 | TransformationHelper.ApplyTransformationToCollection(changes.Schemas, DataServices.Schemas, this, versions); 78 | } 79 | 80 | internal void RenameEntityType(ComplexType renamedType) 81 | { 82 | // renamedType could be ComplexType or EntityType 83 | this.RenameTypeInObjectGraph(renamedType.WorkloadName, renamedType.Name); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /ApiDoctor.Validation/IServiceAccount.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * API Doctor 3 | * Copyright (c) Microsoft Corporation 4 | * All rights reserved. 5 | * 6 | * MIT License 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the ""Software""), to deal in 10 | * the Software without restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 12 | * Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 19 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | namespace ApiDoctor.Validation 27 | { 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Threading.Tasks; 31 | 32 | public interface IServiceAccount 33 | { 34 | /// 35 | /// Display name of the account 36 | /// 37 | string Name { get; } 38 | 39 | /// 40 | /// Determine if the account is enabled for use in test runs. 41 | /// 42 | bool Enabled { get; } 43 | 44 | /// 45 | /// Base URL for all relative API URLs 46 | /// 47 | string BaseUrl { get; } 48 | 49 | /// 50 | /// Scopes supported by this account / authentication 51 | /// 52 | string[] Scopes {get;} 53 | 54 | /// 55 | /// ApiVersions supported by this account / authentication 56 | /// 57 | string[] ApiVersions {get;} 58 | 59 | /// 60 | /// Tags represent any other capabilities, such as services, associated with this account 61 | /// 62 | string[] Tags {get;} 63 | 64 | /// 65 | /// Additional HTTP headers added to all requests for this account 66 | /// 67 | string[] AdditionalHeaders { get; } 68 | 69 | /// 70 | /// Collection of namespaces that are rewritten when a request is generated. Allows conversion between microsoft.graph and workload namespace, for example. 71 | /// 72 | AccountTransforms Transformations { get; } 73 | 74 | /// 75 | /// Called the first time an account is created, allowing the account to 76 | /// refresh any information required to make a service request. 77 | /// 78 | Task PrepareForRequestAsync(); 79 | 80 | /// 81 | /// Ask the account to generate a credentials instance which is passed on. 82 | /// 83 | /// 84 | AuthenicationCredentials CreateCredentials(); 85 | 86 | /// 87 | /// Allow the base url to be overridden if passed in from another source 88 | /// 89 | /// 90 | void OverrideBaseUrl(string newBaseUrl); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Mac File System files 2 | .DS_Store 3 | 4 | ## Ignore Visual Studio temporary files, build results, and 5 | ## files generated by popular Visual Studio add-ons. 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | *.userprefs 13 | .vs/ 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | build/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | 27 | # Roslyn cache directories 28 | *.ide/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | #NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | *_i.c 44 | *_p.c 45 | *_i.h 46 | *.ilk 47 | *.meta 48 | *.obj 49 | *.pch 50 | *.pdb 51 | *.pgc 52 | *.pgd 53 | *.rsp 54 | *.sbr 55 | *.tlb 56 | *.tli 57 | *.tlh 58 | *.tmp 59 | *.tmp_proj 60 | *.log 61 | *.vspscc 62 | *.vssscc 63 | .builds 64 | *.pidb 65 | *.svclog 66 | *.scc 67 | 68 | # Chutzpah Test files 69 | _Chutzpah* 70 | 71 | # Visual C++ cache files 72 | ipch/ 73 | *.aps 74 | *.ncb 75 | *.opensdf 76 | *.sdf 77 | *.cachefile 78 | 79 | # Visual Studio profiler 80 | *.psess 81 | *.vsp 82 | *.vspx 83 | 84 | # TFS 2012 Local Workspace 85 | $tf/ 86 | 87 | # Guidance Automation Toolkit 88 | *.gpState 89 | 90 | # ReSharper is a .NET coding add-in 91 | _ReSharper*/ 92 | *.[Rr]e[Ss]harper 93 | *.DotSettings.user 94 | 95 | # JustCode is a .NET coding addin-in 96 | .JustCode 97 | 98 | # TeamCity is a build add-in 99 | _TeamCity* 100 | 101 | # DotCover is a Code Coverage Tool 102 | *.dotCover 103 | 104 | # NCrunch 105 | _NCrunch_* 106 | .*crunch*.local.xml 107 | 108 | # MightyMoose 109 | *.mm.* 110 | AutoTest.Net/ 111 | 112 | # Web workbench (sass) 113 | .sass-cache/ 114 | 115 | # Installshield output folder 116 | [Ee]xpress/ 117 | 118 | # DocProject is a documentation generator add-in 119 | DocProject/buildhelp/ 120 | DocProject/Help/*.HxT 121 | DocProject/Help/*.HxC 122 | DocProject/Help/*.hhc 123 | DocProject/Help/*.hhk 124 | DocProject/Help/*.hhp 125 | DocProject/Help/Html2 126 | DocProject/Help/html 127 | 128 | # Click-Once directory 129 | publish/ 130 | 131 | # Publish Web Output 132 | *.[Pp]ublish.xml 133 | *.azurePubxml 134 | # TODO: Comment the next line if you want to checkin your web deploy settings 135 | # but database connection strings (with potential passwords) will be unencrypted 136 | *.pubxml 137 | *.publishproj 138 | 139 | # NuGet Packages 140 | *.nupkg 141 | # The packages folder can be ignored because of Package Restore 142 | **/packages/* 143 | # except build/, which is used as an MSBuild target. 144 | !**/packages/build/ 145 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 146 | #!**/packages/repositories.config 147 | 148 | # Windows Azure Build Output 149 | csx/ 150 | *.build.csdef 151 | 152 | # Windows Store app package directory 153 | AppPackages/ 154 | 155 | # Others 156 | *.Cache 157 | ClientBin/ 158 | [Ss]tyle[Cc]op.* 159 | ~$* 160 | *~ 161 | *.dbmdl 162 | *.dbproj.schemaview 163 | *.pfx 164 | *.publishsettings 165 | node_modules/ 166 | bower_components/ 167 | 168 | # RIA/Silverlight projects 169 | Generated_Code/ 170 | 171 | # Backup & report files from converting an old project file 172 | # to a newer Visual Studio version. Backup files are not needed, 173 | # because we have git ;-) 174 | _UpgradeReport_Files/ 175 | Backup*/ 176 | UpgradeLog*.XML 177 | UpgradeLog*.htm 178 | 179 | # SQL Server files 180 | *.mdf 181 | *.ldf 182 | 183 | # Business Intelligence projects 184 | *.rdl.data 185 | *.bim.layout 186 | *.bim_*.settings 187 | 188 | # Microsoft Fakes 189 | FakesAssemblies/ 190 | /packages 191 | --------------------------------------------------------------------------------