From c282fe0177fcfc72398a09835977e81bedfeb7b8 Mon Sep 17 00:00:00 2001 From: Thorsten Riess Date: Sat, 22 May 2021 10:56:45 +0200 Subject: [PATCH 1/3] Extend struct tags with custom type and format --- parser.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parser.go b/parser.go index 402eb57..3377bf2 100644 --- a/parser.go +++ b/parser.go @@ -1150,6 +1150,16 @@ astFieldsLoop: fieldSchema.Deprecated = true continue astFieldsLoop } + if kv := strings.Split(v, "="); len(kv) == 2 { + switch kv[0] { + case "type": + fieldSchema.Type = kv[1] + fieldSchema.Ref = "" + + case "format": + fieldSchema.Format = kv[1] + } + } } if tag := astFieldTag.Get("json"); tag != "" { From e2e857a8219643840bfd3002c887854e6c0e6e31 Mon Sep 17 00:00:00 2001 From: Thorsten Riess Date: Thu, 27 May 2021 15:40:26 +0200 Subject: [PATCH 2/3] Also add the nullable property to the SchemaObject definition --- oas.go | 2 +- parser.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/oas.go b/oas.go index 94e1d34..0762ee6 100644 --- a/oas.go +++ b/oas.go @@ -144,6 +144,7 @@ type SchemaObject struct { Items *SchemaObject `json:"items,omitempty"` // use ptr to prevent recursive error Example interface{} `json:"example,omitempty"` Deprecated bool `json:"deprecated,omitempty"` + Nullable bool `json:"nullable,omitempty"` // Ref is used when SchemaObject is as a ReferenceObject Ref string `json:"$ref,omitempty"` @@ -170,7 +171,6 @@ type SchemaObject struct { // AdditionalProperties // Description // Default - // Nullable // ReadOnly // WriteOnly // XML diff --git a/parser.go b/parser.go index 3377bf2..ad6ad0c 100644 --- a/parser.go +++ b/parser.go @@ -1158,6 +1158,9 @@ astFieldsLoop: case "format": fieldSchema.Format = kv[1] + + case "nullable": + fieldSchema.Nullable, _ = strconv.ParseBool(kv[1]) } } } From e6e1c730475e7b5fee92128ccddd969cc58f4fa9 Mon Sep 17 00:00:00 2001 From: Thorsten Riess Date: Thu, 27 May 2021 15:41:22 +0200 Subject: [PATCH 3/3] Fix indent --- oas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oas.go b/oas.go index 0762ee6..c59226a 100644 --- a/oas.go +++ b/oas.go @@ -144,7 +144,7 @@ type SchemaObject struct { Items *SchemaObject `json:"items,omitempty"` // use ptr to prevent recursive error Example interface{} `json:"example,omitempty"` Deprecated bool `json:"deprecated,omitempty"` - Nullable bool `json:"nullable,omitempty"` + Nullable bool `json:"nullable,omitempty"` // Ref is used when SchemaObject is as a ReferenceObject Ref string `json:"$ref,omitempty"`