Skip to content

Commit

Permalink
Fixes Azure#881 - failure to accept x-* vendor extension in path (Azu…
Browse files Browse the repository at this point in the history
…re#1122)

* Fixes Azure#881 - failure to accept x-* vendor extension in path

* fixed code analysis issue

* code analysis again
  • Loading branch information
fearthecowboy committed Jun 6, 2016
1 parent cd47ac1 commit 81ba78c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="VendorExtensionInPath.cs" />
<Compile Include="SwaggerSpecHelper.cs" />
<Compile Include="SwaggerModelerTests.cs" />
<None Include="app.config" />
Expand Down Expand Up @@ -90,6 +91,9 @@
<None Include="Swagger\swagger-simple-spec.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Swagger\vendor-extension-in-path.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Swagger\swagger-x-ms-parameterized-host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -155,7 +159,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties Swagger_4swagger-x-ms-code-generation-settings_1json__JSONSchema="..\..\..\..\schema\swagger-extensions.json" Swagger_4swagger-validation_1json__JSONSchema="http://json.schemastore.org/swagger-2.0" />
<UserProperties Swagger_4swagger-validation_1json__JSONSchema="http://json.schemastore.org/swagger-2.0" Swagger_4swagger-x-ms-code-generation-settings_1json__JSONSchema="..\..\..\..\schema\swagger-extensions.json" />
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"swagger": "2.0",
"info": {
"version": "2.0",
"title": "My web service",
"description": "No description provided.",
"x-endpoint-name": "default"
},
"host": "dsw12.net:999",
"basePath": "/sandbox/8c88389038102937482abf83f8f/services/5b737fefc19b3047ab4f3234cd34642df2",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/swagger.json": {
"get": {
"summary": "Get swagger API document for the web service",
"operationId": "getSwaggerDocument",
"parameters": [
{
"name": "api-version",
"in": "query",
"description": "API version",
"required": false,
"type": "string",
"default": "2.0",
"enum": [
"2.0"
]
}
],
"responses": {
"200": {
"description": "Swagger API document for this service"
}
}
}
},
"x-vendor-testy": "asd"
}
}
30 changes: 30 additions & 0 deletions AutoRest/Modelers/Swagger.Tests/VendorExtensionInPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.IO;
using Microsoft.Rest.Generator;
using Xunit;

namespace Microsoft.Rest.Modeler.Swagger.Tests
{
[Collection("AutoRest Tests")]
public class VendorExtensionInPath
{
[Fact]
public void AllowVendorExtensionInPath()
{
SwaggerModeler modeler = new SwaggerModeler(new Settings
{
Namespace = "Test",
Input = Path.Combine("Swagger", "vendor-extension-in-path.json")
});
var clientModel = modeler.Build();

// should return a valid model.
Assert.NotNull(clientModel);

// there should be one method in this generated api.
Assert.Equal(1, modeler.ServiceClient.Methods.Count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public override bool CanConvert(System.Type objectType)
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue,
JsonSerializer serializer)
{
// is the leaf an vendor extension? "x-*..."
if (reader == null || reader.Path.Substring(reader.Path.LastIndexOf(".", StringComparison.Ordinal) + 1).StartsWith("x-",StringComparison.CurrentCulture))
{
// skip x-* vendor extensions when used where the path would be.
return new Dictionary < string, Operation >();
}

JObject jobject = JObject.Load(reader);
if (jobject == null)
{
Expand Down

0 comments on commit 81ba78c

Please sign in to comment.