fix: deal with nested complex types
- make sure the definitions object is the same when making recursive calls to generate schema. this way all definitions are captured and can be referenced correctly. - add tests for nested complex types
This commit is contained in:
@@ -68,12 +68,12 @@ static class JsonSchemaGenerator
|
||||
|
||||
private static JsonObject GenerateParameterTypeSchema(Type type, JsonObject inputSchema)
|
||||
{
|
||||
var definitions = inputSchema[DefinitionsKey];
|
||||
var definitions = inputSchema[DefinitionsKey] ?? new JsonObject();
|
||||
|
||||
// Check if a definition for the type already exists
|
||||
// If it does, return a reference to the definition
|
||||
// no need to evaluate the type further
|
||||
if (definitions is not null && definitions.AsObject().ContainsKey(type.FullName))
|
||||
if (definitions.AsObject().ContainsKey(type.FullName))
|
||||
{
|
||||
return new JsonObject()
|
||||
{
|
||||
@@ -150,6 +150,8 @@ static class JsonSchemaGenerator
|
||||
private static JsonObject GenerateTypeDefinitionSchema(Type type, JsonObject inputSchema)
|
||||
{
|
||||
var definitions = inputSchema[DefinitionsKey] ?? new JsonObject();
|
||||
inputSchema[DefinitionsKey] = definitions;
|
||||
|
||||
var typeSchema = new JsonObject()
|
||||
{
|
||||
[TypeKey] = ObjectType
|
||||
|
||||
Reference in New Issue
Block a user