Changeset 466 for TFP-WebServer/WebServer/src/WebAPI/OpenApiHelpers.cs
- Timestamp:
- Aug 17, 2023, 5:49:38 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/src/WebAPI/OpenApiHelpers.cs
r465 r466 1 using System; 1 2 using System.Collections.Generic; 2 3 using System.IO; … … 79 80 80 81 public void LoadOpenApiSpec (AbsWebAPI _api) { 81 Assembly apiAssembly = _api.GetType ().Assembly; 82 string apiName = _api.Name; 83 string apiSpecName = $"{apiName}.openapi.yaml"; 84 85 string specText = ResourceHelpers.GetManifestResourceText (apiAssembly, apiSpecName, true); 82 loadOpenApiSpec (_api.GetType ().Assembly, _api.Name, null); 83 } 84 85 public void LoadOpenApiSpec (AbsHandler _pathHandler) { 86 Type type = _pathHandler.GetType (); 87 loadOpenApiSpec (type.Assembly, type.Name, _pathHandler.UrlBasePath); 88 } 89 90 public void RegisterCustomSpec (Assembly _assembly, string _apiSpecName, string _replaceBasePath = null) { 91 loadOpenApiSpec (_assembly, _apiSpecName, _replaceBasePath); 92 } 93 94 private void loadOpenApiSpec (Assembly _containingAssembly, string _apiName, string _basePath) { 95 string apiSpecName = $"{_apiName}.openapi.yaml"; 96 97 string specText = ResourceHelpers.GetManifestResourceText (_containingAssembly, apiSpecName, true); 86 98 if (specText == null) { 87 99 return; 88 100 } 89 101 90 // Log.Out ($"[Web] Loaded OpenAPI spec for '{apiName}'"); 91 OpenApiSpec spec = new OpenApiSpec (specText, findExportedPaths (specText)); 92 specs.Add (apiSpecName, spec); 93 } 94 95 public void LoadOpenApiSpec (AbsHandler _pathHandler) { 96 Assembly apiAssembly = _pathHandler.GetType ().Assembly; 97 string apiName = _pathHandler.GetType ().Name; 98 string apiSpecName = $"{apiName}.openapi.yaml"; 99 100 string specText = ResourceHelpers.GetManifestResourceText (apiAssembly, apiSpecName, true); 101 if (specText == null) { 102 return; 103 } 104 105 // Log.Out ($"[Web] Loaded OpenAPI spec for '{apiName}'"); 106 OpenApiSpec spec = new OpenApiSpec (specText, findExportedPaths (specText, _pathHandler.UrlBasePath)); 107 specs.Add (apiSpecName, spec); 108 } 109 110 public void RegisterCustomSpec (Assembly _assembly, string _apiSpecName, string _replaceBasePath = null) { 111 string apiSpecName = $"{_apiSpecName}.openapi.yaml"; 112 113 string specText = ResourceHelpers.GetManifestResourceText (_assembly, apiSpecName, true); 114 if (specText == null) { 115 return; 116 } 117 118 // Log.Out ($"[Web] Loaded OpenAPI spec for '{_apiSpecName}'"); 119 OpenApiSpec spec = new OpenApiSpec (specText, findExportedPaths (specText, _replaceBasePath)); 102 // Log.Out ($"[Web] Loaded OpenAPI spec for '{_apiName}'"); 103 OpenApiSpec spec = new OpenApiSpec (specText, findExportedPaths (specText, _basePath)); 120 104 specs.Add (apiSpecName, spec); 121 105 }
Note:
See TracChangeset
for help on using the changeset viewer.