Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 >();
Copy link
Member

@tbombach tbombach Jun 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: spacing? I think these spaces will be removed the next time someone autoformats the document

}

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