-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4eaeb5
commit 95dd163
Showing
7 changed files
with
78 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Text; | ||
using GenHTTP.Modules.Reflection.Operations; | ||
using NSwag; | ||
|
||
namespace GenHTTP.Modules.OpenApi.Discovery; | ||
|
||
public static class OpenApiExtensions | ||
{ | ||
|
||
public static bool MightBeNull(this Type type) | ||
{ | ||
if (type.IsClass) | ||
{ | ||
return true; | ||
} | ||
|
||
return Nullable.GetUnderlyingType(type) != null; | ||
} | ||
|
||
public static OpenApiPathItem GetPathItem(OpenApiDocument document, List<string> path, Operation operation) | ||
{ | ||
var stringPath = BuildPath(operation.Path.Name, path); | ||
|
||
if (document.Paths.TryGetValue(stringPath, out var existing)) | ||
{ | ||
return existing; | ||
} | ||
|
||
var newPath = new OpenApiPathItem(); | ||
|
||
document.Paths.Add(stringPath, newPath); | ||
|
||
return newPath; | ||
} | ||
|
||
public static string BuildPath(string name, List<string> pathParts) | ||
{ | ||
var builder = new StringBuilder("/"); | ||
|
||
if (pathParts.Count > 0) | ||
{ | ||
builder.Append(string.Join('/', pathParts)); | ||
builder.Append('/'); | ||
} | ||
|
||
if (name.Length > 0 && name[0] == '/') | ||
{ | ||
builder.Append(name[1..]); | ||
} | ||
else | ||
{ | ||
builder.Append(name); | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters