private async Task WriteJson(HttpResponse response, Models.OpenRpc document) { response.StatusCode = 200; response.ContentType = "application/json;charset=utf-8"; var json = JsonConvert.SerializeObject(document, OpenRpcConstants.JsonSerializerSettings); await response.WriteAsync(json, new UTF8Encoding(false)); }
/// <summary> /// Magic required to create $ref values with correct path /// </summary> /// <param name="document"></param> private void SetSchemas(Models.OpenRpc document) { document.Components.Schemas = contentDescriptorGenerator.GetDefinitions(); foreach (var schema in document.Components.Schemas) { // this is used to determine $ref path // TODO document or document.Components? both work... schema.Value.Parent = document; } // this actually creates $ref values JsonSchemaReferenceUtilities.UpdateSchemaReferencePaths(document, false, OpenRpcConstants.JsonSerializerSettings.ContractResolver); }
public Models.OpenRpc GetDocument(OpenApiInfo info, string documentName, Uri host) { var defaultRoute = jsonRpcOptions.DefaultMethodOptions.Route; var document = new Models.OpenRpc { Openrpc = OpenRpcConstants.SpecVersion, Info = info, Servers = GetServers(host, defaultRoute), Methods = GetMethods(documentName, host, defaultRoute), Components = new Components(), }; SetSchemas(document); return(document); }