1// Copyright 2015 go-swagger maintainers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package strfmt
16
17import (
18	"encoding/base64"
19	"encoding/json"
20	"fmt"
21	"net/mail"
22	"regexp"
23	"strings"
24
25	"github.com/asaskevich/govalidator"
26)
27
28const (
29	// HostnamePattern http://json-schema.org/latest/json-schema-validation.html#anchor114
30	//  A string instance is valid against this attribute if it is a valid
31	//  representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
32	//  http://tools.ietf.org/html/rfc1034#section-3.5
33	//  <digit> ::= any one of the ten digits 0 through 9
34	//  var digit = /[0-9]/;
35	//  <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
36	//  var letter = /[a-zA-Z]/;
37	//  <let-dig> ::= <letter> | <digit>
38	//  var letDig = /[0-9a-zA-Z]/;
39	//  <let-dig-hyp> ::= <let-dig> | "-"
40	//  var letDigHyp = /[-0-9a-zA-Z]/;
41	//  <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
42	//  var ldhStr = /[-0-9a-zA-Z]+/;
43	//  <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
44	//  var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
45	//  <subdomain> ::= <label> | <subdomain> "." <label>
46	//  var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
47	//  <domain> ::= <subdomain> | " "
48	//
49	// Additional validations:
50	//   - for FDQNs, top-level domain (e.g. ".com"), is at least to letters long (no special characters here)
51	//   - hostnames may start with a digit [RFC1123]
52	//   - special registered names with an underscore ('_') are not allowed in this context
53	//   - dashes are permitted, but not at the start or the end of a segment
54	//   - long top-level domain names (e.g. example.london) are permitted
55	//   - symbol unicode points are permitted (e.g. emoji) (not for top-level domain)
56	HostnamePattern = `^([a-zA-Z0-9\p{S}\p{L}]((-?[a-zA-Z0-9\p{S}\p{L}]{0,62})?)|([a-zA-Z0-9\p{S}\p{L}](([a-zA-Z0-9-\p{S}\p{L}]{0,61}[a-zA-Z0-9\p{S}\p{L}])?)(\.)){1,}([a-zA-Z\p{L}]){2,63})$`
57	// UUIDPattern Regex for UUID that allows uppercase
58	UUIDPattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$`
59	// UUID3Pattern Regex for UUID3 that allows uppercase
60	UUID3Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?3[0-9a-f]{3}-?[0-9a-f]{4}-?[0-9a-f]{12}$`
61	// UUID4Pattern Regex for UUID4 that allows uppercase
62	UUID4Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$`
63	// UUID5Pattern Regex for UUID5 that allows uppercase
64	UUID5Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?5[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$`
65	// json null type
66	jsonNull = "null"
67)
68
69var (
70	rxHostname = regexp.MustCompile(HostnamePattern)
71	rxUUID     = regexp.MustCompile(UUIDPattern)
72	rxUUID3    = regexp.MustCompile(UUID3Pattern)
73	rxUUID4    = regexp.MustCompile(UUID4Pattern)
74	rxUUID5    = regexp.MustCompile(UUID5Pattern)
75)
76
77// IsHostname returns true when the string is a valid hostname
78func IsHostname(str string) bool {
79	if !rxHostname.MatchString(str) {
80		return false
81	}
82
83	// the sum of all label octets and label lengths is limited to 255.
84	if len(str) > 255 {
85		return false
86	}
87
88	// Each node has a label, which is zero to 63 octets in length
89	parts := strings.Split(str, ".")
90	valid := true
91	for _, p := range parts {
92		if len(p) > 63 {
93			valid = false
94		}
95	}
96	return valid
97}
98
99// IsUUID returns true is the string matches a UUID, upper case is allowed
100func IsUUID(str string) bool {
101	return rxUUID.MatchString(str)
102}
103
104// IsUUID3 returns true is the string matches a UUID, upper case is allowed
105func IsUUID3(str string) bool {
106	return rxUUID3.MatchString(str)
107}
108
109// IsUUID4 returns true is the string matches a UUID, upper case is allowed
110func IsUUID4(str string) bool {
111	return rxUUID4.MatchString(str)
112}
113
114// IsUUID5 returns true is the string matches a UUID, upper case is allowed
115func IsUUID5(str string) bool {
116	return rxUUID5.MatchString(str)
117}
118
119// IsEmail validates an email address.
120func IsEmail(str string) bool {
121	addr, e := mail.ParseAddress(str)
122	return e == nil && addr.Address != ""
123}
124
125func init() {
126	// register formats in the default registry:
127	//   - byte
128	//   - creditcard
129	//   - email
130	//   - hexcolor
131	//   - hostname
132	//   - ipv4
133	//   - ipv6
134	//   - cidr
135	//   - isbn
136	//   - isbn10
137	//   - isbn13
138	//   - mac
139	//   - password
140	//   - rgbcolor
141	//   - ssn
142	//   - uri
143	//   - uuid
144	//   - uuid3
145	//   - uuid4
146	//   - uuid5
147	u := URI("")
148	Default.Add("uri", &u, govalidator.IsRequestURI)
149
150	eml := Email("")
151	Default.Add("email", &eml, IsEmail)
152
153	hn := Hostname("")
154	Default.Add("hostname", &hn, IsHostname)
155
156	ip4 := IPv4("")
157	Default.Add("ipv4", &ip4, govalidator.IsIPv4)
158
159	ip6 := IPv6("")
160	Default.Add("ipv6", &ip6, govalidator.IsIPv6)
161
162	cidr := CIDR("")
163	Default.Add("cidr", &cidr, govalidator.IsCIDR)
164
165	mac := MAC("")
166	Default.Add("mac", &mac, govalidator.IsMAC)
167
168	uid := UUID("")
169	Default.Add("uuid", &uid, IsUUID)
170
171	uid3 := UUID3("")
172	Default.Add("uuid3", &uid3, IsUUID3)
173
174	uid4 := UUID4("")
175	Default.Add("uuid4", &uid4, IsUUID4)
176
177	uid5 := UUID5("")
178	Default.Add("uuid5", &uid5, IsUUID5)
179
180	isbn := ISBN("")
181	Default.Add("isbn", &isbn, func(str string) bool { return govalidator.IsISBN10(str) || govalidator.IsISBN13(str) })
182
183	isbn10 := ISBN10("")
184	Default.Add("isbn10", &isbn10, govalidator.IsISBN10)
185
186	isbn13 := ISBN13("")
187	Default.Add("isbn13", &isbn13, govalidator.IsISBN13)
188
189	cc := CreditCard("")
190	Default.Add("creditcard", &cc, govalidator.IsCreditCard)
191
192	ssn := SSN("")
193	Default.Add("ssn", &ssn, govalidator.IsSSN)
194
195	hc := HexColor("")
196	Default.Add("hexcolor", &hc, govalidator.IsHexcolor)
197
198	rc := RGBColor("")
199	Default.Add("rgbcolor", &rc, govalidator.IsRGBcolor)
200
201	b64 := Base64([]byte(nil))
202	Default.Add("byte", &b64, govalidator.IsBase64)
203
204	pw := Password("")
205	Default.Add("password", &pw, func(_ string) bool { return true })
206}
207
208// Base64 represents a base64 encoded string, using URLEncoding alphabet
209//
210// swagger:strfmt byte
211type Base64 []byte
212
213// MarshalText turns this instance into text
214func (b Base64) MarshalText() ([]byte, error) {
215	enc := base64.URLEncoding
216	src := []byte(b)
217	buf := make([]byte, enc.EncodedLen(len(src)))
218	enc.Encode(buf, src)
219	return buf, nil
220}
221
222// UnmarshalText hydrates this instance from text
223func (b *Base64) UnmarshalText(data []byte) error { // validation is performed later on
224	enc := base64.URLEncoding
225	dbuf := make([]byte, enc.DecodedLen(len(data)))
226
227	n, err := enc.Decode(dbuf, data)
228	if err != nil {
229		return err
230	}
231
232	*b = dbuf[:n]
233	return nil
234}
235
236// Scan read a value from a database driver
237func (b *Base64) Scan(raw interface{}) error {
238	switch v := raw.(type) {
239	case []byte:
240		dbuf := make([]byte, base64.StdEncoding.DecodedLen(len(v)))
241		n, err := base64.StdEncoding.Decode(dbuf, v)
242		if err != nil {
243			return err
244		}
245		*b = dbuf[:n]
246	case string:
247		vv, err := base64.StdEncoding.DecodeString(v)
248		if err != nil {
249			return err
250		}
251		*b = Base64(vv)
252	default:
253		return fmt.Errorf("cannot sql.Scan() strfmt.Base64 from: %#v", v)
254	}
255
256	return nil
257}
258
259func (b Base64) String() string {
260	return base64.StdEncoding.EncodeToString([]byte(b))
261}
262
263// MarshalJSON returns the Base64 as JSON
264func (b Base64) MarshalJSON() ([]byte, error) {
265	return json.Marshal(b.String())
266}
267
268// UnmarshalJSON sets the Base64 from JSON
269func (b *Base64) UnmarshalJSON(data []byte) error {
270	var b64str string
271	if err := json.Unmarshal(data, &b64str); err != nil {
272		return err
273	}
274	vb, err := base64.StdEncoding.DecodeString(b64str)
275	if err != nil {
276		return err
277	}
278	*b = Base64(vb)
279	return nil
280}
281
282// DeepCopyInto copies the receiver and writes its value into out.
283func (b *Base64) DeepCopyInto(out *Base64) {
284	*out = *b
285}
286
287// DeepCopy copies the receiver into a new Base64.
288func (b *Base64) DeepCopy() *Base64 {
289	if b == nil {
290		return nil
291	}
292	out := new(Base64)
293	b.DeepCopyInto(out)
294	return out
295}
296
297// URI represents the uri string format as specified by the json schema spec
298//
299// swagger:strfmt uri
300type URI string
301
302// MarshalText turns this instance into text
303func (u URI) MarshalText() ([]byte, error) {
304	return []byte(string(u)), nil
305}
306
307// UnmarshalText hydrates this instance from text
308func (u *URI) UnmarshalText(data []byte) error { // validation is performed later on
309	*u = URI(string(data))
310	return nil
311}
312
313// Scan read a value from a database driver
314func (u *URI) Scan(raw interface{}) error {
315	switch v := raw.(type) {
316	case []byte:
317		*u = URI(string(v))
318	case string:
319		*u = URI(v)
320	default:
321		return fmt.Errorf("cannot sql.Scan() strfmt.URI from: %#v", v)
322	}
323
324	return nil
325}
326
327func (u URI) String() string {
328	return string(u)
329}
330
331// MarshalJSON returns the URI as JSON
332func (u URI) MarshalJSON() ([]byte, error) {
333	return json.Marshal(string(u))
334}
335
336// UnmarshalJSON sets the URI from JSON
337func (u *URI) UnmarshalJSON(data []byte) error {
338	var uristr string
339	if err := json.Unmarshal(data, &uristr); err != nil {
340		return err
341	}
342	*u = URI(uristr)
343	return nil
344}
345
346// DeepCopyInto copies the receiver and writes its value into out.
347func (u *URI) DeepCopyInto(out *URI) {
348	*out = *u
349}
350
351// DeepCopy copies the receiver into a new URI.
352func (u *URI) DeepCopy() *URI {
353	if u == nil {
354		return nil
355	}
356	out := new(URI)
357	u.DeepCopyInto(out)
358	return out
359}
360
361// Email represents the email string format as specified by the json schema spec
362//
363// swagger:strfmt email
364type Email string
365
366// MarshalText turns this instance into text
367func (e Email) MarshalText() ([]byte, error) {
368	return []byte(string(e)), nil
369}
370
371// UnmarshalText hydrates this instance from text
372func (e *Email) UnmarshalText(data []byte) error { // validation is performed later on
373	*e = Email(string(data))
374	return nil
375}
376
377// Scan read a value from a database driver
378func (e *Email) Scan(raw interface{}) error {
379	switch v := raw.(type) {
380	case []byte:
381		*e = Email(string(v))
382	case string:
383		*e = Email(v)
384	default:
385		return fmt.Errorf("cannot sql.Scan() strfmt.Email from: %#v", v)
386	}
387
388	return nil
389}
390
391func (e Email) String() string {
392	return string(e)
393}
394
395// MarshalJSON returns the Email as JSON
396func (e Email) MarshalJSON() ([]byte, error) {
397	return json.Marshal(string(e))
398}
399
400// UnmarshalJSON sets the Email from JSON
401func (e *Email) UnmarshalJSON(data []byte) error {
402	var estr string
403	if err := json.Unmarshal(data, &estr); err != nil {
404		return err
405	}
406	*e = Email(estr)
407	return nil
408}
409
410// DeepCopyInto copies the receiver and writes its value into out.
411func (e *Email) DeepCopyInto(out *Email) {
412	*out = *e
413}
414
415// DeepCopy copies the receiver into a new Email.
416func (e *Email) DeepCopy() *Email {
417	if e == nil {
418		return nil
419	}
420	out := new(Email)
421	e.DeepCopyInto(out)
422	return out
423}
424
425// Hostname represents the hostname string format as specified by the json schema spec
426//
427// swagger:strfmt hostname
428type Hostname string
429
430// MarshalText turns this instance into text
431func (h Hostname) MarshalText() ([]byte, error) {
432	return []byte(string(h)), nil
433}
434
435// UnmarshalText hydrates this instance from text
436func (h *Hostname) UnmarshalText(data []byte) error { // validation is performed later on
437	*h = Hostname(string(data))
438	return nil
439}
440
441// Scan read a value from a database driver
442func (h *Hostname) Scan(raw interface{}) error {
443	switch v := raw.(type) {
444	case []byte:
445		*h = Hostname(string(v))
446	case string:
447		*h = Hostname(v)
448	default:
449		return fmt.Errorf("cannot sql.Scan() strfmt.Hostname from: %#v", v)
450	}
451
452	return nil
453}
454
455func (h Hostname) String() string {
456	return string(h)
457}
458
459// MarshalJSON returns the Hostname as JSON
460func (h Hostname) MarshalJSON() ([]byte, error) {
461	return json.Marshal(string(h))
462}
463
464// UnmarshalJSON sets the Hostname from JSON
465func (h *Hostname) UnmarshalJSON(data []byte) error {
466	var hstr string
467	if err := json.Unmarshal(data, &hstr); err != nil {
468		return err
469	}
470	*h = Hostname(hstr)
471	return nil
472}
473
474// DeepCopyInto copies the receiver and writes its value into out.
475func (h *Hostname) DeepCopyInto(out *Hostname) {
476	*out = *h
477}
478
479// DeepCopy copies the receiver into a new Hostname.
480func (h *Hostname) DeepCopy() *Hostname {
481	if h == nil {
482		return nil
483	}
484	out := new(Hostname)
485	h.DeepCopyInto(out)
486	return out
487}
488
489// IPv4 represents an IP v4 address
490//
491// swagger:strfmt ipv4
492type IPv4 string
493
494// MarshalText turns this instance into text
495func (u IPv4) MarshalText() ([]byte, error) {
496	return []byte(string(u)), nil
497}
498
499// UnmarshalText hydrates this instance from text
500func (u *IPv4) UnmarshalText(data []byte) error { // validation is performed later on
501	*u = IPv4(string(data))
502	return nil
503}
504
505// Scan read a value from a database driver
506func (u *IPv4) Scan(raw interface{}) error {
507	switch v := raw.(type) {
508	case []byte:
509		*u = IPv4(string(v))
510	case string:
511		*u = IPv4(v)
512	default:
513		return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
514	}
515
516	return nil
517}
518
519func (u IPv4) String() string {
520	return string(u)
521}
522
523// MarshalJSON returns the IPv4 as JSON
524func (u IPv4) MarshalJSON() ([]byte, error) {
525	return json.Marshal(string(u))
526}
527
528// UnmarshalJSON sets the IPv4 from JSON
529func (u *IPv4) UnmarshalJSON(data []byte) error {
530	var ustr string
531	if err := json.Unmarshal(data, &ustr); err != nil {
532		return err
533	}
534	*u = IPv4(ustr)
535	return nil
536}
537
538// DeepCopyInto copies the receiver and writes its value into out.
539func (u *IPv4) DeepCopyInto(out *IPv4) {
540	*out = *u
541}
542
543// DeepCopy copies the receiver into a new IPv4.
544func (u *IPv4) DeepCopy() *IPv4 {
545	if u == nil {
546		return nil
547	}
548	out := new(IPv4)
549	u.DeepCopyInto(out)
550	return out
551}
552
553// IPv6 represents an IP v6 address
554//
555// swagger:strfmt ipv6
556type IPv6 string
557
558// MarshalText turns this instance into text
559func (u IPv6) MarshalText() ([]byte, error) {
560	return []byte(string(u)), nil
561}
562
563// UnmarshalText hydrates this instance from text
564func (u *IPv6) UnmarshalText(data []byte) error { // validation is performed later on
565	*u = IPv6(string(data))
566	return nil
567}
568
569// Scan read a value from a database driver
570func (u *IPv6) Scan(raw interface{}) error {
571	switch v := raw.(type) {
572	case []byte:
573		*u = IPv6(string(v))
574	case string:
575		*u = IPv6(v)
576	default:
577		return fmt.Errorf("cannot sql.Scan() strfmt.IPv6 from: %#v", v)
578	}
579
580	return nil
581}
582
583func (u IPv6) String() string {
584	return string(u)
585}
586
587// MarshalJSON returns the IPv6 as JSON
588func (u IPv6) MarshalJSON() ([]byte, error) {
589	return json.Marshal(string(u))
590}
591
592// UnmarshalJSON sets the IPv6 from JSON
593func (u *IPv6) UnmarshalJSON(data []byte) error {
594	var ustr string
595	if err := json.Unmarshal(data, &ustr); err != nil {
596		return err
597	}
598	*u = IPv6(ustr)
599	return nil
600}
601
602// DeepCopyInto copies the receiver and writes its value into out.
603func (u *IPv6) DeepCopyInto(out *IPv6) {
604	*out = *u
605}
606
607// DeepCopy copies the receiver into a new IPv6.
608func (u *IPv6) DeepCopy() *IPv6 {
609	if u == nil {
610		return nil
611	}
612	out := new(IPv6)
613	u.DeepCopyInto(out)
614	return out
615}
616
617// CIDR represents a Classless Inter-Domain Routing notation
618//
619// swagger:strfmt cidr
620type CIDR string
621
622// MarshalText turns this instance into text
623func (u CIDR) MarshalText() ([]byte, error) {
624	return []byte(string(u)), nil
625}
626
627// UnmarshalText hydrates this instance from text
628func (u *CIDR) UnmarshalText(data []byte) error { // validation is performed later on
629	*u = CIDR(string(data))
630	return nil
631}
632
633// Scan read a value from a database driver
634func (u *CIDR) Scan(raw interface{}) error {
635	switch v := raw.(type) {
636	case []byte:
637		*u = CIDR(string(v))
638	case string:
639		*u = CIDR(v)
640	default:
641		return fmt.Errorf("cannot sql.Scan() strfmt.CIDR from: %#v", v)
642	}
643
644	return nil
645}
646
647func (u CIDR) String() string {
648	return string(u)
649}
650
651// MarshalJSON returns the CIDR as JSON
652func (u CIDR) MarshalJSON() ([]byte, error) {
653	return json.Marshal(string(u))
654}
655
656// UnmarshalJSON sets the CIDR from JSON
657func (u *CIDR) UnmarshalJSON(data []byte) error {
658	var ustr string
659	if err := json.Unmarshal(data, &ustr); err != nil {
660		return err
661	}
662	*u = CIDR(ustr)
663	return nil
664}
665
666// DeepCopyInto copies the receiver and writes its value into out.
667func (u *CIDR) DeepCopyInto(out *CIDR) {
668	*out = *u
669}
670
671// DeepCopy copies the receiver into a new CIDR.
672func (u *CIDR) DeepCopy() *CIDR {
673	if u == nil {
674		return nil
675	}
676	out := new(CIDR)
677	u.DeepCopyInto(out)
678	return out
679}
680
681// MAC represents a 48 bit MAC address
682//
683// swagger:strfmt mac
684type MAC string
685
686// MarshalText turns this instance into text
687func (u MAC) MarshalText() ([]byte, error) {
688	return []byte(string(u)), nil
689}
690
691// UnmarshalText hydrates this instance from text
692func (u *MAC) UnmarshalText(data []byte) error { // validation is performed later on
693	*u = MAC(string(data))
694	return nil
695}
696
697// Scan read a value from a database driver
698func (u *MAC) Scan(raw interface{}) error {
699	switch v := raw.(type) {
700	case []byte:
701		*u = MAC(string(v))
702	case string:
703		*u = MAC(v)
704	default:
705		return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
706	}
707
708	return nil
709}
710
711func (u MAC) String() string {
712	return string(u)
713}
714
715// MarshalJSON returns the MAC as JSON
716func (u MAC) MarshalJSON() ([]byte, error) {
717	return json.Marshal(string(u))
718}
719
720// UnmarshalJSON sets the MAC from JSON
721func (u *MAC) UnmarshalJSON(data []byte) error {
722	var ustr string
723	if err := json.Unmarshal(data, &ustr); err != nil {
724		return err
725	}
726	*u = MAC(ustr)
727	return nil
728}
729
730// DeepCopyInto copies the receiver and writes its value into out.
731func (u *MAC) DeepCopyInto(out *MAC) {
732	*out = *u
733}
734
735// DeepCopy copies the receiver into a new MAC.
736func (u *MAC) DeepCopy() *MAC {
737	if u == nil {
738		return nil
739	}
740	out := new(MAC)
741	u.DeepCopyInto(out)
742	return out
743}
744
745// UUID represents a uuid string format
746//
747// swagger:strfmt uuid
748type UUID string
749
750// MarshalText turns this instance into text
751func (u UUID) MarshalText() ([]byte, error) {
752	return []byte(string(u)), nil
753}
754
755// UnmarshalText hydrates this instance from text
756func (u *UUID) UnmarshalText(data []byte) error { // validation is performed later on
757	*u = UUID(string(data))
758	return nil
759}
760
761// Scan read a value from a database driver
762func (u *UUID) Scan(raw interface{}) error {
763	switch v := raw.(type) {
764	case []byte:
765		*u = UUID(string(v))
766	case string:
767		*u = UUID(v)
768	default:
769		return fmt.Errorf("cannot sql.Scan() strfmt.UUID from: %#v", v)
770	}
771
772	return nil
773}
774
775func (u UUID) String() string {
776	return string(u)
777}
778
779// MarshalJSON returns the UUID as JSON
780func (u UUID) MarshalJSON() ([]byte, error) {
781	return json.Marshal(string(u))
782}
783
784// UnmarshalJSON sets the UUID from JSON
785func (u *UUID) UnmarshalJSON(data []byte) error {
786	if string(data) == jsonNull {
787		return nil
788	}
789	var ustr string
790	if err := json.Unmarshal(data, &ustr); err != nil {
791		return err
792	}
793	*u = UUID(ustr)
794	return nil
795}
796
797// DeepCopyInto copies the receiver and writes its value into out.
798func (u *UUID) DeepCopyInto(out *UUID) {
799	*out = *u
800}
801
802// DeepCopy copies the receiver into a new UUID.
803func (u *UUID) DeepCopy() *UUID {
804	if u == nil {
805		return nil
806	}
807	out := new(UUID)
808	u.DeepCopyInto(out)
809	return out
810}
811
812// UUID3 represents a uuid3 string format
813//
814// swagger:strfmt uuid3
815type UUID3 string
816
817// MarshalText turns this instance into text
818func (u UUID3) MarshalText() ([]byte, error) {
819	return []byte(string(u)), nil
820}
821
822// UnmarshalText hydrates this instance from text
823func (u *UUID3) UnmarshalText(data []byte) error { // validation is performed later on
824	*u = UUID3(string(data))
825	return nil
826}
827
828// Scan read a value from a database driver
829func (u *UUID3) Scan(raw interface{}) error {
830	switch v := raw.(type) {
831	case []byte:
832		*u = UUID3(string(v))
833	case string:
834		*u = UUID3(v)
835	default:
836		return fmt.Errorf("cannot sql.Scan() strfmt.UUID3 from: %#v", v)
837	}
838
839	return nil
840}
841
842func (u UUID3) String() string {
843	return string(u)
844}
845
846// MarshalJSON returns the UUID as JSON
847func (u UUID3) MarshalJSON() ([]byte, error) {
848	return json.Marshal(string(u))
849}
850
851// UnmarshalJSON sets the UUID from JSON
852func (u *UUID3) UnmarshalJSON(data []byte) error {
853	if string(data) == jsonNull {
854		return nil
855	}
856	var ustr string
857	if err := json.Unmarshal(data, &ustr); err != nil {
858		return err
859	}
860	*u = UUID3(ustr)
861	return nil
862}
863
864// DeepCopyInto copies the receiver and writes its value into out.
865func (u *UUID3) DeepCopyInto(out *UUID3) {
866	*out = *u
867}
868
869// DeepCopy copies the receiver into a new UUID3.
870func (u *UUID3) DeepCopy() *UUID3 {
871	if u == nil {
872		return nil
873	}
874	out := new(UUID3)
875	u.DeepCopyInto(out)
876	return out
877}
878
879// UUID4 represents a uuid4 string format
880//
881// swagger:strfmt uuid4
882type UUID4 string
883
884// MarshalText turns this instance into text
885func (u UUID4) MarshalText() ([]byte, error) {
886	return []byte(string(u)), nil
887}
888
889// UnmarshalText hydrates this instance from text
890func (u *UUID4) UnmarshalText(data []byte) error { // validation is performed later on
891	*u = UUID4(string(data))
892	return nil
893}
894
895// Scan read a value from a database driver
896func (u *UUID4) Scan(raw interface{}) error {
897	switch v := raw.(type) {
898	case []byte:
899		*u = UUID4(string(v))
900	case string:
901		*u = UUID4(v)
902	default:
903		return fmt.Errorf("cannot sql.Scan() strfmt.UUID4 from: %#v", v)
904	}
905
906	return nil
907}
908
909func (u UUID4) String() string {
910	return string(u)
911}
912
913// MarshalJSON returns the UUID as JSON
914func (u UUID4) MarshalJSON() ([]byte, error) {
915	return json.Marshal(string(u))
916}
917
918// UnmarshalJSON sets the UUID from JSON
919func (u *UUID4) UnmarshalJSON(data []byte) error {
920	if string(data) == jsonNull {
921		return nil
922	}
923	var ustr string
924	if err := json.Unmarshal(data, &ustr); err != nil {
925		return err
926	}
927	*u = UUID4(ustr)
928	return nil
929}
930
931// DeepCopyInto copies the receiver and writes its value into out.
932func (u *UUID4) DeepCopyInto(out *UUID4) {
933	*out = *u
934}
935
936// DeepCopy copies the receiver into a new UUID4.
937func (u *UUID4) DeepCopy() *UUID4 {
938	if u == nil {
939		return nil
940	}
941	out := new(UUID4)
942	u.DeepCopyInto(out)
943	return out
944}
945
946// UUID5 represents a uuid5 string format
947//
948// swagger:strfmt uuid5
949type UUID5 string
950
951// MarshalText turns this instance into text
952func (u UUID5) MarshalText() ([]byte, error) {
953	return []byte(string(u)), nil
954}
955
956// UnmarshalText hydrates this instance from text
957func (u *UUID5) UnmarshalText(data []byte) error { // validation is performed later on
958	*u = UUID5(string(data))
959	return nil
960}
961
962// Scan read a value from a database driver
963func (u *UUID5) Scan(raw interface{}) error {
964	switch v := raw.(type) {
965	case []byte:
966		*u = UUID5(string(v))
967	case string:
968		*u = UUID5(v)
969	default:
970		return fmt.Errorf("cannot sql.Scan() strfmt.UUID5 from: %#v", v)
971	}
972
973	return nil
974}
975
976func (u UUID5) String() string {
977	return string(u)
978}
979
980// MarshalJSON returns the UUID as JSON
981func (u UUID5) MarshalJSON() ([]byte, error) {
982	return json.Marshal(string(u))
983}
984
985// UnmarshalJSON sets the UUID from JSON
986func (u *UUID5) UnmarshalJSON(data []byte) error {
987	if string(data) == jsonNull {
988		return nil
989	}
990	var ustr string
991	if err := json.Unmarshal(data, &ustr); err != nil {
992		return err
993	}
994	*u = UUID5(ustr)
995	return nil
996}
997
998// DeepCopyInto copies the receiver and writes its value into out.
999func (u *UUID5) DeepCopyInto(out *UUID5) {
1000	*out = *u
1001}
1002
1003// DeepCopy copies the receiver into a new UUID5.
1004func (u *UUID5) DeepCopy() *UUID5 {
1005	if u == nil {
1006		return nil
1007	}
1008	out := new(UUID5)
1009	u.DeepCopyInto(out)
1010	return out
1011}
1012
1013// ISBN represents an isbn string format
1014//
1015// swagger:strfmt isbn
1016type ISBN string
1017
1018// MarshalText turns this instance into text
1019func (u ISBN) MarshalText() ([]byte, error) {
1020	return []byte(string(u)), nil
1021}
1022
1023// UnmarshalText hydrates this instance from text
1024func (u *ISBN) UnmarshalText(data []byte) error { // validation is performed later on
1025	*u = ISBN(string(data))
1026	return nil
1027}
1028
1029// Scan read a value from a database driver
1030func (u *ISBN) Scan(raw interface{}) error {
1031	switch v := raw.(type) {
1032	case []byte:
1033		*u = ISBN(string(v))
1034	case string:
1035		*u = ISBN(v)
1036	default:
1037		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN from: %#v", v)
1038	}
1039
1040	return nil
1041}
1042
1043func (u ISBN) String() string {
1044	return string(u)
1045}
1046
1047// MarshalJSON returns the ISBN as JSON
1048func (u ISBN) MarshalJSON() ([]byte, error) {
1049	return json.Marshal(string(u))
1050}
1051
1052// UnmarshalJSON sets the ISBN from JSON
1053func (u *ISBN) UnmarshalJSON(data []byte) error {
1054	if string(data) == jsonNull {
1055		return nil
1056	}
1057	var ustr string
1058	if err := json.Unmarshal(data, &ustr); err != nil {
1059		return err
1060	}
1061	*u = ISBN(ustr)
1062	return nil
1063}
1064
1065// DeepCopyInto copies the receiver and writes its value into out.
1066func (u *ISBN) DeepCopyInto(out *ISBN) {
1067	*out = *u
1068}
1069
1070// DeepCopy copies the receiver into a new ISBN.
1071func (u *ISBN) DeepCopy() *ISBN {
1072	if u == nil {
1073		return nil
1074	}
1075	out := new(ISBN)
1076	u.DeepCopyInto(out)
1077	return out
1078}
1079
1080// ISBN10 represents an isbn 10 string format
1081//
1082// swagger:strfmt isbn10
1083type ISBN10 string
1084
1085// MarshalText turns this instance into text
1086func (u ISBN10) MarshalText() ([]byte, error) {
1087	return []byte(string(u)), nil
1088}
1089
1090// UnmarshalText hydrates this instance from text
1091func (u *ISBN10) UnmarshalText(data []byte) error { // validation is performed later on
1092	*u = ISBN10(string(data))
1093	return nil
1094}
1095
1096// Scan read a value from a database driver
1097func (u *ISBN10) Scan(raw interface{}) error {
1098	switch v := raw.(type) {
1099	case []byte:
1100		*u = ISBN10(string(v))
1101	case string:
1102		*u = ISBN10(v)
1103	default:
1104		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN10 from: %#v", v)
1105	}
1106
1107	return nil
1108}
1109
1110func (u ISBN10) String() string {
1111	return string(u)
1112}
1113
1114// MarshalJSON returns the ISBN10 as JSON
1115func (u ISBN10) MarshalJSON() ([]byte, error) {
1116	return json.Marshal(string(u))
1117}
1118
1119// UnmarshalJSON sets the ISBN10 from JSON
1120func (u *ISBN10) UnmarshalJSON(data []byte) error {
1121	if string(data) == jsonNull {
1122		return nil
1123	}
1124	var ustr string
1125	if err := json.Unmarshal(data, &ustr); err != nil {
1126		return err
1127	}
1128	*u = ISBN10(ustr)
1129	return nil
1130}
1131
1132// DeepCopyInto copies the receiver and writes its value into out.
1133func (u *ISBN10) DeepCopyInto(out *ISBN10) {
1134	*out = *u
1135}
1136
1137// DeepCopy copies the receiver into a new ISBN10.
1138func (u *ISBN10) DeepCopy() *ISBN10 {
1139	if u == nil {
1140		return nil
1141	}
1142	out := new(ISBN10)
1143	u.DeepCopyInto(out)
1144	return out
1145}
1146
1147// ISBN13 represents an isbn 13 string format
1148//
1149// swagger:strfmt isbn13
1150type ISBN13 string
1151
1152// MarshalText turns this instance into text
1153func (u ISBN13) MarshalText() ([]byte, error) {
1154	return []byte(string(u)), nil
1155}
1156
1157// UnmarshalText hydrates this instance from text
1158func (u *ISBN13) UnmarshalText(data []byte) error { // validation is performed later on
1159	*u = ISBN13(string(data))
1160	return nil
1161}
1162
1163// Scan read a value from a database driver
1164func (u *ISBN13) Scan(raw interface{}) error {
1165	switch v := raw.(type) {
1166	case []byte:
1167		*u = ISBN13(string(v))
1168	case string:
1169		*u = ISBN13(v)
1170	default:
1171		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN13 from: %#v", v)
1172	}
1173
1174	return nil
1175}
1176
1177func (u ISBN13) String() string {
1178	return string(u)
1179}
1180
1181// MarshalJSON returns the ISBN13 as JSON
1182func (u ISBN13) MarshalJSON() ([]byte, error) {
1183	return json.Marshal(string(u))
1184}
1185
1186// UnmarshalJSON sets the ISBN13 from JSON
1187func (u *ISBN13) UnmarshalJSON(data []byte) error {
1188	if string(data) == jsonNull {
1189		return nil
1190	}
1191	var ustr string
1192	if err := json.Unmarshal(data, &ustr); err != nil {
1193		return err
1194	}
1195	*u = ISBN13(ustr)
1196	return nil
1197}
1198
1199// DeepCopyInto copies the receiver and writes its value into out.
1200func (u *ISBN13) DeepCopyInto(out *ISBN13) {
1201	*out = *u
1202}
1203
1204// DeepCopy copies the receiver into a new ISBN13.
1205func (u *ISBN13) DeepCopy() *ISBN13 {
1206	if u == nil {
1207		return nil
1208	}
1209	out := new(ISBN13)
1210	u.DeepCopyInto(out)
1211	return out
1212}
1213
1214// CreditCard represents a credit card string format
1215//
1216// swagger:strfmt creditcard
1217type CreditCard string
1218
1219// MarshalText turns this instance into text
1220func (u CreditCard) MarshalText() ([]byte, error) {
1221	return []byte(string(u)), nil
1222}
1223
1224// UnmarshalText hydrates this instance from text
1225func (u *CreditCard) UnmarshalText(data []byte) error { // validation is performed later on
1226	*u = CreditCard(string(data))
1227	return nil
1228}
1229
1230// Scan read a value from a database driver
1231func (u *CreditCard) Scan(raw interface{}) error {
1232	switch v := raw.(type) {
1233	case []byte:
1234		*u = CreditCard(string(v))
1235	case string:
1236		*u = CreditCard(v)
1237	default:
1238		return fmt.Errorf("cannot sql.Scan() strfmt.CreditCard from: %#v", v)
1239	}
1240
1241	return nil
1242}
1243
1244func (u CreditCard) String() string {
1245	return string(u)
1246}
1247
1248// MarshalJSON returns the CreditCard as JSON
1249func (u CreditCard) MarshalJSON() ([]byte, error) {
1250	return json.Marshal(string(u))
1251}
1252
1253// UnmarshalJSON sets the CreditCard from JSON
1254func (u *CreditCard) UnmarshalJSON(data []byte) error {
1255	if string(data) == jsonNull {
1256		return nil
1257	}
1258	var ustr string
1259	if err := json.Unmarshal(data, &ustr); err != nil {
1260		return err
1261	}
1262	*u = CreditCard(ustr)
1263	return nil
1264}
1265
1266// DeepCopyInto copies the receiver and writes its value into out.
1267func (u *CreditCard) DeepCopyInto(out *CreditCard) {
1268	*out = *u
1269}
1270
1271// DeepCopy copies the receiver into a new CreditCard.
1272func (u *CreditCard) DeepCopy() *CreditCard {
1273	if u == nil {
1274		return nil
1275	}
1276	out := new(CreditCard)
1277	u.DeepCopyInto(out)
1278	return out
1279}
1280
1281// SSN represents a social security string format
1282//
1283// swagger:strfmt ssn
1284type SSN string
1285
1286// MarshalText turns this instance into text
1287func (u SSN) MarshalText() ([]byte, error) {
1288	return []byte(string(u)), nil
1289}
1290
1291// UnmarshalText hydrates this instance from text
1292func (u *SSN) UnmarshalText(data []byte) error { // validation is performed later on
1293	*u = SSN(string(data))
1294	return nil
1295}
1296
1297// Scan read a value from a database driver
1298func (u *SSN) Scan(raw interface{}) error {
1299	switch v := raw.(type) {
1300	case []byte:
1301		*u = SSN(string(v))
1302	case string:
1303		*u = SSN(v)
1304	default:
1305		return fmt.Errorf("cannot sql.Scan() strfmt.SSN from: %#v", v)
1306	}
1307
1308	return nil
1309}
1310
1311func (u SSN) String() string {
1312	return string(u)
1313}
1314
1315// MarshalJSON returns the SSN as JSON
1316func (u SSN) MarshalJSON() ([]byte, error) {
1317	return json.Marshal(string(u))
1318}
1319
1320// UnmarshalJSON sets the SSN from JSON
1321func (u *SSN) UnmarshalJSON(data []byte) error {
1322	if string(data) == jsonNull {
1323		return nil
1324	}
1325	var ustr string
1326	if err := json.Unmarshal(data, &ustr); err != nil {
1327		return err
1328	}
1329	*u = SSN(ustr)
1330	return nil
1331}
1332
1333// DeepCopyInto copies the receiver and writes its value into out.
1334func (u *SSN) DeepCopyInto(out *SSN) {
1335	*out = *u
1336}
1337
1338// DeepCopy copies the receiver into a new SSN.
1339func (u *SSN) DeepCopy() *SSN {
1340	if u == nil {
1341		return nil
1342	}
1343	out := new(SSN)
1344	u.DeepCopyInto(out)
1345	return out
1346}
1347
1348// HexColor represents a hex color string format
1349//
1350// swagger:strfmt hexcolor
1351type HexColor string
1352
1353// MarshalText turns this instance into text
1354func (h HexColor) MarshalText() ([]byte, error) {
1355	return []byte(string(h)), nil
1356}
1357
1358// UnmarshalText hydrates this instance from text
1359func (h *HexColor) UnmarshalText(data []byte) error { // validation is performed later on
1360	*h = HexColor(string(data))
1361	return nil
1362}
1363
1364// Scan read a value from a database driver
1365func (h *HexColor) Scan(raw interface{}) error {
1366	switch v := raw.(type) {
1367	case []byte:
1368		*h = HexColor(string(v))
1369	case string:
1370		*h = HexColor(v)
1371	default:
1372		return fmt.Errorf("cannot sql.Scan() strfmt.HexColor from: %#v", v)
1373	}
1374
1375	return nil
1376}
1377
1378func (h HexColor) String() string {
1379	return string(h)
1380}
1381
1382// MarshalJSON returns the HexColor as JSON
1383func (h HexColor) MarshalJSON() ([]byte, error) {
1384	return json.Marshal(string(h))
1385}
1386
1387// UnmarshalJSON sets the HexColor from JSON
1388func (h *HexColor) UnmarshalJSON(data []byte) error {
1389	if string(data) == jsonNull {
1390		return nil
1391	}
1392	var ustr string
1393	if err := json.Unmarshal(data, &ustr); err != nil {
1394		return err
1395	}
1396	*h = HexColor(ustr)
1397	return nil
1398}
1399
1400// DeepCopyInto copies the receiver and writes its value into out.
1401func (h *HexColor) DeepCopyInto(out *HexColor) {
1402	*out = *h
1403}
1404
1405// DeepCopy copies the receiver into a new HexColor.
1406func (h *HexColor) DeepCopy() *HexColor {
1407	if h == nil {
1408		return nil
1409	}
1410	out := new(HexColor)
1411	h.DeepCopyInto(out)
1412	return out
1413}
1414
1415// RGBColor represents a RGB color string format
1416//
1417// swagger:strfmt rgbcolor
1418type RGBColor string
1419
1420// MarshalText turns this instance into text
1421func (r RGBColor) MarshalText() ([]byte, error) {
1422	return []byte(string(r)), nil
1423}
1424
1425// UnmarshalText hydrates this instance from text
1426func (r *RGBColor) UnmarshalText(data []byte) error { // validation is performed later on
1427	*r = RGBColor(string(data))
1428	return nil
1429}
1430
1431// Scan read a value from a database driver
1432func (r *RGBColor) Scan(raw interface{}) error {
1433	switch v := raw.(type) {
1434	case []byte:
1435		*r = RGBColor(string(v))
1436	case string:
1437		*r = RGBColor(v)
1438	default:
1439		return fmt.Errorf("cannot sql.Scan() strfmt.RGBColor from: %#v", v)
1440	}
1441
1442	return nil
1443}
1444
1445func (r RGBColor) String() string {
1446	return string(r)
1447}
1448
1449// MarshalJSON returns the RGBColor as JSON
1450func (r RGBColor) MarshalJSON() ([]byte, error) {
1451	return json.Marshal(string(r))
1452}
1453
1454// UnmarshalJSON sets the RGBColor from JSON
1455func (r *RGBColor) UnmarshalJSON(data []byte) error {
1456	if string(data) == jsonNull {
1457		return nil
1458	}
1459	var ustr string
1460	if err := json.Unmarshal(data, &ustr); err != nil {
1461		return err
1462	}
1463	*r = RGBColor(ustr)
1464	return nil
1465}
1466
1467// DeepCopyInto copies the receiver and writes its value into out.
1468func (r *RGBColor) DeepCopyInto(out *RGBColor) {
1469	*out = *r
1470}
1471
1472// DeepCopy copies the receiver into a new RGBColor.
1473func (r *RGBColor) DeepCopy() *RGBColor {
1474	if r == nil {
1475		return nil
1476	}
1477	out := new(RGBColor)
1478	r.DeepCopyInto(out)
1479	return out
1480}
1481
1482// Password represents a password.
1483// This has no validations and is mainly used as a marker for UI components.
1484//
1485// swagger:strfmt password
1486type Password string
1487
1488// MarshalText turns this instance into text
1489func (r Password) MarshalText() ([]byte, error) {
1490	return []byte(string(r)), nil
1491}
1492
1493// UnmarshalText hydrates this instance from text
1494func (r *Password) UnmarshalText(data []byte) error { // validation is performed later on
1495	*r = Password(string(data))
1496	return nil
1497}
1498
1499// Scan read a value from a database driver
1500func (r *Password) Scan(raw interface{}) error {
1501	switch v := raw.(type) {
1502	case []byte:
1503		*r = Password(string(v))
1504	case string:
1505		*r = Password(v)
1506	default:
1507		return fmt.Errorf("cannot sql.Scan() strfmt.Password from: %#v", v)
1508	}
1509
1510	return nil
1511}
1512
1513func (r Password) String() string {
1514	return string(r)
1515}
1516
1517// MarshalJSON returns the Password as JSON
1518func (r Password) MarshalJSON() ([]byte, error) {
1519	return json.Marshal(string(r))
1520}
1521
1522// UnmarshalJSON sets the Password from JSON
1523func (r *Password) UnmarshalJSON(data []byte) error {
1524	if string(data) == jsonNull {
1525		return nil
1526	}
1527	var ustr string
1528	if err := json.Unmarshal(data, &ustr); err != nil {
1529		return err
1530	}
1531	*r = Password(ustr)
1532	return nil
1533}
1534
1535// DeepCopyInto copies the receiver and writes its value into out.
1536func (r *Password) DeepCopyInto(out *Password) {
1537	*out = *r
1538}
1539
1540// DeepCopy copies the receiver into a new Password.
1541func (r *Password) DeepCopy() *Password {
1542	if r == nil {
1543		return nil
1544	}
1545	out := new(Password)
1546	r.DeepCopyInto(out)
1547	return out
1548}
1549