Repository navigation
Expand file tree
/
Copy pathExampleTests.cs
More file actions
65 lines (54 loc) · 1.84 KB
/
Copy pathExampleTests.cs
File metadata and controls
65 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.OpenApi;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Writers;
using SharpYaml.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
namespace OpenApi.Tests
{
public class ExampleTests
{
[Fact] //Temporarily disabled until I create a JsonPointer
public void WriteResponseExample()
{
var doc = new OpenApiDocument
{
Info = new OpenApiInfo()
{
Title = "test",
Version = new Version(1, 0)
}
};
doc.CreatePath("/test",
p => p.CreateOperation(OperationType.Get,
o => o.CreateResponse("200", r =>
{
r.Description = "foo";
r.CreateContent("application/json", c =>
{
c.Example = "xyz"; ///"{ \"foo\": \"bar\" }"; This doesn't work because parser treats it as a node
});
})));
var stream = new MemoryStream();
doc.Save(stream);
stream.Position = 0;
var yamlStream = new YamlStream();
yamlStream.Load(new StreamReader(stream));
var yamlDocument = yamlStream.Documents.First();
var rootNode = new RootNode(new ParsingContext(), yamlDocument);
var node = rootNode.Find(new JsonPointer("/paths/~1test/get/responses/200/content/application~1json/example"));
string example = node.GetScalarValue();
Assert.Equal("xyz", example);
}
}
public static class YamlExtensions
{
public static YamlMappingNode AsMap(this YamlNode node)
{
return node as YamlMappingNode;
}
}
}