[Koha-devel] DBIC > Swagger object definition

Tomas Cohen Arazi tomascohen at gmail.com
Thu Jan 5 20:32:26 CET 2017


In the process of writing a script for generating swagger object
definitions our of DBIC schemas (for sort-of scaffolding them making easier
to add REST endpoints) I resumed some talks we had at Marseille, and also
picked some previous work from Lari on automating the Koha::Object <->
Swagger translation.

One thing that would be handy for this process, is to add the column
descriptions to the schema files. This can be accomplished like this
example (for Koha::Schema::Result::BorrowerAttributeType):

+__PACKAGE__->add_columns(
+    "+code" => {
+        koha_description => "Unique key used to identify the attribute
type"
+    },
+    "+description" =>
+        { koha_description => "Description for the attribute type" },
+    "+repeatable" => {
+        koha_description =>
+            "Defines if a patron can have multiple values for the
attribute type"
+    },
+    "+unique_id" => {
+        koha_description => "Defines if the assinged value need to be
unique"
+    },
+    "+opac_display" => {
+        koha_description =>
+            "Defines if the attribute is visible to patrons on their
account in the OPAC or not"
+    },
+    "+opac_editable" => {
+        koha_description =>
+            "Defines if the attribute is editable by patrons on their
account in the OPAC or not"
+    },
+    "+staff_searchable" => {
+        koha_description =>
+            "Defines if the attribute is searchable via the patron search
in the staff client"
+    },
+    "+authorised_value_category" => {
+        koha_description =>
+            "Foreign key from authorised_values that links this attribute
to an authorized value category"
+    },
+    "+display_checkout" => {
+        koha_description =>
+            "Defines if the attribute  is displayed in checkout screens"
+    },
+    "+category_code" => {
+        koha_description =>
+            "Defines a constraint on a patron category for the attribute
type"
+    },
+    "+class" =>
+        { koha_description => "Defines a class for grouping attributes" }
+);

This way we can have really simple access to those descriptions we already
have in kohastructure.sql:

my $columns_info =
Koha::Database->new->schema->resultset('BorrowerAttributeType')
    ->result_source->columns_info;

foreach $key ( keys %{ $columns_info } ) {
    print "Column: $key | Description: " .
$columns_info->{$key}->{koha_description};
}

This could be an easy initial task for academy bugs.

Opinions? We will need this at some point if we would change our workflow
and have DB structure handled by DBIC.

Anyway, I'll send a pull request to Jonathan so he adds this handy (and
perfectible) script to his koha-misc4dev repository. This will make it
available on kohadevbox right out-of-the-box. I'll then try to document it
on Kyle's Koha Developer Handbook, which we all should add our bits of
knowledge!

Looking forward to your feedback!

-- 
Tomás Cohen Arazi
Theke Solutions (https://theke.io <http://theke.io/>)
✆ +54 9351 3513384
GPG: B2F3C15F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20170105/213750e4/attachment.html>


More information about the Koha-devel mailing list