Repository: go-openapi/strfmt
Pull request #48 (2019-03-07 20:24:38)

Feature: Add CIDR format
Adds CIDR format and validation that work for IPv4 and IPv6.

- Code formatted using `goimports`.
- Lint fixes based on output from `golangci-lint` that do not impact
  the exported names. Adds exclude for lint errors that requires a
  change to the exported names.
- Dependency updated using `go mod tidy`

codecov[bot]: # [Codecov](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=h1) Report
> Merging [#48](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=desc) into [master](https://codecov.io/gh/go-openapi/strfmt/commit/bb512950308460a5584a64228c227807cea1e4bd?src=pr&el=desc) will **decrease** coverage by `0.06%`.
> The diff coverage is `97.12%`.

[![Impacted file tree graph](https://codecov.io/gh/go-openapi/strfmt/pull/48/graphs/tree.svg?width=650&token=1NsRXHf1sd&height=150&src=pr)](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
- Coverage   89.33%   89.26%   -0.07%     
==========================================
  Files          10       10              
  Lines        1632     1668      +36     
==========================================
+ Hits         1458     1489      +31     
- Misses        145      149       +4     
- Partials       29       30       +1
```


| [Impacted Files](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [format.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-Zm9ybWF0Lmdv) | `73.91% <100%> (+0.32%)` | :arrow_up: |
| [time.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-dGltZS5nbw==) | `96.66% <100%> (-0.04%)` | :arrow_down: |
| [date.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-ZGF0ZS5nbw==) | `95.83% <100%> (-0.06%)` | :arrow_down: |
| [bson.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-YnNvbi5nbw==) | `77.19% <100%> (-0.4%)` | :arrow_down: |
| [duration.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-ZHVyYXRpb24uZ28=) | `96.42% <100%> (-0.05%)` | :arrow_down: |
| [conv/default.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-Y29udi9kZWZhdWx0Lmdv) | `66.66% <66.66%> (ø)` | :arrow_up: |
| [default.go](https://codecov.io/gh/go-openapi/strfmt/pull/48/diff?src=pr&el=tree#diff-ZGVmYXVsdC5nbw==) | `93.52% <97.94%> (-0.09%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=footer). Last update [bb51295...3af8f20](https://codecov.io/gh/go-openapi/strfmt/pull/48?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 08d2e68..3702f9d 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -4,7 +4,7 @@ linters-settings:
   golint:
     min-confidence: 0
   gocyclo:
-    min-complexity: 30
+    min-complexity: 31
   maligned:
     suggest-new: true
   dupl:
@@ -20,3 +20,10 @@ linters:
     - lll
     - gochecknoinits
     - gochecknoglobals
+
+issues:
+  exclude-rules:
+    - path: bson.go
+      text: "should be .*ObjectID"
+      linters:
+        - golint
diff --git a/README.md b/README.md
index 55f8804..87357cd 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ This package exposes a registry of data types to support string formats in the g
 strfmt represents a well known string format such as credit card or email. The go toolkit for OpenAPI specifications knows how to deal with those.
 
 ## Supported data formats
-go-openapi/strfmt follows the swagger 2.0 specification with the following formats 
+go-openapi/strfmt follows the swagger 2.0 specification with the following formats
 defined [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types).
 
 It also provides convenient extensions to go-openapi users.
@@ -37,12 +37,13 @@ It also provides convenient extensions to go-openapi users.
   - rgbcolor (e.g. "rgb(100,100,100)")
   - ssn
   - uuid, uuid3, uuid4, uuid5
+  - cidr (e.g. "192.0.2.1/24", "2001:db8:a0b:12f0::1/32")
 
-> NOTE: as the name stands for, this package is intended to support string formatting only. 
-> It does not provide validation for numerical values with swagger format extension for JSON types "number" or  
+> NOTE: as the name stands for, this package is intended to support string formatting only.
+> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
 > "integer" (e.g. float, double, int32...).
 
-## Format types 
+## Format types
 Types defined in strfmt expose marshaling and validation capabilities.
 
 List of defined types:
@@ -56,6 +57,7 @@ List of defined types:
 - Hostname
 - IPv4
 - IPv6
+- CIDR
 - ISBN
 - ISBN10
 - ISBN13
diff --git a/bson.go b/bson.go
index 2abd101..79bd2d8 100644
--- a/bson.go
+++ b/bson.go
@@ -127,17 +127,16 @@ func (id *ObjectId) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *ObjectId) DeepCopyInto(out *ObjectId) {
-	*out = *in
-	return
+func (id *ObjectId) DeepCopyInto(out *ObjectId) {
+	*out = *id
 }
 
 // DeepCopy copies the receiver into a new ObjectId.
-func (in *ObjectId) DeepCopy() *ObjectId {
-	if in == nil {
+func (id *ObjectId) DeepCopy() *ObjectId {
+	if id == nil {
 		return nil
 	}
 	out := new(ObjectId)
-	in.DeepCopyInto(out)
+	id.DeepCopyInto(out)
 	return out
 }
diff --git a/conv/default.go b/conv/default.go
index d00fa17..078a1e5 100644
--- a/conv/default.go
+++ b/conv/default.go
@@ -94,6 +94,21 @@ func IPv6Value(v *strfmt.IPv6) strfmt.IPv6 {
 	return *v
 }
 
+// CIDR returns a pointer to of the CIDR value passed in.
+func CIDR(v strfmt.CIDR) *strfmt.CIDR {
+	return &v
+}
+
+// CIDRValue returns the value of the CIDR pointer passed in or
+// the default value if the pointer is nil.
+func CIDRValue(v *strfmt.CIDR) strfmt.CIDR {
+	if v == nil {
+		return strfmt.CIDR("")
+	}
+
+	return *v
+}
+
 // MAC returns a pointer to of the MAC value passed in.
 func MAC(v strfmt.MAC) *strfmt.MAC {
 	return &v
diff --git a/date.go b/date.go
index 482bda6..7108bab 100644
--- a/date.go
+++ b/date.go
@@ -150,17 +150,16 @@ func (d *Date) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Date) DeepCopyInto(out *Date) {
-	*out = *in
-	return
+func (d *Date) DeepCopyInto(out *Date) {
+	*out = *d
 }
 
 // DeepCopy copies the receiver into a new Date.
-func (in *Date) DeepCopy() *Date {
-	if in == nil {
+func (d *Date) DeepCopy() *Date {
+	if d == nil {
 		return nil
 	}
 	out := new(Date)
-	in.DeepCopyInto(out)
+	d.DeepCopyInto(out)
 	return out
 }
diff --git a/default.go b/default.go
index c36abad..e438d38 100644
--- a/default.go
+++ b/default.go
@@ -135,6 +135,7 @@ func init() {
 	//   - hostname
 	//   - ipv4
 	//   - ipv6
+	//   - cidr
 	//   - isbn
 	//   - isbn10
 	//   - isbn13
@@ -162,6 +163,9 @@ func init() {
 	ip6 := IPv6("")
 	Default.Add("ipv6", &ip6, govalidator.IsIPv6)
 
+	cidr := CIDR("")
+	Default.Add("cidr", &cidr, govalidator.IsCIDR)
+
 	mac := MAC("")
 	Default.Add("mac", &mac, govalidator.IsMAC)
 
@@ -312,18 +316,17 @@ func (b *Base64) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Base64) DeepCopyInto(out *Base64) {
-	*out = *in
-	return
+func (b *Base64) DeepCopyInto(out *Base64) {
+	*out = *b
 }
 
 // DeepCopy copies the receiver into a new Base64.
-func (in *Base64) DeepCopy() *Base64 {
-	if in == nil {
+func (b *Base64) DeepCopy() *Base64 {
+	if b == nil {
 		return nil
 	}
 	out := new(Base64)
-	in.DeepCopyInto(out)
+	b.DeepCopyInto(out)
 	return out
 }
 
@@ -413,18 +416,17 @@ func (u *URI) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *URI) DeepCopyInto(out *URI) {
-	*out = *in
-	return
+func (u *URI) DeepCopyInto(out *URI) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new URI.
-func (in *URI) DeepCopy() *URI {
-	if in == nil {
+func (u *URI) DeepCopy() *URI {
+	if u == nil {
 		return nil
 	}
 	out := new(URI)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -514,18 +516,17 @@ func (e *Email) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Email) DeepCopyInto(out *Email) {
-	*out = *in
-	return
+func (e *Email) DeepCopyInto(out *Email) {
+	*out = *e
 }
 
 // DeepCopy copies the receiver into a new Email.
-func (in *Email) DeepCopy() *Email {
-	if in == nil {
+func (e *Email) DeepCopy() *Email {
+	if e == nil {
 		return nil
 	}
 	out := new(Email)
-	in.DeepCopyInto(out)
+	e.DeepCopyInto(out)
 	return out
 }
 
@@ -615,18 +616,17 @@ func (h *Hostname) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Hostname) DeepCopyInto(out *Hostname) {
-	*out = *in
-	return
+func (h *Hostname) DeepCopyInto(out *Hostname) {
+	*out = *h
 }
 
 // DeepCopy copies the receiver into a new Hostname.
-func (in *Hostname) DeepCopy() *Hostname {
-	if in == nil {
+func (h *Hostname) DeepCopy() *Hostname {
+	if h == nil {
 		return nil
 	}
 	out := new(Hostname)
-	in.DeepCopyInto(out)
+	h.DeepCopyInto(out)
 	return out
 }
 
@@ -716,18 +716,17 @@ func (u *IPv4) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *IPv4) DeepCopyInto(out *IPv4) {
-	*out = *in
-	return
+func (u *IPv4) DeepCopyInto(out *IPv4) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new IPv4.
-func (in *IPv4) DeepCopy() *IPv4 {
-	if in == nil {
+func (u *IPv4) DeepCopy() *IPv4 {
+	if u == nil {
 		return nil
 	}
 	out := new(IPv4)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -817,18 +816,117 @@ func (u *IPv6) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *IPv6) DeepCopyInto(out *IPv6) {
-	*out = *in
-	return
+func (u *IPv6) DeepCopyInto(out *IPv6) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new IPv6.
-func (in *IPv6) DeepCopy() *IPv6 {
-	if in == nil {
+func (u *IPv6) DeepCopy() *IPv6 {
+	if u == nil {
 		return nil
 	}
 	out := new(IPv6)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
+	return out
+}
+
+// CIDR represents a Classless Inter-Domain Routing notation
+//
+// swagger:strfmt cidr
+type CIDR string
+
+// MarshalText turns this instance into text
+func (u CIDR) MarshalText() ([]byte, error) {
+	return []byte(string(u)), nil
+}
+
+// UnmarshalText hydrates this instance from text
+func (u *CIDR) UnmarshalText(data []byte) error { // validation is performed later on
+	*u = CIDR(string(data))
+	return nil
+}
+
+// Scan read a value from a database driver
+func (u *CIDR) Scan(raw interface{}) error {
+	switch v := raw.(type) {
+	case []byte:
+		*u = CIDR(string(v))
+	case string:
+		*u = CIDR(v)
+	default:
+		return fmt.Errorf("cannot sql.Scan() strfmt.CIDR from: %#v", v)
+	}
+
+	return nil
+}
+
+// Value converts a value to a database driver value
+func (u CIDR) Value() (driver.Value, error) {
+	return driver.Value(string(u)), nil
+}
+
+func (u CIDR) String() string {
+	return string(u)
+}
+
+// MarshalJSON returns the CIDR as JSON
+func (u CIDR) MarshalJSON() ([]byte, error) {
+	var w jwriter.Writer
+	u.MarshalEasyJSON(&w)
+	return w.BuildBytes()
+}
+
+// MarshalEasyJSON writes the CIDR to a easyjson.Writer
+func (u CIDR) MarshalEasyJSON(w *jwriter.Writer) {
+	w.String(string(u))
+}
+
+// UnmarshalJSON sets the CIDR from JSON
+func (u *CIDR) UnmarshalJSON(data []byte) error {
+	l := jlexer.Lexer{Data: data}
+	u.UnmarshalEasyJSON(&l)
+	return l.Error()
+}
+
+// UnmarshalEasyJSON sets the CIDR from a easyjson.Lexer
+func (u *CIDR) UnmarshalEasyJSON(in *jlexer.Lexer) {
+	if data := in.String(); in.Ok() {
+		*u = CIDR(data)
+	}
+}
+
+// GetBSON returns the CIDR as a bson.M{} map.
+func (u *CIDR) GetBSON() (interface{}, error) {
+	return bson.M{"data": string(*u)}, nil
+}
+
+// SetBSON sets the CIDR from raw bson data
+func (u *CIDR) SetBSON(raw bson.Raw) error {
+	var m bson.M
+	if err := raw.Unmarshal(&m); err != nil {
+		return err
+	}
+
+	if data, ok := m["data"].(string); ok {
+		*u = CIDR(data)
+		return nil
+	}
+
+	return errors.New("couldn't unmarshal bson raw value as CIDR")
+}
+
+// DeepCopyInto copies the receiver and writes its value into out.
+func (u *CIDR) DeepCopyInto(out *CIDR) {
+	*out = *u
+}
+
+// DeepCopy copies the receiver into a new CIDR.
+func (u *CIDR) DeepCopy() *CIDR {
+	if u == nil {
+		return nil
+	}
+	out := new(CIDR)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -918,18 +1016,17 @@ func (u *MAC) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *MAC) DeepCopyInto(out *MAC) {
-	*out = *in
-	return
+func (u *MAC) DeepCopyInto(out *MAC) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new MAC.
-func (in *MAC) DeepCopy() *MAC {
-	if in == nil {
+func (u *MAC) DeepCopy() *MAC {
+	if u == nil {
 		return nil
 	}
 	out := new(MAC)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1022,18 +1119,17 @@ func (u *UUID) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *UUID) DeepCopyInto(out *UUID) {
-	*out = *in
-	return
+func (u *UUID) DeepCopyInto(out *UUID) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new UUID.
-func (in *UUID) DeepCopy() *UUID {
-	if in == nil {
+func (u *UUID) DeepCopy() *UUID {
+	if u == nil {
 		return nil
 	}
 	out := new(UUID)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1126,18 +1222,17 @@ func (u *UUID3) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *UUID3) DeepCopyInto(out *UUID3) {
-	*out = *in
-	return
+func (u *UUID3) DeepCopyInto(out *UUID3) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new UUID3.
-func (in *UUID3) DeepCopy() *UUID3 {
-	if in == nil {
+func (u *UUID3) DeepCopy() *UUID3 {
+	if u == nil {
 		return nil
 	}
 	out := new(UUID3)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1230,18 +1325,17 @@ func (u *UUID4) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *UUID4) DeepCopyInto(out *UUID4) {
-	*out = *in
-	return
+func (u *UUID4) DeepCopyInto(out *UUID4) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new UUID4.
-func (in *UUID4) DeepCopy() *UUID4 {
-	if in == nil {
+func (u *UUID4) DeepCopy() *UUID4 {
+	if u == nil {
 		return nil
 	}
 	out := new(UUID4)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1334,18 +1428,17 @@ func (u *UUID5) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *UUID5) DeepCopyInto(out *UUID5) {
-	*out = *in
-	return
+func (u *UUID5) DeepCopyInto(out *UUID5) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new UUID5.
-func (in *UUID5) DeepCopy() *UUID5 {
-	if in == nil {
+func (u *UUID5) DeepCopy() *UUID5 {
+	if u == nil {
 		return nil
 	}
 	out := new(UUID5)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1435,18 +1528,17 @@ func (u *ISBN) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *ISBN) DeepCopyInto(out *ISBN) {
-	*out = *in
-	return
+func (u *ISBN) DeepCopyInto(out *ISBN) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new ISBN.
-func (in *ISBN) DeepCopy() *ISBN {
-	if in == nil {
+func (u *ISBN) DeepCopy() *ISBN {
+	if u == nil {
 		return nil
 	}
 	out := new(ISBN)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1536,18 +1628,17 @@ func (u *ISBN10) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *ISBN10) DeepCopyInto(out *ISBN10) {
-	*out = *in
-	return
+func (u *ISBN10) DeepCopyInto(out *ISBN10) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new ISBN10.
-func (in *ISBN10) DeepCopy() *ISBN10 {
-	if in == nil {
+func (u *ISBN10) DeepCopy() *ISBN10 {
+	if u == nil {
 		return nil
 	}
 	out := new(ISBN10)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1637,18 +1728,17 @@ func (u *ISBN13) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *ISBN13) DeepCopyInto(out *ISBN13) {
-	*out = *in
-	return
+func (u *ISBN13) DeepCopyInto(out *ISBN13) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new ISBN13.
-func (in *ISBN13) DeepCopy() *ISBN13 {
-	if in == nil {
+func (u *ISBN13) DeepCopy() *ISBN13 {
+	if u == nil {
 		return nil
 	}
 	out := new(ISBN13)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1738,18 +1828,17 @@ func (u *CreditCard) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *CreditCard) DeepCopyInto(out *CreditCard) {
-	*out = *in
-	return
+func (u *CreditCard) DeepCopyInto(out *CreditCard) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new CreditCard.
-func (in *CreditCard) DeepCopy() *CreditCard {
-	if in == nil {
+func (u *CreditCard) DeepCopy() *CreditCard {
+	if u == nil {
 		return nil
 	}
 	out := new(CreditCard)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1839,18 +1928,17 @@ func (u *SSN) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *SSN) DeepCopyInto(out *SSN) {
-	*out = *in
-	return
+func (u *SSN) DeepCopyInto(out *SSN) {
+	*out = *u
 }
 
 // DeepCopy copies the receiver into a new SSN.
-func (in *SSN) DeepCopy() *SSN {
-	if in == nil {
+func (u *SSN) DeepCopy() *SSN {
+	if u == nil {
 		return nil
 	}
 	out := new(SSN)
-	in.DeepCopyInto(out)
+	u.DeepCopyInto(out)
 	return out
 }
 
@@ -1940,18 +2028,17 @@ func (h *HexColor) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *HexColor) DeepCopyInto(out *HexColor) {
-	*out = *in
-	return
+func (h *HexColor) DeepCopyInto(out *HexColor) {
+	*out = *h
 }
 
 // DeepCopy copies the receiver into a new HexColor.
-func (in *HexColor) DeepCopy() *HexColor {
-	if in == nil {
+func (h *HexColor) DeepCopy() *HexColor {
+	if h == nil {
 		return nil
 	}
 	out := new(HexColor)
-	in.DeepCopyInto(out)
+	h.DeepCopyInto(out)
 	return out
 }
 
@@ -2041,18 +2128,17 @@ func (r *RGBColor) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *RGBColor) DeepCopyInto(out *RGBColor) {
-	*out = *in
-	return
+func (r *RGBColor) DeepCopyInto(out *RGBColor) {
+	*out = *r
 }
 
 // DeepCopy copies the receiver into a new RGBColor.
-func (in *RGBColor) DeepCopy() *RGBColor {
-	if in == nil {
+func (r *RGBColor) DeepCopy() *RGBColor {
+	if r == nil {
 		return nil
 	}
 	out := new(RGBColor)
-	in.DeepCopyInto(out)
+	r.DeepCopyInto(out)
 	return out
 }
 
@@ -2143,17 +2229,16 @@ func (r *Password) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Password) DeepCopyInto(out *Password) {
-	*out = *in
-	return
+func (r *Password) DeepCopyInto(out *Password) {
+	*out = *r
 }
 
 // DeepCopy copies the receiver into a new Password.
-func (in *Password) DeepCopy() *Password {
-	if in == nil {
+func (r *Password) DeepCopy() *Password {
+	if r == nil {
 		return nil
 	}
 	out := new(Password)
-	in.DeepCopyInto(out)
+	r.DeepCopyInto(out)
 	return out
 }
diff --git a/duration.go b/duration.go
index 65b2b69..7867a0e 100644
--- a/duration.go
+++ b/duration.go
@@ -203,17 +203,16 @@ func (d *Duration) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *Duration) DeepCopyInto(out *Duration) {
-	*out = *in
-	return
+func (d *Duration) DeepCopyInto(out *Duration) {
+	*out = *d
 }
 
 // DeepCopy copies the receiver into a new Duration.
-func (in *Duration) DeepCopy() *Duration {
-	if in == nil {
+func (d *Duration) DeepCopy() *Duration {
+	if d == nil {
 		return nil
 	}
 	out := new(Duration)
-	in.DeepCopyInto(out)
+	d.DeepCopyInto(out)
 	return out
 }
diff --git a/format.go b/format.go
index 266cff5..9ac14f1 100644
--- a/format.go
+++ b/format.go
@@ -138,6 +138,8 @@ func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
 					return IPv4(data.(string)), nil
 				case "ipv6":
 					return IPv6(data.(string)), nil
+				case "cidr":
+					return CIDR(data.(string)), nil
 				case "mac":
 					return MAC(data.(string)), nil
 				case "isbn":
diff --git a/go.mod b/go.mod
index 19c0939..24cb388 100644
--- a/go.mod
+++ b/go.mod
@@ -2,12 +2,12 @@ module github.com/go-openapi/strfmt
 
 require (
 	github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
-	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb
 	github.com/go-openapi/errors v0.17.0
+	github.com/kr/pretty v0.1.0 // indirect
 	github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329
 	github.com/mitchellh/mapstructure v1.1.2
 	github.com/pborman/uuid v1.2.0
-	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/stretchr/testify v1.2.2
+	gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
 )
diff --git a/go.sum b/go.sum
index 77349a2..73b59ba 100644
--- a/go.sum
+++ b/go.sum
@@ -4,16 +4,24 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvUbuvHW93esHg7F8N/OYeBBcJoTr0=
 github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
-github.com/go-openapi/errors v0.17.0 h1:47T+LqPrQUxFXQnB22aLBfsTRFSqWp5y4OiFgQm+/Lw=
-github.com/go-openapi/errors v0.17.0/go.mod h1:La0D2x9HoXenv7MDEiAv6vWoe84CXFo0PQRk/jdQlww=
+github.com/go-openapi/errors v0.17.0 h1:g5DzIh94VpuR/dd6Ff8KqyHNnw7yBa2xSHIPPzjRDUo=
+github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
 github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
 github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
 github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
 github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
 github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
 github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/time.go b/time.go
index 23f5380..f550dc4 100644
--- a/time.go
+++ b/time.go
@@ -195,17 +195,16 @@ func (t *DateTime) SetBSON(raw bson.Raw) error {
 }
 
 // DeepCopyInto copies the receiver and writes its value into out.
-func (in *DateTime) DeepCopyInto(out *DateTime) {
-	*out = *in
-	return
+func (t *DateTime) DeepCopyInto(out *DateTime) {
+	*out = *t
 }
 
 // DeepCopy copies the receiver into a new DateTime.
-func (in *DateTime) DeepCopy() *DateTime {
-	if in == nil {
+func (t *DateTime) DeepCopy() *DateTime {
+	if t == nil {
 		return nil
 	}
 	out := new(DateTime)
-	in.DeepCopyInto(out)
+	t.DeepCopyInto(out)
 	return out
 }


Test patch:
diff --git a/conv/date_test.go b/conv/date_test.go
index da97888..85586f4 100644
--- a/conv/date_test.go
+++ b/conv/date_test.go
@@ -4,8 +4,9 @@ import (
 	"testing"
 	"time"
 
-	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/strfmt"
 )
 
 func TestDateValue(t *testing.T) {
diff --git a/conv/default_test.go b/conv/default_test.go
index b182ef7..8b779c5 100644
--- a/conv/default_test.go
+++ b/conv/default_test.go
@@ -3,8 +3,9 @@ package conv
 import (
 	"testing"
 
-	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/strfmt"
 )
 
 func TestBase64Value(t *testing.T) {
@@ -43,6 +44,12 @@ func TestIPv6Value(t *testing.T) {
 	assert.Equal(t, value, IPv6Value(&value))
 }
 
+func TestCIDRValue(t *testing.T) {
+	assert.Equal(t, strfmt.CIDR(""), CIDRValue(nil))
+	value := strfmt.CIDR("foo")
+	assert.Equal(t, value, CIDRValue(&value))
+}
+
 func TestMACValue(t *testing.T) {
 	assert.Equal(t, strfmt.MAC(""), MACValue(nil))
 	value := strfmt.MAC("foo")
diff --git a/conv/duration_test.go b/conv/duration_test.go
index f19173f..a015936 100644
--- a/conv/duration_test.go
+++ b/conv/duration_test.go
@@ -3,8 +3,9 @@ package conv
 import (
 	"testing"
 
-	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/strfmt"
 )
 
 func TestDurationValue(t *testing.T) {
diff --git a/conv/time_test.go b/conv/time_test.go
index 89a427d..9196bdb 100644
--- a/conv/time_test.go
+++ b/conv/time_test.go
@@ -4,8 +4,9 @@ import (
 	"testing"
 	"time"
 
-	"github.com/go-openapi/strfmt"
 	"github.com/stretchr/testify/assert"
+
+	"github.com/go-openapi/strfmt"
 )
 
 func TestDateTimeValue(t *testing.T) {
diff --git a/default_test.go b/default_test.go
index 1645546..3544728 100644
--- a/default_test.go
+++ b/default_test.go
@@ -158,6 +158,12 @@ func TestFormatIPv6(t *testing.T) {
 	testStringFormat(t, &ipv6, "ipv6", str, []string{}, []string{"127.0.0.1"})
 }
 
+func TestFormatCIDR(t *testing.T) {
+	cidr := CIDR("192.168.254.1/24")
+	str := string("192.168.254.2/24")
+	testStringFormat(t, &cidr, "cidr", str, []string{"192.0.2.1/24", "2001:db8:a0b:12f0::1/32"}, []string{"198.168.254.2", "2001:db8:a0b:12f0::1"})
+}
+
 func TestFormatMAC(t *testing.T) {
 	mac := MAC("01:02:03:04:05:06")
 	str := string("06:05:04:03:02:01")
@@ -531,6 +537,22 @@ func TestDeepCopyIPv6(t *testing.T) {
 	assert.Nil(t, out3)
 }
 
+func TestDeepCopyCIDR(t *testing.T) {
+	cidr := CIDR("192.0.2.1/24")
+	in := &cidr
+
+	out := new(CIDR)
+	in.DeepCopyInto(out)
+	assert.Equal(t, in, out)
+
+	out2 := in.DeepCopy()
+	assert.Equal(t, in, out2)
+
+	var inNil *CIDR
+	out3 := inNil.DeepCopy()
+	assert.Nil(t, out3)
+}
+
 func TestDeepCopyMAC(t *testing.T) {
 	mac := MAC("01:02:03:04:05:06")
 	in := &mac
diff --git a/format_test.go b/format_test.go
index 5caf30f..dc9afed 100644
--- a/format_test.go
+++ b/format_test.go
@@ -140,6 +140,7 @@ type testStruct struct {
 	Hn         Hostname   `json:"hn,omitempty"`
 	Ipv4       IPv4       `json:"ipv4,omitempty"`
 	Ipv6       IPv6       `json:"ipv6,omitempty"`
+	Cidr       CIDR       `json:"cidr,omitempty"`
 	Mac        MAC        `json:"mac,omitempty"`
 	Isbn       ISBN       `json:"isbn,omitempty"`
 	Isbn10     ISBN10     `json:"isbn10,omitempty"`
@@ -167,6 +168,7 @@ func TestDecodeHook(t *testing.T) {
 		"hn":         "somewhere.com",
 		"ipv4":       "192.168.254.1",
 		"ipv6":       "::1",
+		"cidr":       "192.0.2.1/24",
 		"mac":        "01:02:03:04:05:06",
 		"isbn":       "0321751043",
 		"isbn10":     "0321751043",
@@ -196,6 +198,7 @@ func TestDecodeHook(t *testing.T) {
 		Hn:         Hostname("somewhere.com"),
 		Ipv4:       IPv4("192.168.254.1"),
 		Ipv6:       IPv6("::1"),
+		Cidr:       CIDR("192.0.2.1/24"),
 		Mac:        MAC("01:02:03:04:05:06"),
 		Isbn:       ISBN("0321751043"),
 		Isbn10:     ISBN10("0321751043"),