diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/ReadmeParser.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/ReadmeParser.cs index 4b1480de339..6b05d5b4a6f 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/ReadmeParser.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/ReadmeParser.cs @@ -54,8 +54,8 @@ public static IEnumerable GetSwaggerFilesFromReadme(string readme, strin readmeTag = parser.basicConfig.tag; } - parser.inputSwaggerFilesMap.TryGetValue(readmeTag, out InputSwaggerFiles ret); - return ret != null ? ret.input : new List(); + parser.inputSwaggerFilesMap.TryGetValue(readmeTag, out InputSwaggerFiles inputFiles); + return inputFiles?.input ?? Enumerable.Empty(); } private void ParseReadmeConfig() { @@ -93,6 +93,8 @@ private void ParseReadmeConfig() } var tag = ReadmeParser.GetTagFromYamlArguments(argument); + + inputSwaggerFiles.input?.Sort(StringComparer.InvariantCultureIgnoreCase); inputSwaggerFilesMap.Add(tag, inputSwaggerFiles); } } diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/ReadmeParserTest.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/ReadmeParserTest.cs index 6719a0a4656..d9a26736e16 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/ReadmeParserTest.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/ReadmeParserTest.cs @@ -72,4 +72,12 @@ public void TestGetTagFromYamlArgumentsInvalidCase() Assert.Equal("", result); } + + [Fact] + public void TestOrderedInputFiles() + { + const string readmeFilePath = "./fixtures/unordered.md"; + var inputFiles = ReadmeParser.GetSwaggerFilesFromReadme(readmeFilePath, "package-2023-02"); + Assert.Collection(inputFiles, x => Assert.Equal("a.json", x), x => Assert.Equal("z.json", x)); + } } diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerApiParserTest.csproj b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerApiParserTest.csproj index 2118e939843..b7d609b6c2e 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerApiParserTest.csproj +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerApiParserTest.csproj @@ -25,5 +25,8 @@ + + + diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/unordered.md b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/unordered.md new file mode 100644 index 00000000000..23959e07130 --- /dev/null +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/unordered.md @@ -0,0 +1,42 @@ +# Unordered + +> see https://aka.ms/autorest + +This is the AutoRest configuration file for Unordered. + +--- + +## Getting Started + +To build the SDK for ApiManagement, simply [Install AutoRest](https://aka.ms/autorest/install) and in this folder, run: + +> `autorest` + +To see additional help and options, run: + +> `autorest --help` + +--- + +## Configuration + +### Basic Information + +These are the global settings for the ApiManagement API. + +``` yaml +title: UnorderedClient +description: Unordered Client +tag: package-2023-02 +``` + + +### Tag: package-2023-02 + +These settings apply only when `--tag=package-2023-02` is specified on the command line. + +```yaml $(tag) == 'package-2023-02' +input-file: + - z.json + - a.json +```