nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: getkin/kin-openapi
Pull request #987 (2024-07-19 19:14:28)

openapi3gen: generate "nullable: true" for pointers
Fixes https://github.com/getkin/kin-openapi/issues/968

endertunc: Hi @fenollp, this should be ready for review. Let me know if you have any feedback!

Patch:
diff --git a/openapi3gen/openapi3gen.go b/openapi3gen/openapi3gen.go
index 9eae7cc..78e6901 100644
--- a/openapi3gen/openapi3gen.go
+++ b/openapi3gen/openapi3gen.go
@@ -195,14 +195,16 @@ func (g *Generator) generateWithoutSaving(parents []*theTypeInfo, t reflect.Type
 			return nil, &CycleError{}
 		}
 	}
-
-	if cap(parents) == 0 {
+	isRoot := cap(parents) == 0
+	if isRoot {
 		parents = make([]*theTypeInfo, 0, 4)
 	}
 	parents = append(parents, typeInfo)
 
+	isNullable := false
 	for t.Kind() == reflect.Ptr {
 		t = t.Elem()
+		isNullable = !isRoot
 	}
 
 	if strings.HasSuffix(t.Name(), "Ref") {
@@ -231,6 +233,7 @@ func (g *Generator) generateWithoutSaving(parents []*theTypeInfo, t reflect.Type
 	}
 
 	schema := &openapi3.Schema{}
+	schema.Nullable = isNullable
 
 	switch t.Kind() {
 	case reflect.Func, reflect.Chan:


Test patch:
diff --git a/openapi3gen/openapi3gen_test.go b/openapi3gen/openapi3gen_test.go
index 8263983..4d9c1e2 100644
--- a/openapi3gen/openapi3gen_test.go
+++ b/openapi3gen/openapi3gen_test.go
@@ -108,11 +108,13 @@ func ExampleGenerator_SchemaRefs() {
 	//     "json": {},
 	//     "map": {
 	//       "additionalProperties": {
+	//         "nullable": true,
 	//         "type": "string"
 	//       },
 	//       "type": "object"
 	//     },
 	//     "ptr": {
+	//       "nullable": true,
 	//       "type": "string"
 	//     },
 	//     "slice": {
@@ -178,6 +180,7 @@ func ExampleThrowErrorOnCycle() {
 	// schemaRef: {
 	//   "properties": {
 	//     "a": {
+	//       "nullable": true,
 	//       "properties": {
 	//         "b": {
 	//           "$ref": "#/components/schemas/CyclicType0"
@@ -192,6 +195,7 @@ func ExampleThrowErrorOnCycle() {
 	//   "CyclicType0": {
 	//     "properties": {
 	//       "a": {
+	//         "nullable": true,
 	//         "properties": {
 	//           "b": {
 	//             "$ref": "#/components/schemas/CyclicType0"
diff --git a/openapi3gen/simple_test.go b/openapi3gen/simple_test.go
index 99e94ae..11b3b26 100644
--- a/openapi3gen/simple_test.go
+++ b/openapi3gen/simple_test.go
@@ -70,11 +70,13 @@ func Example() {
 	//     "json": {},
 	//     "map": {
 	//       "additionalProperties": {
+	//         "nullable": true,
 	//         "type": "string"
 	//       },
 	//       "type": "object"
 	//     },
 	//     "ptr": {
+	//       "nullable": true,
 	//       "type": "string"
 	//     },
 	//     "slice": {
Repository: getkin/kin-openapi
Pull request #990 (2024-07-23 15:20:06)

openapi3filter: Remove inconsistency for arrays in queries
See #989 for details, but in a nutshell:

- DecodeArray returns a []any, which means that whenever DecodeArray returns nil, it will actually return a []interface{nil}
- Viewed from decodeStyledParameter, this is an inconsistent behaviour, since decodeStyledParameter returns nil when the query parameters are empty, AND []interface{nil} when there is at least another parameter set.

I am unsure as to whether this is the best way to fix that issue, and am open to suggestions.

Thanks


Patch:
diff --git a/openapi3filter/req_resp_decoder.go b/openapi3filter/req_resp_decoder.go
index c509def..31fce23 100644
--- a/openapi3filter/req_resp_decoder.go
+++ b/openapi3filter/req_resp_decoder.go
@@ -320,6 +320,10 @@ func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMetho
 		switch {
 		case schema.Value.Type.Is("array"):
 			decodeFn = func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (any, bool, error) {
+				res, b, e := dec.DecodeArray(param, sm, schema)
+				if len(res) == 0 {
+					return nil, b, e
+				}
 				return dec.DecodeArray(param, sm, schema)
 			}
 		case schema.Value.Type.Is("object"):


Test patch:
diff --git a/openapi3filter/req_resp_decoder_test.go b/openapi3filter/req_resp_decoder_test.go
index 6e456d2..5376390 100644
--- a/openapi3filter/req_resp_decoder_test.go
+++ b/openapi3filter/req_resp_decoder_test.go
@@ -878,6 +878,22 @@ func TestDecodeParameter(t *testing.T) {
 					want:  map[string]any{"id": "foo", "name": "bar"},
 					found: true,
 				},
+				{
+					name:  "no param, for arrays",
+					param: &openapi3.Parameter{Name: "something", In: "query", Schema: stringArraySchema},
+					query: "",
+					want:  nil,
+					found: false,
+					err:   nil,
+				},
+				{
+					name:  "missing param, for arrays",
+					param: &openapi3.Parameter{Name: "something", In: "query", Schema: stringArraySchema},
+					query: "foo=bar",
+					want:  nil,
+					found: false,
+					err:   nil,
+				},
 				{
 					name: "deepObject explode additionalProperties with object properties - missing index on nested array",
 					param: &openapi3.Parameter{
Repository: getkin/kin-openapi
Pull request #1008 (2024-08-29 18:14:49)

make form required field order deterministic
The required fields list of a form was generated by iterating over a map, but in Go maps do not seem to have a natural order.  This causes the list of fields to have some randomness to it.  

Everything else so far is deterministic, and we rely on this to determine if the openapi spec needs to be updated

fenollp: LGTM but please add a (regression) test
jlsherrill: added a test that should reliably fail on master but passes with this.  Thanks!

Patch:
diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go
index 0a622f4..fa161bc 100644
--- a/openapi2conv/openapi2_conv.go
+++ b/openapi2conv/openapi2_conv.go
@@ -346,6 +346,7 @@ func formDataBody(bodies map[string]*openapi3.SchemaRef, reqs map[string]bool, c
 			bodies[s] = ref
 		}
 	}
+	sort.Strings(requireds)
 	schema := &openapi3.Schema{
 		Type:       &openapi3.Types{"object"},
 		Properties: ToV3Schemas(bodies),


Test patch:
diff --git a/openapi2conv/issue1008_test.go b/openapi2conv/issue1008_test.go
new file mode 100644
index 0000000..4d8dfe5
--- /dev/null
+++ b/openapi2conv/issue1008_test.go
@@ -0,0 +1,49 @@
+package openapi2conv
+
+import (
+	"context"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+)
+
+func TestIssue1008(t *testing.T) {
+	v2 := []byte(`
+swagger: '2.0'
+info:
+  version: '1.10'
+  title: title
+paths:
+  "/ping":
+    post:
+      consumes:
+      - multipart/form-data
+      parameters:
+      - name: zebra
+        in: formData
+        description: stripes
+        required: true
+        type: string
+      - name: alpaca
+        in: formData
+        description: chewy
+        required: true
+        type: string
+      - name: bee
+        in: formData
+        description: buzz
+        required: true
+        type: string
+      responses:
+        '200':
+          description: OK
+`)
+
+	v3, err := v2v3YAML(v2)
+	require.NoError(t, err)
+
+	err = v3.Validate(context.Background())
+	require.NoError(t, err)
+	assert.Equal(t, []string{"alpaca", "bee", "zebra"}, v3.Paths.Value("/ping").Post.RequestBody.Value.Content.Get("multipart/form-data").Schema.Value.Required)
+}
Repository: getkin/kin-openapi
Pull request #1030 (2024-11-13 12:03:19)

openapi2conv: convert schemaRef for additional props
Fixes Issue: https://github.com/getkin/kin-openapi/issues/1016.
 
Not sure why additionProperties field is of type openapi3.Schema .Doing a conversion on the ref field 


Patch:
diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go
index ef0a5ed..ec7646d 100644
--- a/openapi2conv/openapi2_conv.go
+++ b/openapi2conv/openapi2_conv.go
@@ -516,6 +516,10 @@ func ToV3SchemaRef(schema *openapi2.SchemaRef) *openapi3.SchemaRef {
 		AdditionalProperties: schema.Value.AdditionalProperties,
 	}
 
+	if schema.Value.AdditionalProperties.Schema != nil {
+		v3Schema.AdditionalProperties.Schema.Ref = ToV3Ref(schema.Value.AdditionalProperties.Schema.Ref)
+	}
+
 	if schema.Value.Discriminator != "" {
 		v3Schema.Discriminator = &openapi3.Discriminator{
 			PropertyName: schema.Value.Discriminator,


Test patch:
diff --git a/openapi2conv/issue1016_test.go b/openapi2conv/issue1016_test.go
new file mode 100644
index 0000000..acd87d0
--- /dev/null
+++ b/openapi2conv/issue1016_test.go
@@ -0,0 +1,81 @@
+package openapi2conv
+
+import (
+	"context"
+	"encoding/json"
+	"testing"
+
+	"github.com/getkin/kin-openapi/openapi2"
+	"github.com/stretchr/testify/require"
+)
+
+func TestIssue1016(t *testing.T) {
+	v2 := []byte(`
+{
+    "basePath": "/v2",
+    "host": "test.example.com",
+    "info": {
+        "title": "MyAPI",
+        "version": "0.1",
+        "x-info": "info extension"
+    },
+    "paths": {
+        "/foo": {
+            "get": {
+                "operationId": "getFoo",
+                "responses": {
+                    "200": {
+                        "description": "returns all information",
+                        "schema": {
+                            "$ref": "#/definitions/PetDirectory"
+                        }
+                    },
+                    "default": {
+                        "description": "OK"
+                    }
+                },
+                "summary": "get foo"
+            }
+        }
+    },
+    "schemes": [
+        "http"
+    ],
+    "swagger": "2.0",
+    "definitions": {
+		"Pet": {
+			"type": "object",
+			"required": ["petType"],
+			"properties": {
+				"petType": {
+					"type": "string"
+				},
+				"name": {
+					"type": "string"
+				},
+				"age": {
+					"type": "integer"
+				}
+			}
+		},
+		"PetDirectory":{
+			"type": "object",
+			"additionalProperties": {
+				"$ref": "#/definitions/Pet"
+			}
+		}
+    }
+}
+`)
+
+	var doc2 openapi2.T
+	err := json.Unmarshal(v2, &doc2)
+	require.NoError(t, err)
+
+	doc3, err := v2v3YAML(v2)
+	require.NoError(t, err)
+
+	err = doc3.Validate(context.Background())
+	require.NoError(t, err)
+	require.Equal(t, "#/components/schemas/Pet", doc3.Components.Schemas["PetDirectory"].Value.AdditionalProperties.Schema.Ref)
+}
Repository: getkin/kin-openapi
Pull request #1050 (2025-01-28 00:26:15)

feat(openapi3gen): Customize json.RawMessage
Using a SchemaCustomizer, I can't configure schemas for `json.RawMessage` fields. If I have the following struct

```go
type Foo struct {
    Bar string `json:"bar"`
    Output json.RawMessage `json:"output"`
}
```

The schema customization function will only be called for the Bar field, not the Output field.

kyleconroy: @fenollp please let me know if this is something you'd consider merging. Thanks!
fenollp: Please add tests.
kyleconroy: Tests added

Patch:
diff --git a/openapi3gen/openapi3gen.go b/openapi3gen/openapi3gen.go
index 78e6901..b36c762 100644
--- a/openapi3gen/openapi3gen.go
+++ b/openapi3gen/openapi3gen.go
@@ -290,11 +290,10 @@ func (g *Generator) generateWithoutSaving(parents []*theTypeInfo, t reflect.Type
 
 	case reflect.Slice:
 		if t.Elem().Kind() == reflect.Uint8 {
-			if t == rawMessageType {
-				return &openapi3.SchemaRef{Value: schema}, nil
+			if t != rawMessageType {
+				schema.Type = &openapi3.Types{"string"}
+				schema.Format = "byte"
 			}
-			schema.Type = &openapi3.Types{"string"}
-			schema.Format = "byte"
 		} else {
 			schema.Type = &openapi3.Types{"array"}
 			items, err := g.generateSchemaRefFor(parents, t.Elem(), name, tag)


Test patch:
diff --git a/openapi3gen/openapi3gen_test.go b/openapi3gen/openapi3gen_test.go
index 4d9c1e2..c6c3ad3 100644
--- a/openapi3gen/openapi3gen_test.go
+++ b/openapi3gen/openapi3gen_test.go
@@ -407,7 +407,8 @@ func ExampleSchemaCustomizer() {
 			InnerFieldWithTag    int `mymintag:"-1" mymaxtag:"50"`
 			NestedInnerBla
 		}
-		Enum2Field string `json:"enum2" myenumtag:"c,d"`
+		Enum2Field string          `json:"enum2" myenumtag:"c,d"`
+		JsonField  json.RawMessage `json:"rawmsg" myjsontag:"raw"`
 	}
 
 	type Bla struct {
@@ -435,6 +436,9 @@ func ExampleSchemaCustomizer() {
 				schema.Enum = append(schema.Enum, s)
 			}
 		}
+		if tag.Get("myjsontag") != "" {
+			schema.Description = "description"
+		}
 		return nil
 	})
 
@@ -487,6 +491,9 @@ func ExampleSchemaCustomizer() {
 	//         "f"
 	//       ],
 	//       "type": "string"
+	//     },
+	//     "rawmsg": {
+	//       "description": "description"
 	//     }
 	//   },
 	//   "type": "object"
Repository: getkin/kin-openapi
Pull request #1052 (2025-02-09 12:46:56)

openapi3gen: Fix issue with separate component generated for time.Time
openapi3gen generates separate schema component for time.Time properies, when ExportComponentSchemas opt provided.
Here is a small example:
```go
type Some struct {
	Name      string
	CreatedAt time.Time
}

func main() {
	schemas := make(openapi3.Schemas)
	g := openapi3gen.NewGenerator(
		openapi3gen.UseAllExportedFields(),
		openapi3gen.CreateComponentSchemas(openapi3gen.ExportComponentSchemasOptions{
			ExportComponentSchemas: true,
		}),
	)

	ref, err := g.NewSchemaRefForValue(&Some{}, schemas)
	if err != nil {
		panic(err)
	}

	schema, _ := json.MarshalIndent(ref, "", "  ")
	fmt.Println(string(schema))
}
```

Expected output is:
```json
{
  "properties": {
    "CreatedAt": {
      "format": "date-time",
      "type": "string"
    },
    "Name": {
      "type": "string"
    }
  },
  "type": "object"
}
```

But for now generator produces following:
```json
{
  "properties": {
    "CreatedAt": {
      "$ref": "#/components/schemas/Time"
    },
    "Name": {
      "type": "string"
    }
  },
  "type": "object"
}
```

fenollp: Please add your example as a test and we should be good to go. 

Patch:
diff --git a/openapi3gen/openapi3gen.go b/openapi3gen/openapi3gen.go
index b36c762..5d9b64a 100644
--- a/openapi3gen/openapi3gen.go
+++ b/openapi3gen/openapi3gen.go
@@ -429,6 +429,11 @@ func (g *Generator) generateWithoutSaving(parents []*theTypeInfo, t reflect.Type
 
 	// For structs we add the schemas to the component schemas
 	if len(parents) > 1 || g.opts.exportComponentSchemas.ExportTopLevelSchema {
+		// If struct is a time.Time instance, separate component shouldn't be generated
+		if t == timeType {
+			return openapi3.NewSchemaRef(t.Name(), schema), nil
+		}
+
 		typeName := g.generateTypeName(t)
 
 		g.componentSchemaRefs[typeName] = struct{}{}


Test patch:
diff --git a/openapi3gen/openapi3gen_test.go b/openapi3gen/openapi3gen_test.go
index c6c3ad3..e18d861 100644
--- a/openapi3gen/openapi3gen_test.go
+++ b/openapi3gen/openapi3gen_test.go
@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"github.com/stretchr/testify/assert"
 	"reflect"
 	"strconv"
 	"strings"
@@ -641,3 +642,28 @@ func ExampleSetSchemar() {
 	//   "type": "object"
 	// }
 }
+
+func TestExportComponentSchemasForTimeProp(t *testing.T) {
+	type Some struct {
+		Name      string
+		CreatedAt time.Time
+	}
+
+	schemas := make(openapi3.Schemas)
+	g := openapi3gen.NewGenerator(
+		openapi3gen.UseAllExportedFields(),
+		openapi3gen.CreateComponentSchemas(openapi3gen.ExportComponentSchemasOptions{
+			ExportComponentSchemas: true,
+		}),
+	)
+
+	ref, err := g.NewSchemaRefForValue(&Some{}, schemas)
+	require.NoError(t, err)
+
+	schema, err := json.MarshalIndent(ref, "", "  ")
+	require.NoError(t, err)
+
+	assert.Condition(t, func() bool {
+		return !strings.Contains(string(schema), "#/components/schemas/Time")
+	}, "Expected no schema for time.Time property but got one: %s", schema)
+}
Repository: getkin/kin-openapi
Pull request #232 (2020-07-06 13:29:07)

openapi2_conv: include ExternalDocs prop when converting to v3
`ToV3Swagger` func should include `ExternalDocs` prop. Without this, it is required to set it explicitly, e.g.:

```
v3, err := openapi2conv.ToV3Swagger(&v2)		
v3.ExternalDocs = v2.ExternalDocs

```


Patch:
diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go
index 14a77a1..5654366 100644
--- a/openapi2conv/openapi2_conv.go
+++ b/openapi2conv/openapi2_conv.go
@@ -21,6 +21,7 @@ func ToV3Swagger(swagger *openapi2.Swagger) (*openapi3.Swagger, error) {
 		Components:     openapi3.Components{},
 		Tags:           swagger.Tags,
 		ExtensionProps: swagger.ExtensionProps,
+		ExternalDocs:   swagger.ExternalDocs,
 	}
 	host := swagger.Host
 	if len(host) > 0 {
@@ -362,6 +363,7 @@ func FromV3Swagger(swagger *openapi3.Swagger) (*openapi2.Swagger, error) {
 		Responses:      resultResponses,
 		Tags:           swagger.Tags,
 		ExtensionProps: swagger.ExtensionProps,
+		ExternalDocs:   swagger.ExternalDocs,
 	}
 
 	isHTTPS := false


Test patch:
diff --git a/openapi2conv/openapi2_conv_test.go b/openapi2conv/openapi2_conv_test.go
index d0e659b..536a569 100644
--- a/openapi2conv/openapi2_conv_test.go
+++ b/openapi2conv/openapi2_conv_test.go
@@ -41,6 +41,10 @@ const exampleV2 = `
   "schemes": ["https"],
   "host": "test.example.com",
   "basePath": "/v2",
+  "externalDocs": {
+    "url": "https://example/doc/",
+    "description": "Example Documentation"
+  },
   "tags": [
     {
       "name": "Example",
@@ -229,6 +233,10 @@ const exampleV3 = `
   "x-root2": "root extension 2",
   "openapi": "3.0.2",
   "info": {"title":"MyAPI","version":"0.1","x-info":"info extension"},
+  "externalDocs": {
+    "url": "https://example/doc/",
+    "description": "Example Documentation"
+  },
   "components": {
     "responses": {
       "ForbiddenError": {
Repository: getkin/kin-openapi
Pull request #287 (2021-01-18 21:18:20)

Add OIDC Schema format as per spec
https://swagger.io/docs/specification/authentication/openid-connect-discovery/


Patch:
diff --git a/openapi3/security_scheme.go b/openapi3/security_scheme.go
index 8dcb230..7e83019 100644
--- a/openapi3/security_scheme.go
+++ b/openapi3/security_scheme.go
@@ -28,13 +28,14 @@ var _ jsonpointer.JSONPointable = (*SecuritySchemes)(nil)
 type SecurityScheme struct {
 	ExtensionProps
 
-	Type         string      `json:"type,omitempty" yaml:"type,omitempty"`
-	Description  string      `json:"description,omitempty" yaml:"description,omitempty"`
-	Name         string      `json:"name,omitempty" yaml:"name,omitempty"`
-	In           string      `json:"in,omitempty" yaml:"in,omitempty"`
-	Scheme       string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
-	BearerFormat string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
-	Flows        *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
+	Type             string      `json:"type,omitempty" yaml:"type,omitempty"`
+	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
+	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`
+	In               string      `json:"in,omitempty" yaml:"in,omitempty"`
+	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
+	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
+	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
+	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
 }
 
 func NewSecurityScheme() *SecurityScheme {
@@ -49,6 +50,13 @@ func NewCSRFSecurityScheme() *SecurityScheme {
 	}
 }
 
+func NewOIDCSecurityScheme(oidcUrl string) *SecurityScheme {
+	return &SecurityScheme{
+		Type:             "openIdConnect",
+		OpenIdConnectUrl: oidcUrl,
+	}
+}
+
 func NewJWTSecurityScheme() *SecurityScheme {
 	return &SecurityScheme{
 		Type:         "http",
@@ -114,7 +122,9 @@ func (ss *SecurityScheme) Validate(c context.Context) error {
 	case "oauth2":
 		hasFlow = true
 	case "openIdConnect":
-		return fmt.Errorf("Support for security schemes with type '%v' has not been implemented", ss.Type)
+		if ss.OpenIdConnectUrl == "" {
+			return fmt.Errorf("No OIDC URL found for openIdConnect security scheme %q", ss.Name)
+		}
 	default:
 		return fmt.Errorf("Security scheme 'type' can't be '%v'", ss.Type)
 	}


Test patch:
diff --git a/openapi3/security_scheme_test.go b/openapi3/security_scheme_test.go
index 2a64208..9edb17a 100644
--- a/openapi3/security_scheme_test.go
+++ b/openapi3/security_scheme_test.go
@@ -198,4 +198,24 @@ var securitySchemeExamples = []securitySchemeExample{
 `),
 		valid: true,
 	},
+	{
+		title: "OIDC Type With URL",
+		raw: []byte(`
+{
+  "type": "openIdConnect",
+  "openIdConnectUrl": "https://example.com/.well-known/openid-configuration"
+}
+`),
+		valid: true,
+	},
+	{
+		title: "OIDC Type Without URL",
+		raw: []byte(`
+{
+  "type": "openIdConnect",
+  "openIdConnectUrl": ""
+}
+`),
+		valid: false,
+	},
 }
Repository: getkin/kin-openapi
Pull request #319 (2021-03-03 18:19:07)

go:embed loader.ReadFromURIFunc example


Patch:
diff --git a/go.mod b/go.mod
index 8ccc139..5856146 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module github.com/getkin/kin-openapi
 
-go 1.14
+go 1.16
 
 require (
 	github.com/ghodss/yaml v1.0.0


Test patch:
diff --git a/openapi3/load_with_go_embed_test.go b/openapi3/load_with_go_embed_test.go
new file mode 100644
index 0000000..67ecfea
--- /dev/null
+++ b/openapi3/load_with_go_embed_test.go
@@ -0,0 +1,32 @@
+package openapi3_test
+
+import (
+	"embed"
+	"fmt"
+	"net/url"
+
+	"github.com/getkin/kin-openapi/openapi3"
+)
+
+//go:embed testdata/recursiveRef/*
+var fs embed.FS
+
+func Example() {
+	loader := openapi3.NewSwaggerLoader()
+	loader.IsExternalRefsAllowed = true
+	loader.ReadFromURIFunc = func(loader *openapi3.SwaggerLoader, uri *url.URL) ([]byte, error) {
+		return fs.ReadFile(uri.Path)
+	}
+
+	doc, err := loader.LoadSwaggerFromFile("testdata/recursiveRef/openapi.yml")
+	if err != nil {
+		panic(err)
+	}
+
+	if err = doc.Validate(loader.Context); err != nil {
+		panic(err)
+	}
+
+	fmt.Println(doc.Paths["/foo"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["foo"].Value.Properties["bar"].Value.Type)
+	// Output: array
+}
Repository: getkin/kin-openapi
Pull request #379 (2021-06-25 13:16:10)

Add uint type to openapi3gen
Didn't open an issue because it was pretty straightforward!

Lemme know if I need to change something, I'm happy to.


Patch:
diff --git a/openapi3gen/openapi3gen.go b/openapi3gen/openapi3gen.go
index f704133..9606983 100644
--- a/openapi3gen/openapi3gen.go
+++ b/openapi3gen/openapi3gen.go
@@ -144,6 +144,9 @@ func (g *Generator) generateWithoutSaving(parents []*jsoninfo.TypeInfo, t reflec
 	case reflect.Int64:
 		schema.Type = "integer"
 		schema.Format = "int64"
+	case reflect.Uint:
+		schema.Type = "integer"
+		schema.Min = &zeroInt
 	case reflect.Uint8:
 		schema.Type = "integer"
 		schema.Min = &zeroInt


Test patch:
diff --git a/openapi3gen/openapi3gen_test.go b/openapi3gen/openapi3gen_test.go
index a975b2a..777bb9d 100644
--- a/openapi3gen/openapi3gen_test.go
+++ b/openapi3gen/openapi3gen_test.go
@@ -39,3 +39,17 @@ func TestExportedNonTagged(t *testing.T) {
 			"even_a_yaml": {Value: &openapi3.Schema{Type: "string"}},
 		}}}, schemaRef)
 }
+
+func TestExportUint(t *testing.T) {
+	type UnsignedIntStruct struct {
+		UnsignedInt uint `json:"uint"`
+	}
+
+	schemaRef, _, err := NewSchemaRefForValue(&UnsignedIntStruct{}, UseAllExportedFields())
+	require.NoError(t, err)
+	require.Equal(t, &openapi3.SchemaRef{Value: &openapi3.Schema{
+		Type: "object",
+		Properties: map[string]*openapi3.SchemaRef{
+			"uint": {Value: &openapi3.Schema{Type: "integer", Min: &zeroInt}},
+		}}}, schemaRef)
+}