Skip to content

Commit 36f2c01

Browse files
committed
add reveal solution option
1 parent 7afe194 commit 36f2c01

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

LearnJsonEverything/Services/LessonData.cs

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public class LessonData
1919
public JsonArray Tests { get; set; }
2020
public bool Achieved { get; set; }
2121
public string? UserCode { get; set; }
22+
public string Solution { get; set; }
2223
}

LearnJsonEverything/Shared/Teacher.razor

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<div class="d-flex">
4747
<button class="btn btn-primary m-1" disabled="@_previousButtonDisabled" @onclick="PreviousLesson">&lt; Previous</button>
4848
<button class="btn btn-primary m-1" @onclick="Run">Run</button>
49+
<button class="btn btn-primary m-1" @onclick="RevealSolution">Reveal Solution</button>
4950
<button class="btn btn-primary m-1" disabled="@_nextButtonDisabled" @onclick="NextLesson">Next &gt;</button>
5051
</div>
5152
</div>
@@ -100,6 +101,11 @@
100101
}
101102
}
102103

104+
private Task RevealSolution()
105+
{
106+
return _codeEditor.SetValue(_currentLesson?.Solution ?? string.Empty);
107+
}
108+
103109
private Task PreviousLesson()
104110
{
105111
_currentLesson = _lessons.GetPrevious(_currentLesson?.Id);

LearnJsonEverything/wwwroot/data/lessons/schema.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
return schema.Evaluate(instance);
4141
}
4242
}
43+
solution: |-
44+
var schema = JsonSerializer.Deserialize<JsonSchema>(schemaText);
4345
tests:
4446
- instance: { "foo": 13, "bar": "a string" }
4547
isValid: true
@@ -54,7 +56,7 @@
5456
- instance: 6.8
5557
isValid: false
5658
- id: 26b6ebca-58e6-4824-86ea-4946d844c9a8
57-
skip: true
59+
skip: true # source gen is not available in dynamic compilation
5860
background: |
5961
JSON Schema is typically itself represented in JSON. To support this, the `JsonSchema`
6062
type is completely compatible with the _System.Text.Json_ serializer.
@@ -102,6 +104,10 @@
102104
}
103105
104106
/* USER CODE */
107+
solution: |-
108+
[JsonSerializable(typeof(JsonSchema))]
109+
[JsonSerializable(typeof(EvaluationResults))]
110+
internal partial class MySerializerContext : JsonSerializerContext;
105111
tests:
106112
- instance: { "foo": 13, "bar": "a string" }
107113
isValid: true
@@ -148,6 +154,8 @@
148154
return schema.Evaluate(instance);
149155
}
150156
}
157+
solution: |-
158+
builder.Type(SchemaValueType.String);
151159
tests:
152160
- instance: a string value
153161
isValid: true
@@ -191,6 +199,10 @@
191199
return schema.Evaluate(instance);
192200
}
193201
}
202+
solution: |-
203+
builder.Type(SchemaValueType.String)
204+
.ExclusiveMinimum(0)
205+
.Maximum(10);
194206
tests:
195207
- instance: 6.8
196208
isValid: true
@@ -250,6 +262,10 @@
250262
return schema.Evaluate(instance);
251263
}
252264
}
265+
solution: |-
266+
builder.Type(SchemaValueType.Array)
267+
.Items(new JsonSchemaBuilder().Type(SchemaValueType.Integer))
268+
.MaxItems(5);
253269
tests:
254270
- instance: 6.8
255271
isValid: false
@@ -305,6 +321,8 @@
305321
return schema.Evaluate(instance, options);
306322
}
307323
}
324+
solution: |-
325+
options.RequireFormatValidation = true;
308326
tests:
309327
- instance: 2015-06-13T10:31:16+04:00
310328
format: date-time
@@ -409,6 +427,8 @@
409427
return schema.Evaluate(instance, options);
410428
}
411429
}
430+
solution: |-
431+
var options = new EvaluationOptions { EvaluateAs = specVersion };
412432
tests:
413433
- instance: [{},4]
414434
version: Draft6

0 commit comments

Comments
 (0)