Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 4557e55

Browse files
authored
Remove file preparer and load the assemblies from the path provided (#107)
- Remove file preparer and load the assemblies from the path provided - Remove system.web as its not available in .net core
1 parent 04998c9 commit 4557e55

File tree

5 files changed

+95
-169
lines changed

5 files changed

+95
-169
lines changed

src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// ------------------------------------------------------------
55

66
using System;
7+
using System.Net;
78
using System.Text.RegularExpressions;
8-
using System.Web;
99

1010
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
1111
{
@@ -117,7 +117,7 @@ public static string ToTitleCase(this string value)
117117
/// <returns>The absolute path inside the URL.</returns>
118118
public static string UrlStringToAbsolutePath(this string value)
119119
{
120-
return HttpUtility.UrlDecode(new Uri(value).AbsolutePath);
120+
return WebUtility.UrlDecode(new Uri(value).AbsolutePath);
121121
}
122122
}
123123
}

src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/FilePreparer.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/InternalOpenApiGenerator.cs

Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void AddOperation(
8585
ExceptionType = e.GetType().Name,
8686
Message = e.Message
8787
}
88-
);
88+
);
8989
}
9090
}
9191

@@ -132,7 +132,7 @@ private void AddOperation(
132132
ExceptionType = e.GetType().Name,
133133
Message = e.Message
134134
}
135-
);
135+
);
136136
}
137137
}
138138

@@ -161,7 +161,7 @@ private void AddOperation(
161161
ExceptionType = e.GetType().Name,
162162
Message = e.Message
163163
}
164-
);
164+
);
165165
}
166166
}
167167
}
@@ -276,120 +276,117 @@ IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments
276276

277277
try
278278
{
279-
using (var filePreparer = new FilePreparer())
280-
{
281-
generationDiagnostic = new GenerationDiagnostic();
282-
var documentGenerationDiagnostic = new DocumentGenerationDiagnostic();
279+
generationDiagnostic = new GenerationDiagnostic();
280+
var documentGenerationDiagnostic = new DocumentGenerationDiagnostic();
283281

284-
if (documentVariantElementNames?.Count > 1)
282+
if (documentVariantElementNames?.Count > 1)
283+
{
284+
documentGenerationDiagnostic.Errors.Add(new GenerationError
285285
{
286-
documentGenerationDiagnostic.Errors.Add(new GenerationError
287-
{
288-
Message = string.Format(
289-
SpecificationGenerationMessages.MoreThanOneVariantNameNotAllowed,
290-
documentVariantElementNames.First())
291-
});
292-
}
286+
Message = string.Format(
287+
SpecificationGenerationMessages.MoreThanOneVariantNameNotAllowed,
288+
documentVariantElementNames.First())
289+
});
290+
}
293291

294-
var typeFetcher = new TypeFetcher(filePreparer.CopyFileToPrivateBin(contractAssemblyPaths));
292+
var typeFetcher = new TypeFetcher(contractAssemblyPaths);
295293

296-
var operationGenerationDiagnostics = GenerateSpecificationDocuments(
297-
typeFetcher,
298-
operationElements,
299-
operationConfigElement,
300-
documentVariantElementNames.FirstOrDefault(),
301-
out var documents);
294+
var operationGenerationDiagnostics = GenerateSpecificationDocuments(
295+
typeFetcher,
296+
operationElements,
297+
operationConfigElement,
298+
documentVariantElementNames.FirstOrDefault(),
299+
out var documents);
302300

303-
foreach (var operationGenerationDiagnostic in operationGenerationDiagnostics)
304-
{
305-
generationDiagnostic.OperationGenerationDiagnostics.Add(
306-
new OperationGenerationDiagnostic(operationGenerationDiagnostic));
307-
}
301+
foreach (var operationGenerationDiagnostic in operationGenerationDiagnostics)
302+
{
303+
generationDiagnostic.OperationGenerationDiagnostics.Add(
304+
new OperationGenerationDiagnostic(operationGenerationDiagnostic));
305+
}
308306

309-
foreach (var variantInfoDocumentValuePair in documents)
310-
{
311-
var openApiDocument = variantInfoDocumentValuePair.Value;
307+
foreach (var variantInfoDocumentValuePair in documents)
308+
{
309+
var openApiDocument = variantInfoDocumentValuePair.Value;
312310

313-
foreach (var documentFilter in _documentFilters)
311+
foreach (var documentFilter in _documentFilters)
312+
{
313+
try
314314
{
315-
try
316-
{
317-
documentFilter.Apply(
318-
openApiDocument,
319-
annotationXmlDocuments,
320-
new DocumentFilterSettings
321-
{
322-
TypeFetcher = typeFetcher,
323-
OpenApiDocumentVersion = openApiDocumentVersion
324-
});
325-
}
326-
catch (Exception e)
327-
{
328-
documentGenerationDiagnostic.Errors.Add(
329-
new GenerationError
330-
{
331-
ExceptionType = e.GetType().Name,
332-
Message = e.Message
333-
});
334-
}
315+
documentFilter.Apply(
316+
openApiDocument,
317+
annotationXmlDocuments,
318+
new DocumentFilterSettings
319+
{
320+
TypeFetcher = typeFetcher,
321+
OpenApiDocumentVersion = openApiDocumentVersion
322+
});
335323
}
336-
337-
foreach (var filter in _postProcessingDocumentFilters)
324+
catch (Exception e)
338325
{
339-
filter.Apply(
340-
openApiDocument,
341-
new PostProcessingDocumentFilterSettings()
326+
documentGenerationDiagnostic.Errors.Add(
327+
new GenerationError
342328
{
343-
OperationGenerationDiagnostics = operationGenerationDiagnostics
329+
ExceptionType = e.GetType().Name,
330+
Message = e.Message
344331
});
345332
}
346333
}
347334

348-
if (documentConfigElement != null)
335+
foreach (var filter in _postProcessingDocumentFilters)
349336
{
350-
foreach (var documentConfigFilter in _documentConfigFilters)
351-
{
352-
try
337+
filter.Apply(
338+
openApiDocument,
339+
new PostProcessingDocumentFilterSettings()
353340
{
354-
documentConfigFilter.Apply(
355-
documents,
356-
documentConfigElement,
357-
annotationXmlDocuments,
358-
new DocumentConfigFilterSettings());
359-
}
360-
catch (Exception e)
361-
{
362-
documentGenerationDiagnostic.Errors.Add(
363-
new GenerationError
364-
{
365-
ExceptionType = e.GetType().Name,
366-
Message = e.Message
367-
});
368-
}
369-
}
341+
OperationGenerationDiagnostics = operationGenerationDiagnostics
342+
});
370343
}
344+
}
371345

372-
var failedOperations = generationDiagnostic.OperationGenerationDiagnostics
373-
.Where(i => i.Errors.Count > 0);
374-
375-
if (failedOperations.Any())
346+
if (documentConfigElement != null)
347+
{
348+
foreach (var documentConfigFilter in _documentConfigFilters)
376349
{
377-
var totalOperationsCount = generationDiagnostic.OperationGenerationDiagnostics.Count();
350+
try
351+
{
352+
documentConfigFilter.Apply(
353+
documents,
354+
documentConfigElement,
355+
annotationXmlDocuments,
356+
new DocumentConfigFilterSettings());
357+
}
358+
catch (Exception e)
359+
{
360+
documentGenerationDiagnostic.Errors.Add(
361+
new GenerationError
362+
{
363+
ExceptionType = e.GetType().Name,
364+
Message = e.Message
365+
});
366+
}
367+
}
368+
}
378369

379-
var exception = new UnableToGenerateAllOperationsException(
380-
totalOperationsCount - failedOperations.Count(), totalOperationsCount);
370+
var failedOperations = generationDiagnostic.OperationGenerationDiagnostics
371+
.Where(i => i.Errors.Count > 0);
381372

382-
documentGenerationDiagnostic.Errors.Add(
383-
new GenerationError
384-
{
385-
ExceptionType = exception.GetType().Name,
386-
Message = exception.Message
387-
});
388-
}
373+
if (failedOperations.Any())
374+
{
375+
var totalOperationsCount = generationDiagnostic.OperationGenerationDiagnostics.Count();
376+
377+
var exception = new UnableToGenerateAllOperationsException(
378+
totalOperationsCount - failedOperations.Count(), totalOperationsCount);
389379

390-
generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic;
391-
return documents;
380+
documentGenerationDiagnostic.Errors.Add(
381+
new GenerationError
382+
{
383+
ExceptionType = exception.GetType().Name,
384+
Message = exception.Message
385+
});
392386
}
387+
388+
generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic;
389+
return documents;
393390
}
394391
catch (Exception e)
395392
{

src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Company>Microsoft</Company>
1010
<Title>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</Title>
1111
<PackageId>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</PackageId>
12-
<Version>1.0.0-beta025</Version>
12+
<Version>1.0.0-beta026</Version>
1313
<Description>Library that translates Visual Studio C# Annotations into .NET objects representing OpenAPI specification.</Description>
1414
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1515
<PackageTags>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</PackageTags>
@@ -27,8 +27,4 @@
2727
<PackageReference Include="Microsoft.OpenApi" Version="1.0.0-beta016" />
2828
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.0.0-beta016" />
2929
</ItemGroup>
30-
31-
<ItemGroup>
32-
<Reference Include="System.Web" />
33-
</ItemGroup>
3430
</Project>

src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/OperationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
using System;
77
using System.Linq;
8+
using System.Net;
89
using System.Text;
910
using System.Text.RegularExpressions;
10-
using System.Web;
1111
using System.Xml.Linq;
1212
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
1313
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
@@ -103,7 +103,7 @@ public static string GetUrl(
103103

104104
try
105105
{
106-
url = HttpUtility.UrlDecode(new Uri(url).AbsolutePath);
106+
url = WebUtility.UrlDecode(new Uri(url).AbsolutePath);
107107
}
108108
catch (UriFormatException)
109109
{

0 commit comments

Comments
 (0)