Types

Anatomy of a type µSpec #

The µType specs are regular yaml files.

The “type-object” contains 3 fields. The fields type, fields are mandatory, the field target is optional and autogenerated when ommited.

You can have as many type definitions per file as you want. It makes sense that you put types in a file, that belongs togehter.

File: muspec/sample.types.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
- type: 'sample.Sample #A sample type'
  fields:
    password: '* string:1 #The password.'
    username: '* string:2 #The username or email, or something to identify.'
    details: 'sample.Details:3 #Details.'
  target: sample.proto # this is "optional", if you omit this, Furo will use the package name (auth)

- type: 'sample.Details #A sample type'
  fields:
    birth_date: '* google.type.Date:1 #The birth date.'
    weight: '* number:2 #The weight.'    
    age: '- number:3 #Calculated field for displaying the age, because the calculations are very hard.'
  target: sample.proto 

The type line #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
- type: 'sample.Sample  #A sample type'
  !___!  !____||_____!  !____________!
    |       |     |          |
    |       |   type name    |
    |    package             |
    |                    description (recomended) begins with a #
    |                  
    | 
    | 
field name of the type


It is a good practice to give a good description of the type.

Fields #

In the “fields-object”, what a surprise, you define the fields / attributes of a type.

minimalistic example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
fieldname: '* string:2 #The description.'
!_______!  !_!!____!!_!!________________!
    |       |    |   |          |  
    |       |    |   |  description (recomended) begins with a #
 field name |    |   |   
            |    |  field id, indicated by a :   
            |    |  
            |   type  
            |     
       Indicator for required (*), readonly (-), repeated ([])

example with default value and oneof

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fieldname: '* string:2 = default value [oneofname] #The description.'
!_______!  !_!!____!!_!!______________!!__________!!________________!
    |       |    |   |          |            |              |   
    |       |    |   |          |   oneof definition in []  |
    |       |    |   |    default value (=)                 |
    |       |    |   |                                      |
    |       |    |   |        description (recomended) begins with a #
 field name |    |   |   
            |    |  field id, indicated by a :   
            |    |  
            |   type  
            |     
       Indicator for required (*), readonly (-), repeated ([])

Fieldname #

The name of the field

Indicator for required #

If the field is required, type in a *

Indicator for readonly #

If the field is readonly, type in a -

Indicator for repeated #

If the field is repeated, type in a []

Type #

Types are the same like in protobuf

Field id #

The field id must be unique, the generated protos use them too

Default value #

This does not reflect in the protos.

Oneof definition #

Description #

It is a good practice to give a good description of the type. This description will go to the generated protos and other generates.