describeOutput method

  1. @override
SchemaType describeOutput(
  1. DogEngine engine,
  2. SchemaConfig config
)
override

Generates a SchemaType describing the output generated by this converter.

NOTE: Do not return a shared instance of SchemaType as it will be modified by the visitor. For such cases, use SchemaType.clone to create a new instance.

Implementation

@override
SchemaType describeOutput(DogEngine engine, SchemaConfig config) {
  final pass = SchemaPass.current!;

  final structure = struct!;
  if (structure.isSynthetic) return SchemaType.any;
  if (config.useReferences && pass.depth >= 1) {
    return SchemaReference(structure.serialName);
  }

  pass.depth++;
  final fields = structure.fields.map((e) {
    final converter = engine.getTreeConverter(e.type);
    final type = converter.describeOutput(engine, config);
    type.nullable = e.optional;

    final schemaField = SchemaField(e.name, type);
    e.annotationsOf<SchemaFieldVisitor>().forEach((visitor) {
      visitor.visitSchemaField(schemaField);
    });
    return schemaField;
  }).toList();
  pass.depth--;

  final object = SchemaObject(fields: fields);
  object[SchemaProperties.serialName] = structure.serialName;
  return object;
}