Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
9 changes: 9 additions & 0 deletions 9 src/Microsoft.OpenApi/Models/OpenApiReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public string ReferenceV3
{
return Id;
}
if (Id.StartsWith("http"))
{
return Id;
}

return "#/components/" + Type.GetDisplayName() + "/" + Id;
}
Expand Down Expand Up @@ -236,6 +240,11 @@ private string GetExternalReferenceV3()
return ExternalResource + "#" + Id;
}

if (Id.StartsWith("http"))
{
return Id;
}

return ExternalResource + "#/components/" + Type.GetDisplayName() + "/" + Id;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;
using System;
using System.Collections.Generic;
using System.Runtime;
using System.Text.Json.Nodes;

namespace Microsoft.OpenApi.Models.References
Expand Down
8 changes: 5 additions & 3 deletions 8 src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer
string refId = !pointer.Contains('#') ? pointer : refSegments.Last();

var isExternalResource = !refSegments.First().StartsWith("#");
string externalResource = isExternalResource
? $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}"
: null;
string externalResource = null;
if (isExternalResource && pointer.Contains('#'))
{
externalResource = $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}";
}

return (refId, externalResource);
}
Expand Down
8 changes: 4 additions & 4 deletions 8 test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<DependentUpon>OpenApiCallbackReferenceTests.cs</DependentUpon>
</None>

<None Update="Models\Samples\docWithDollarId.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<None Update="Models\Samples\docWithReusableWebhooks.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<None Update="PublicApi\PublicApi.approved.txt" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\Samples\" />
</ItemGroup>
</Project>
49 changes: 49 additions & 0 deletions 49 test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,5 +1642,54 @@ public void SerializeV31DocumentWithRefsInWebhooksWorks()
var actual = stringWriter.ToString();
actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
}

[Fact]
public void SerializeDocWithDollarIdInDollarRefSucceeds()
{
var expected = @"openapi: '3.1.0'
info:
title: Simple API
version: 1.0.0
paths:
/box:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: https://foo.bar/Box
/circle:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: https://foo.bar/Circle
components:
schemas:
Box:
$id: https://foo.bar/Box
type: object
properties:
width:
type: number
height:
type: number
Circle:
$id: https://foo.bar/Circle
type: object
properties:
radius:
type: number
";
var doc = OpenApiDocument.Load("Models/Samples/docWithDollarId.yaml").OpenApiDocument;

var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
}
}
}
39 changes: 39 additions & 0 deletions 39 test/Microsoft.OpenApi.Tests/Models/Samples/docWithDollarId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
openapi: 3.1.0
info:
title: Simple API
version: 1.0.0
paths:
/box:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: https://foo.bar/Box
/circle:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: https://foo.bar/Circle
components:
schemas:
Box:
$id: https://foo.bar/Box
type: object
properties:
width:
type: number
height:
type: number
Circle:
$id: https://foo.bar/Circle
type: object
properties:
radius:
type: number
Morty Proxy This is a proxified and sanitized view of the page, visit original site.