mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Tackled the boss, schemas! now mutable.
A tricky one, because of the complexity, still working through edge cases and variations, but so far, operating correctly!
This commit is contained in:
@@ -257,6 +257,11 @@ unevaluatedProperties:
|
||||
|
||||
wentLow := compiled.GoLow()
|
||||
assert.Equal(t, 114, wentLow.AdditionalProperties.ValueNode.Line)
|
||||
|
||||
// now render it out!
|
||||
schemaBytes, _ := compiled.Render()
|
||||
assert.Equal(t, testSpec, string(schemaBytes))
|
||||
|
||||
}
|
||||
|
||||
func TestSchemaObjectWithAllOfSequenceOrder(t *testing.T) {
|
||||
@@ -701,3 +706,114 @@ properties:
|
||||
type: number
|
||||
`
|
||||
}
|
||||
|
||||
func TestNewSchemaProxy_RenderSchema(t *testing.T) {
|
||||
testSpec := `type: object
|
||||
description: something object
|
||||
discriminator:
|
||||
propertyName: athing
|
||||
mapping:
|
||||
log: cat
|
||||
pizza: party
|
||||
allOf:
|
||||
- type: object
|
||||
description: an allof thing
|
||||
properties:
|
||||
allOfA:
|
||||
type: string
|
||||
description: allOfA description
|
||||
example: allOfAExp
|
||||
allOfB:
|
||||
type: string
|
||||
description: allOfB description
|
||||
example: allOfBExp
|
||||
`
|
||||
|
||||
var compNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(testSpec), &compNode)
|
||||
|
||||
sp := new(lowbase.SchemaProxy)
|
||||
err := sp.Build(compNode.Content[0], nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lowproxy := low.NodeReference[*lowbase.SchemaProxy]{
|
||||
Value: sp,
|
||||
ValueNode: compNode.Content[0],
|
||||
}
|
||||
|
||||
schemaProxy := NewSchemaProxy(&lowproxy)
|
||||
compiled := schemaProxy.Schema()
|
||||
|
||||
assert.Equal(t, schemaProxy, compiled.ParentProxy)
|
||||
|
||||
assert.NotNil(t, compiled)
|
||||
assert.Nil(t, schemaProxy.GetBuildError())
|
||||
|
||||
// now render it out, it should be identical.
|
||||
schemaBytes, _ := compiled.Render()
|
||||
assert.Equal(t, testSpec, string(schemaBytes))
|
||||
|
||||
}
|
||||
|
||||
func TestNewSchemaProxy_RenderSchemaWithMultipleObjectTypes(t *testing.T) {
|
||||
testSpec := `type: object
|
||||
description: something object
|
||||
oneOf:
|
||||
- type: object
|
||||
description: a oneof thing
|
||||
properties:
|
||||
oneOfA:
|
||||
type: string
|
||||
example: oneOfAExp
|
||||
anyOf:
|
||||
- type: object
|
||||
description: an anyOf thing
|
||||
properties:
|
||||
anyOfA:
|
||||
type: string
|
||||
example: anyOfAExp
|
||||
not:
|
||||
type: object
|
||||
description: a not thing
|
||||
properties:
|
||||
notA:
|
||||
type: string
|
||||
example: notAExp
|
||||
items:
|
||||
type: object
|
||||
description: an items thing
|
||||
properties:
|
||||
itemsA:
|
||||
type: string
|
||||
description: itemsA description
|
||||
example: itemsAExp
|
||||
itemsB:
|
||||
type: string
|
||||
description: itemsB description
|
||||
example: itemsBExp
|
||||
`
|
||||
|
||||
var compNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(testSpec), &compNode)
|
||||
|
||||
sp := new(lowbase.SchemaProxy)
|
||||
err := sp.Build(compNode.Content[0], nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lowproxy := low.NodeReference[*lowbase.SchemaProxy]{
|
||||
Value: sp,
|
||||
ValueNode: compNode.Content[0],
|
||||
}
|
||||
|
||||
schemaProxy := NewSchemaProxy(&lowproxy)
|
||||
compiled := schemaProxy.Schema()
|
||||
|
||||
assert.Equal(t, schemaProxy, compiled.ParentProxy)
|
||||
|
||||
assert.NotNil(t, compiled)
|
||||
assert.Nil(t, schemaProxy.GetBuildError())
|
||||
|
||||
// now render it out, it should be identical.
|
||||
schemaBytes, _ := compiled.Render()
|
||||
assert.Equal(t, testSpec, string(schemaBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user