Repository: getkin/kin-openapi
Pull request #138 (2019-11-01 23:36:38)

Tags at the root
This moves tags in v3 from `components` to the root.  See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object.


Patch:
diff --git a/openapi2/openapi2.go b/openapi2/openapi2.go
index ebe1be9..792f693 100644
--- a/openapi2/openapi2.go
+++ b/openapi2/openapi2.go
@@ -155,7 +155,7 @@ type Parameter struct {
 	MinLength    uint64              `json:"minLength,omitempty"`
 	MaxLength    *uint64             `json:"maxLength,omitempty"`
 	Pattern      string              `json:"pattern,omitempty"`
-	Default      string              `json:"default,omitempty"`
+	Default      interface{}         `json:"default,omitempty"`
 }
 
 type Response struct {
diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go
index d9395e8..97a0e71 100644
--- a/openapi2conv/openapi2_conv.go
+++ b/openapi2conv/openapi2_conv.go
@@ -12,11 +12,10 @@ import (
 
 func ToV3Swagger(swagger *openapi2.Swagger) (*openapi3.Swagger, error) {
 	result := &openapi3.Swagger{
-		OpenAPI: "3.0",
-		Info:    &swagger.Info,
-		Components: openapi3.Components{
-			Tags: swagger.Tags,
-		},
+		OpenAPI:    "3.0",
+		Info:       &swagger.Info,
+		Components: openapi3.Components{},
+		Tags:       swagger.Tags,
 	}
 	host := swagger.Host
 	if len(host) > 0 {
@@ -189,6 +188,7 @@ func ToV3Parameter(parameter *openapi2.Parameter) (*openapi3.ParameterRef, *open
 				ExclusiveMax: parameter.ExclusiveMax,
 				MinLength:    parameter.MinLength,
 				MaxLength:    parameter.MaxLength,
+				Default:      parameter.Default,
 			},
 		}
 	}
@@ -273,7 +273,7 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
 func FromV3Swagger(swagger *openapi3.Swagger) (*openapi2.Swagger, error) {
 	result := &openapi2.Swagger{
 		Info: *swagger.Info,
-		Tags: swagger.Components.Tags,
+		Tags: swagger.Tags,
 	}
 	isHTTPS := false
 	isHTTP := false
@@ -461,7 +461,6 @@ func FromV3Parameter(ref *openapi3.ParameterRef) (*openapi2.Parameter, error) {
 		In:          parameter.In,
 		Name:        parameter.Name,
 		Required:    parameter.Required,
-		Schema:      parameter.Schema,
 	}
 	if schemaRef := parameter.Schema; schemaRef != nil {
 		schema := schemaRef.Value
@@ -469,12 +468,13 @@ func FromV3Parameter(ref *openapi3.ParameterRef) (*openapi2.Parameter, error) {
 		result.Format = schema.Format
 		result.Enum = schema.Enum
 		result.Minimum = schema.Min
-		result.Maximum = schema.Min
+		result.Maximum = schema.Max
 		result.ExclusiveMin = schema.ExclusiveMin
 		result.ExclusiveMax = schema.ExclusiveMax
 		result.MinLength = schema.MinLength
 		result.MaxLength = schema.MaxLength
 		result.Pattern = schema.Pattern
+		result.Default = schema.Default
 	}
 	return result, nil
 }
diff --git a/openapi3/components.go b/openapi3/components.go
index 37e9ed2..78b66aa 100644
--- a/openapi3/components.go
+++ b/openapi3/components.go
@@ -18,7 +18,6 @@ type Components struct {
 	Responses       map[string]*ResponseRef       `json:"responses,omitempty" yaml:"responses,omitempty"`
 	SecuritySchemes map[string]*SecuritySchemeRef `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
 	Examples        map[string]*ExampleRef        `json:"examples,omitempty" yaml:"examples,omitempty"`
-	Tags            Tags                          `json:"tags,omitempty" yaml:"tags,omitempty"`
 	Links           map[string]*LinkRef           `json:"links,omitempty" yaml:"links,omitempty"`
 	Callbacks       map[string]*CallbackRef       `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
 }
diff --git a/openapi3/swagger.go b/openapi3/swagger.go
index 24f21e6..6ca8f1e 100644
--- a/openapi3/swagger.go
+++ b/openapi3/swagger.go
@@ -15,6 +15,7 @@ type Swagger struct {
 	Servers      Servers              `json:"servers,omitempty" yaml:"servers,omitempty"`
 	Paths        Paths                `json:"paths" yaml:"paths"` // Required
 	Components   Components           `json:"components,omitempty" yaml:"components,omitempty"`
+	Tags         Tags                 `json:"tags,omitempty" yaml:"tags,omitempty"`
 	Security     SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
 	ExternalDocs *ExternalDocs        `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
 }


Test patch:
diff --git a/openapi2conv/openapi2_conv_test.go b/openapi2conv/openapi2_conv_test.go
index 8b9da3e..84a053c 100644
--- a/openapi2conv/openapi2_conv_test.go
+++ b/openapi2conv/openapi2_conv_test.go
@@ -40,6 +40,12 @@ const exampleV2 = `
   "schemes": ["https"],
   "host": "test.example.com",
   "basePath": "/v2",
+  "tags": [
+    {
+      "name": "Example",
+      "description": "An example tag."
+    }
+  ],
   "paths": {
     "/example": {
       "delete": {
@@ -57,11 +63,23 @@ const exampleV2 = `
         "operationId": "example-get",
         "summary": "example get",
         "description": "example get",
+        "tags": [
+          "Example"
+        ],
         "parameters": [
           {
             "in": "query",
             "name": "x"
           },
+          {
+            "in": "query",
+            "name": "y",
+            "description": "The y parameter",
+            "type": "integer",
+            "minimum": 1,
+            "maximum": 10000,
+            "default": 250
+          },
           {
             "in": "body",
             "name": "body",
@@ -125,6 +143,12 @@ const exampleV3 = `
   "openapi": "3.0",
   "info": {"title":"MyAPI","version":"0.1"},
   "components": {},
+  "tags": [
+    {
+      "name": "Example",
+      "description": "An example tag."
+    }
+  ],
   "servers": [
     {
       "url": "https://test.example.com/v2"
@@ -147,10 +171,24 @@ const exampleV3 = `
         "operationId": "example-get",
         "summary": "example get",
         "description": "example get",
+        "tags": [
+          "Example"
+        ],
         "parameters": [
           {
             "in": "query",
             "name": "x"
+          },
+          {
+            "description": "The y parameter",
+            "in": "query",
+            "name": "y",
+            "schema": {
+              "default": 250,
+              "maximum": 10000,
+              "minimum": 1,
+              "type": "integer"
+            }
           }
         ],
         "requestBody": {