Comparison between Goa v1 vs. v3 about the design primitive types
Tags: go, goadesign
Published: 2019-10-11 08:02:07

---
title: Comparison between Goa v1 vs. v3 about the design primitive types
published: true
description: 
tags: #go #goadesign
---

Goa v3 changed the primitive types used to design from v1. This article compares v1 and v3 primitive types with Swagger data types.

## Primitive types of v1 

Source: [https://godoc.org/gopkg.in/goadesign/goa.v1/design#pkg-constants](https://godoc.org/gopkg.in/goadesign/goa.v1/design#pkg-constants)

```go
const (
    // Boolean is the type for a JSON boolean.
    Boolean = Primitive(BooleanKind)

    // Integer is the type for a JSON number without a fraction or exponent part.
    Integer = Primitive(IntegerKind)

    // Number is the type for any JSON number, including integers.
    Number = Primitive(NumberKind)

    // String is the type for a JSON string.
    String = Primitive(StringKind)

    // DateTime is the type for a JSON string parsed as a Go time.Time
    // DateTime expects an RFC3339 formatted value.
    DateTime = Primitive(DateTimeKind)

    // UUID is the type for a JSON string parsed as a Go uuid.UUID
    // UUID expects an RFC4122 formatted value.
    UUID = Primitive(UUIDKind)

    // Any is the type for an arbitrary JSON value (interface{} in Go).
    Any = Primitive(AnyKind)

    // File is the type for a file. This type can only be used in a multipart definition.
    File = Primitive(FileKind)
)
```

## Primitive types of v3

Source: [https://godoc.org/goa.design/goa/expr#pkg-constants](https://godoc.org/goa.design/goa/expr#pkg-constants)

```go
const (
    // Boolean is the type for a JSON boolean.
    Boolean = Primitive(BooleanKind)

    // Int is the type for a signed integer.
    Int = Primitive(IntKind)

    // Int32 is the type for a signed 32-bit integer.
    Int32 = Primitive(Int32Kind)

    // Int64 is the type for a signed 64-bit integer.
    Int64 = Primitive(Int64Kind)

    // UInt is the type for an unsigned integer.
    UInt = Primitive(UIntKind)

    // UInt32 is the type for an unsigned 32-bit integer.
    UInt32 = Primitive(UInt32Kind)

    // UInt64 is the type for an unsigned 64-bit integer.
    UInt64 = Primitive(UInt64Kind)

    // Float32 is the type for a 32-bit floating number.
    Float32 = Primitive(Float32Kind)

    // Float64 is the type for a 64-bit floating number.
    Float64 = Primitive(Float64Kind)

    // String is the type for a JSON string.
    String = Primitive(StringKind)

    // Bytes is the type for binary data.
    Bytes = Primitive(BytesKind)

    // Any is the type for an arbitrary JSON value (interface{} in Go).
    Any = Primitive(AnyKind)
)
```

## Swagger data types

Source: [https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types)

Common Name | `type` | `format` | Comments
----------- | ------ | -------- | --------
integer | `integer` | `int32` | signed 32 bits
long | `integer` | `int64` | signed 64 bits
float | `number` | `float` | |
double | `number` | `double` | |
string | `string` | | |
byte | `string` | `byte` | base64 encoded characters
binary | `string` | `binary` | any sequence of octets
boolean | `boolean` | | |
date | `string` | `date` | As defined by `full-date` - [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)
dateTime | `string` | `date-time` | As defined by `date-time` - [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)
password | `string` | `password` | Used to hint UIs the input needs to be obscured.

## Comparison

v3 has more types than v1 to support gRPC. `DateTime` and `UUID` are obsoleted but equivalent definitions can be described using the `Format` DSL. There are many more formats.

| v1 | v3 | Swagger Common Name | Swagger `type` | Swagger `format` |
| --- | --- | --- | --- | --- |
| `Boolean` | `Boolean` | boolean | `boolean` | |
| `Integer` | `Int` | long | `integer` | `int64` |
| | `Int32` | integer | `integer` | `int32` |
| | `Int64` | long | `integer` | `int64` |
| | `UInt` | long | `integer` | `int64` |
| | `UInt32` | integer | `integer` | `int32` |
| | `UInt64` | long | `integer` | `int64` |
| `Number` | `Float32` | float | `number` | `float` |
| | `Float64` | double | `number` | `double` |
| `String` | `String` | string | `string` | |
| `DateTime` | `String` + `Format(FormatDateTime)` | dateTime | `string` | `date-time` |
| `UUID` | `String` + `Format(FormatUUID)` | | `string` | `uuid` |
| | `String` + `Format(FormatDate)` | date | `string` | `date` |
| | `String` + `Format(FormatEmail)` | | `string` | `email` |
| | `String` + `Format(FormatHostname)` | | `string` | `hostname` |
| | `String` + `Format(FormatIPv4)` | | `string` | `ipv4` |
| | `String` + `Format(FormatIPv6)` | | `string` | `ipv6` |
| | `String` + `Format(FormatIP)` | | `string` | `ip` |
| | `String` + `Format(FormatURI)` | | `string` | `uri` |
| | `String` + `Format(FormatMAC)` | | `string` | `mac` |
| | `String` + `Format(FormatCIDR)` | | `string` | `cidr` |
| | `String` + `Format(FormatRegexp)` | | `string` | `regexp` |
| | `String` + `Format(FormatJSON)` | | `string` | `json` |
| | `String` + `Format(FormatRFC1123)` | | `string` | `rfc1123` |
| | `Bytes` | byte | `string` | `byte` |
| `Any` | `Any` | | `any` | |
| `File` | | | `file` | |