Skip to content

Commit

Permalink
chore: Handle empty contact info.
Browse files Browse the repository at this point in the history
  • Loading branch information
peombwa committed Nov 16, 2023
1 parent 6a4bbf9 commit ee957a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.5.3] - 2023-11-16

### Added

Expand Down
16 changes: 12 additions & 4 deletions src/lib/TypeExtensions/OpenApiDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ public static partial class OpenApiDocumentExtensions
/// <param name="apiDescriptionUrl">The URL of the API description.</param>
/// <param name="applicationName">The name of the application.</param>
/// <param name="apiDependencyName">The name of the API dependency. If not specified, it defaults to the title from the OpenAPI document.</param>
/// <param name="publisherName"> The publisher name of the API manifest. If not supplied, it defaults to the contact name from the OpenAPI document, if available. In the absence of both, 'publisher-name' is used as a fallback.</param>
/// <param name="publisherEmail">The publisher email of the API manifest. If not supplied, it defaults to the contact email from the OpenAPI document, if available.In the absence of both, '[email protected]' is used as a fallback.</param>
/// <param name="publisherName">
/// The publisher's name for the API manifest.
/// If not provided, it defaults to the contact name from the OpenAPI document (if available).
/// If the contact name is also not available, it defaults to 'publisher-name'.
/// </param>
/// <param name="publisherEmail">
/// The publisher's email for the API manifest.
/// If not provided, it defaults to the contact email from the OpenAPI document (if available).
/// If the contact email is also not available, it defaults to '[email protected]'.
/// </param>
/// <returns>An <see cref="ApiManifestDocument"/>.</returns>
public static ApiManifestDocument ToApiManifest(this OpenApiDocument document, string? apiDescriptionUrl, string applicationName, string? apiDependencyName = default, string? publisherName = default, string? publisherEmail = default)
{
Expand All @@ -31,10 +39,10 @@ public static ApiManifestDocument ToApiManifest(this OpenApiDocument document, s
ValidationHelpers.ValidateNullOrWhitespace(nameof(applicationName), applicationName, nameof(ApiManifestDocument));

if (string.IsNullOrEmpty(publisherName))
publisherName = document.Info.Contact?.Name ?? DefaultPublisherName;
publisherName = document.Info.Contact?.Name is string cName && !string.IsNullOrEmpty(cName) ? cName : DefaultPublisherName;

if (string.IsNullOrEmpty(publisherEmail))
publisherEmail = document.Info.Contact?.Email ?? DefaultPublisherEmail;
publisherEmail = document.Info.Contact?.Email is string cEmail && !string.IsNullOrEmpty(cEmail) ? cEmail : DefaultPublisherEmail;

apiDependencyName = NormalizeApiName(string.IsNullOrEmpty(apiDependencyName) ? document.Info.Title : apiDependencyName);
string? apiDeploymentBaseUrl = GetApiDeploymentBaseUrl(document.Servers.FirstOrDefault());
Expand Down
2 changes: 1 addition & 1 deletion src/lib/apimanifest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PackageId>Microsoft.OpenApi.ApiManifest</PackageId>
<VersionPrefix>0.5.2</VersionPrefix>
<VersionPrefix>0.5.3</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageProjectUrl>https://github.com/Microsoft/OpenApi.ApiManifest</PackageProjectUrl>
Expand Down

0 comments on commit ee957a5

Please sign in to comment.