11using System ;
22using System . Collections . Generic ;
3- using System . Collections . Immutable ;
43using System . Diagnostics ;
54using System . IO ;
65using System . Linq ;
76using System . Net . Http ;
87using System . Text . Json ;
98using Corvus . Json ;
10- using Corvus . Json . SourceGeneratorTools ;
119using Microsoft . CodeAnalysis ;
1210using Microsoft . CodeAnalysis . Text ;
1311using Microsoft . OpenApi ;
@@ -31,35 +29,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3129
3230 var openapiDocumentProvider = provider . Select ( ( array , _ ) => array . First ( ) ) ;
3331
34- // Get global options
35- var globalOptions =
36- context . AnalyzerConfigOptionsProvider . Select ( ( optionsProvider , token ) =>
37- new SourceGeneratorHelpers . GlobalOptions (
38- fallbackVocabulary : Corvus . Json . CodeGeneration . Draft4 . VocabularyAnalyser . DefaultVocabulary ,
39- optionalAsNullable : true ,
40- useOptionalNameHeuristics : true ,
41- alwaysAssertFormat : true ,
42- ImmutableArray < string > . Empty ) ) ;
43-
44- var openApiProvider = globalOptions
45- . Combine ( openapiDocumentProvider )
32+ var openApiProvider = openapiDocumentProvider
4633 . Combine ( context . CompilationProvider )
4734 . Select ( ( tuple , _ ) => (
48- Options : tuple . Left . Left ,
49- OpenApiDocument : tuple . Left . Right ,
35+ OpenApiDocument : tuple . Left ,
5036 Compilation : tuple . Right
5137 ) ) ;
5238
5339 context . RegisterSourceOutput ( openApiProvider ,
54- WithExceptionReporting < ( SourceGeneratorHelpers . GlobalOptions , AdditionalText , Compilation ) > ( GenerateCode ) ) ;
40+ WithExceptionReporting < ( AdditionalText , Compilation ) > ( GenerateCode ) ) ;
5541 }
5642
5743 private static void GenerateCode ( SourceProductionContext context , (
58- SourceGeneratorHelpers . GlobalOptions Options ,
5944 AdditionalText OpenApiDocument ,
6045 Compilation Compilation ) generatorContext )
6146 {
62- var globalOptions = generatorContext . Options ;
6347 var compilation = generatorContext . Compilation ;
6448 var rootNamespace = compilation . Assembly . Name ;
6549
@@ -82,18 +66,19 @@ private static void GenerateCode(SourceProductionContext context, (
8266 throw new InvalidOperationException (
8367 $ "Could not load OpenAPI document { openApiDocumentFile . Path } ") ;
8468
69+
8570 var openApiUri = new JsonReference ( openApi . BaseUri . ToString ( ) ) ;
8671 var documentResolver = new PrepopulatedDocumentResolver ( ) ;
8772 var openApiDocument = JsonDocument . Parse ( generatorContext . OpenApiDocument . AsStream ( ) ) ;
8873 if ( ! documentResolver . AddDocument ( openApiUri , openApiDocument ) )
8974 {
9075 throw new InvalidOperationException ( "Could not add OpenApi document" ) ;
9176 }
92- var generationContext = new SourceGeneratorHelpers . GenerationContext ( documentResolver , globalOptions ) ;
93- var schemaGenerator = new SchemaGenerator (
94- rootNamespace ,
95- context ,
96- generationContext ) ;
77+ var schemaGenerator = SchemaGenerator . For (
78+ openApiVersion ,
79+ documentResolver ,
80+ rootNamespace ,
81+ context ) ;
9782
9883 var openApiReference = new OpenApiReference < OpenApiDocument > ( openApi , openApiDocument , openApiUri ) ;
9984 var openApiVisitor = OpenApiVisitor . V ( openApiVersion , openApiReference ) ;
0 commit comments