public Dictionary <string, object> GetMeta() { var schema = SchemaGenerator.GenerateFromType <Note>(); using var ms = new MemoryStream(); var writer = new Utf8JsonWriter(ms); var serializerOptions = new JsonSerializerOptions() { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase }; SchemaSerializer.Serialize(schema, writer, serializerOptions); writer.Flush(); ms.Position = 0; using var sr = new StreamReader(ms); var serializedSchema = sr.ReadToEnd(); return(new Dictionary <string, object> { ["schema"] = serializedSchema }); }
public Task ExecuteAsync( ControllerActionDescriptor action, Utf8JsonWriter writer, JsonSerializerOptions options) { var method = action.MethodInfo; var returnType = method.GetCustomAttribute <ReturnsAttribute>()?.ReturnType; if (returnType != null) { var wrapperType = typeof(MicrotypeContainerWrapper <>).MakeGenericType(returnType); var schema = SchemaGenerator.GenerateFromType(wrapperType); SchemaSerializer.Serialize(schema, writer, options); } else { writer.WriteStartObject(); writer.WriteEndObject(); } return(Task.CompletedTask); }