diff --git a/mlf-codegen/src/lib.rs b/mlf-codegen/src/lib.rs index 192e5e9..6c2aff8 100644 --- a/mlf-codegen/src/lib.rs +++ b/mlf-codegen/src/lib.rs @@ -586,7 +586,14 @@ fn generate_subscription_json( } fn generate_def_type_json(def_type: &DefType, usage_counts: &HashMap, workspace: &Workspace, current_namespace: &str) -> Value { - generate_type_json(&def_type.ty, usage_counts, workspace, current_namespace) + let mut field_json = generate_type_json(&def_type.ty, usage_counts, workspace, current_namespace); + // Add description if the type definition has doc comments + if !def_type.docs.is_empty() { + if let Some(obj) = field_json.as_object_mut() { + obj.shift_insert(1, "description".to_string(), json!(extract_docs(&def_type.docs))); + } + } + field_json } fn generate_type_json(ty: &Type, usage_counts: &HashMap, workspace: &Workspace, current_namespace: &str) -> Value { diff --git a/tests/codegen/lexicon/doc_comments/expected.json b/tests/codegen/lexicon/doc_comments/expected.json new file mode 100644 index 0000000..676c8c4 --- /dev/null +++ b/tests/codegen/lexicon/doc_comments/expected.json @@ -0,0 +1,30 @@ +{ + "$type": "com.atproto.lexicon.schema", + "lexicon": 1, + "id": "com.example.thread", + "defs": { + "main": { + "type": "record", + "description": "A forum thread", + "key": "tid", + "record": { + "type": "object", + "required": [ + "title" + ], + "properties": { + "title": { + "type": "ref", + "ref": "#title" + } + } + } + }, + "title": { + "type": "string", + "description": "Thread title", + "maxLength": 200, + "minLength": 1 + } + } +} diff --git a/tests/codegen/lexicon/doc_comments/input.mlf b/tests/codegen/lexicon/doc_comments/input.mlf new file mode 100644 index 0000000..8ca195b --- /dev/null +++ b/tests/codegen/lexicon/doc_comments/input.mlf @@ -0,0 +1,10 @@ +/// A forum thread +record thread { + title!: title, +} + +/// Thread title +def type title = string constrained { + maxLength: 200, + minLength: 1, +}; diff --git a/tests/codegen/lexicon/doc_comments/test.toml b/tests/codegen/lexicon/doc_comments/test.toml new file mode 100644 index 0000000..68ec5ce --- /dev/null +++ b/tests/codegen/lexicon/doc_comments/test.toml @@ -0,0 +1,4 @@ +[test] +name = "doc_comments" +description = "Test doc comments for defs" +namespace = "com.example.thread"