Skip to content

Commit

Permalink
Merge pull request #1159 from microsoft/bugfix/copy-constructors-rela…
Browse files Browse the repository at this point in the history
…tive-urls

- fixes a bug where copy constructors would fail on relative urls
  • Loading branch information
baywet authored Feb 13, 2023
2 parents c99a51a + 116b56d commit 21e91c6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Models/OpenApiContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public OpenApiContact() { }
public OpenApiContact(OpenApiContact contact)
{
Name = contact?.Name ?? Name;
Url = contact?.Url != null ? new Uri(contact.Url.OriginalString) : null;
Url = contact?.Url != null ? new Uri(contact.Url.OriginalString, UriKind.RelativeOrAbsolute) : null;
Email = contact?.Email ?? Email;
Extensions = contact?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(contact.Extensions) : null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible
/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiExternalDocs() {}
public OpenApiExternalDocs() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiExternalDocs"/> object
/// </summary>
public OpenApiExternalDocs(OpenApiExternalDocs externalDocs)
{
Description = externalDocs?.Description ?? Description;
Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString) : null;
Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString, UriKind.RelativeOrAbsolute) : null;
Extensions = externalDocs?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(externalDocs.Extensions) : null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiLicense.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiLicense() {}
public OpenApiLicense() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiLicense"/> object
/// </summary>
public OpenApiLicense(OpenApiLicense license)
{
Name = license?.Name ?? Name;
Url = license?.Url != null ? new Uri(license.Url.OriginalString) : null;
Url = license?.Url != null ? new Uri(license.Url.OriginalString, UriKind.RelativeOrAbsolute) : null;
Extensions = license?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(license.Extensions) : null;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiOAuthFlow() {}
public OpenApiOAuthFlow() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiOAuthFlow"/> object
/// </summary>
public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow)
{
AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString) : null;
TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString) : null;
RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString) : null;
AuthorizationUrl = oAuthFlow?.AuthorizationUrl != null ? new Uri(oAuthFlow.AuthorizationUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
Scopes = oAuthFlow?.Scopes != null ? new Dictionary<string, string>(oAuthFlow.Scopes) : null;
Extensions = oAuthFlow?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(oAuthFlow.Extensions) : null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class OpenApiSecurityScheme : IOpenApiSerializable, IOpenApiReferenceable
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiSecurityScheme() {}
public OpenApiSecurityScheme() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiSecurityScheme"/> object
Expand All @@ -91,7 +91,7 @@ public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme)
Scheme = securityScheme?.Scheme ?? Scheme;
BearerFormat = securityScheme?.BearerFormat ?? BearerFormat;
Flows = securityScheme?.Flows != null ? new(securityScheme?.Flows) : null;
OpenIdConnectUrl = securityScheme?.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString) : null;
OpenIdConnectUrl = securityScheme?.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
Extensions = securityScheme?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(securityScheme.Extensions) : null;
UnresolvedReference = securityScheme?.UnresolvedReference ?? UnresolvedReference;
Reference = securityScheme?.Reference != null ? new(securityScheme?.Reference) : null;
Expand All @@ -107,8 +107,8 @@ public void SerializeAsV3(IOpenApiWriter writer)
throw Error.ArgumentNull(nameof(writer));
}

if (Reference != null)

if (Reference != null)
{
Reference.SerializeAsV3(writer);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ public void WriteInlineRecursiveSchemav2()
type: object
properties:
children:
$ref: '#/definitions/thing'
type: object
properties:
children:
$ref: '#/definitions/thing'
related:
type: integer
related:
type: integer";
// Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles.
Expand Down

0 comments on commit 21e91c6

Please sign in to comment.