Repository: nf-core/tools

Issue:
Schema: Lint for mimetype
Check that `params.input` has a `mimetype` set and trigger warning if missing.

[Example](https://github.com/nf-core/tools/blob/171127bd850040e76febd0945e6980b7afcaad69/nf_core/pipeline-template/nextflow_schema.json#L18): `"mimetype": "text/csv",`

Would be nice to link to a list of commonly used mimetypes in the docstring docs for lint tests.


Discussion:

Resolving patch:
diff --git a/nf_core/lint/schema_lint.py b/nf_core/lint/schema_lint.py
--- a/nf_core/lint/schema_lint.py
+++ b/nf_core/lint/schema_lint.py
@@ -37,6 +37,7 @@ def schema_lint(self):
         * ``$id``: URL to the raw schema file, eg. ``https://raw.githubusercontent.com/YOURPIPELINE/master/nextflow_schema.json``
         * ``title``: ``YOURPIPELINE pipeline parameters``
         * ``description``: The pipeline config ``manifest.description``
+    * That the ``input`` property is defined and has a mimetype. A list of common mimetypes can be found `here <https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types>`_.
 
     For example, an *extremely* minimal schema could look like this:
 
@@ -88,4 +89,15 @@ def schema_lint(self):
         except AssertionError as e:
             warned.append(str(e))
 
+    # Check for mimetype in the 'input' parameter, warn if missing
+    if self.schema_obj.schema is not None:
+        try:
+            has_valid_mimetype = self.schema_obj.check_for_input_mimetype()
+            if has_valid_mimetype is not None:
+                passed.append(f"Input mimetype lint passed: '{has_valid_mimetype}'")
+            else:
+                warned.append("Input mimetype is missing or empty")
+        except LookupError as e:
+            warned.append(str(e))
+
     return {"passed": passed, "warned": warned, "failed": failed}
diff --git a/nf_core/schema.py b/nf_core/schema.py
--- a/nf_core/schema.py
+++ b/nf_core/schema.py
@@ -413,6 +413,33 @@ def validate_schema_title_description(self, schema=None):
                 self.schema["description"] == desc_attr
             ), f"Schema 'description' should be '{desc_attr}'\n Found: '{self.schema['description']}'"
 
+    def check_for_input_mimetype(self):
+        """
+        Check that the input parameter has a mimetype
+
+        Common mime types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
+
+        Returns:
+            mimetype (str): The mimetype of the input parameter
+
+        Raises:
+            LookupError: If the input parameter is not found or defined in the correct place
+        """
+
+        # Check that the input parameter is defined
+        if "input" not in self.schema_params:
+            raise LookupError(f"Parameter `input` not found in schema")
+        # Check that the input parameter is defined in the right place
+        if "input" not in self.schema.get("definitions", {}).get("input_output_options", {}).get("properties", {}):
+            raise LookupError(f"Parameter `input` is not defined in the correct subschema (input_output_options)")
+        input_entry = self.schema["definitions"]["input_output_options"]["properties"]["input"]
+        if "mimetype" not in input_entry:
+            return None
+        mimetype = input_entry["mimetype"]
+        if mimetype == "" or mimetype is None:
+            return None
+        return mimetype
+
     def print_documentation(
         self,
         output_fn=None,


Test patch: