Original indention and text delimiter style retained when rendering #106

Now the original indention is captured and string delimiters are retained when rendering out documents.

Signed-off-by: Dave Shanley <dave@quobix.com>

# fixes 106
This commit is contained in:
Dave Shanley
2023-06-16 09:50:27 -04:00
committed by quobix
parent 5b128c098a
commit e1f0f69650
8 changed files with 172 additions and 52 deletions

View File

@@ -622,3 +622,54 @@ func TestDocument_InputAsJSON(t *testing.T) {
assert.Equal(t, d, strings.TrimSpace(string(rend)))
}
func TestDocument_InputAsJSON_LargeIndent(t *testing.T) {
var d = `{
"openapi": "3.1",
"paths": {
"/an/operation": {
"get": {
"operationId": "thisIsAnOperationId"
}
}
}
}`
doc, err := NewDocumentWithConfiguration([]byte(d), datamodel.NewOpenDocumentConfiguration())
if err != nil {
panic(err)
}
_, _ = doc.BuildV3Model()
// render the document.
rend, _, _, _ := doc.RenderAndReload()
assert.Equal(t, d, strings.TrimSpace(string(rend)))
}
func TestDocument_RenderWithIndention(t *testing.T) {
spec := `openapi: "3.1.0"
info:
title: Test
version: 1.0.0
paths:
/test:
get:
operationId: 'test'`
config := datamodel.NewOpenDocumentConfiguration()
doc, err := NewDocumentWithConfiguration([]byte(spec), config)
if err != nil {
panic(err)
}
_, _ = doc.BuildV3Model()
rend, _, _, _ := doc.RenderAndReload()
assert.Equal(t, spec, strings.TrimSpace(string(rend)))
}