Uh oh!
There was an error while loading. Please reload this page.
How to load an OpenAPI description document with an external schema #2481
Replies: 1 comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I've got it working by patching the OpenAPI description document with a fragment containing the schema usingMicrosoft.OpenApi;usingMicrosoft.OpenApi.Reader;usingSystem.Text.Json.Nodes;namespaceDasfn{internalclassProgram{staticasyncTaskMain(string[]args){UribaseUrl=new("https://www.bcb.gov.br/htms/dasfn/catalogo/1.0.10/");HttpClienthttpClient=new(){BaseAddress=baseUrl,};OpenApiReaderSettingssettings=new(){BaseUrl=baseUrl,HttpClient=httpClient,LoadExternalRefs=true,};(OpenApiDocument?document,OpenApiDiagnostic?diagnostic)=awaitOpenApiDocument.LoadAsync(newUri(baseUrl,"openapi.json").AbsoluteUri,settings);if(diagnostic?.ErrorsisIList<OpenApiError>errors){foreach(OpenApiErrorerrorinerrors){Console.WriteLine(error);}}OpenApiMediaTypemediaType=document!.Paths["/catalogo"].Operations![HttpMethod.Get].Responses!["200"].Content!["application/json"];if(mediaType.SchemaisOpenApiSchemaReferenceschemaReference&&schemaReference.UnresolvedReference){usingMemoryStreamstream=new(awaithttpClient.GetByteArrayAsync(schemaReference.Reference.ExternalResource,CancellationToken.None));mediaType.Schema=settings.Readers["json"].ReadFragment<OpenApiSchema>(stream,diagnostic!.SpecificationVersion,document,outOpenApiDiagnosticschemaDiagnostic);}}}}There's probably a better/proper way to do this, but at least for now this will suffice. |
0 replies
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Given the OpenAPI description document at https://www.bcb.gov.br/htms/dasfn/catalogo/1.0.10/openapi.json referencing the external schema file at https://www.bcb.gov.br/htms/dasfn/catalogo/1.0.10/schema.json, the following code
... reports failure to load schema.json apparently due to it not having a
Versionfield. Furthermore, the schema is marked as an unsolved reference:It is my understanding that
Versionis only required on the OpenAPI description itself and not on referenced schemas.I have no control over the definition of this OpenAPI description document so changing it is not an option.
Is there a proper way or a workaround for loading the external schema?
All reactions