Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions maps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ value_types+=('*PathItem')
value_types+=('*PathItem')

deref_vs=()
deref_vs+=('*Response = v.Value')
deref_vs+=('*PathItem = v')
deref_vs+=('*PathItem = v')
deref_vs+=('v.Value')
deref_vs+=('v')
deref_vs+=('v')

names=()
names+=('responses')
Expand Down Expand Up @@ -145,8 +145,7 @@ func (${name} ${type#'*'}) JSONLookup(token string) (any, error) {
} else if ref := v.Ref; ref != "" {
return &Ref{Ref: ref}, nil
} else {
var vv ${deref_v}
return vv, nil
return ${deref_v}, nil
}
}

Expand Down
11 changes: 5 additions & 6 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ToV3WithLoader(doc2 *openapi2.T, loader *openapi3.Loader, location *url.URL

if host := doc2.Host; host != "" {
if strings.Contains(host, "/") {
err := fmt.Errorf("invalid host %q. This MUST be the host only and does not include the scheme nor sub-paths.", host)
err := fmt.Errorf("invalid host %q. This MUST be the host only and does not include the scheme nor sub-paths", host)
return nil, err
}
schemes := doc2.Schemes
Expand Down Expand Up @@ -679,12 +679,11 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
isHTTP := false
servers := doc3.Servers
for i, server := range servers {
parsedURL, err := url.Parse(server.URL)
if err == nil {
// See which schemes seem to be supported
if parsedURL.Scheme == "https" {
if parsedURL, err := url.Parse(server.URL); err == nil {
switch parsedURL.Scheme {
case "https":
isHTTPS = true
} else if parsedURL.Scheme == "http" {
case "http":
isHTTP = true
}
// The first server is assumed to provide the base path
Expand Down
9 changes: 1 addition & 8 deletions openapi3/internalize_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,11 @@ func DefaultRefNameResolver(doc *T, ref ComponentRef) string {

// Trim the common prefix with the root doc path.
if doc.url != nil {
commonDir := path.Dir(doc.url.Path)
for {
if commonDir == "." { // no common prefix
break
}

for commonDir := path.Dir(doc.url.Path); /*no common prefix*/ commonDir != "."; commonDir = path.Dir(commonDir) {
if p, found := cutDirectories(filePath, commonDir); found {
filePath = p
break
}

commonDir = path.Dir(commonDir)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,5 +1229,5 @@ func (loader *Loader) resolvePathItemRef(doc *T, pathItem *PathItem, documentPat
}

func unescapeRefString(ref string) string {
return strings.Replace(strings.Replace(ref, "~1", "/", -1), "~0", "~", -1)
return strings.ReplaceAll(strings.ReplaceAll(ref, "~1", "/"), "~0", "~")
}
9 changes: 3 additions & 6 deletions openapi3/maplike.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (responses Responses) JSONLookup(token string) (any, error) {
} else if ref := v.Ref; ref != "" {
return &Ref{Ref: ref}, nil
} else {
var vv *Response = v.Value
return vv, nil
return v.Value, nil
}
}

Expand Down Expand Up @@ -213,8 +212,7 @@ func (callback Callback) JSONLookup(token string) (any, error) {
} else if ref := v.Ref; ref != "" {
return &Ref{Ref: ref}, nil
} else {
var vv *PathItem = v
return vv, nil
return v, nil
}
}

Expand Down Expand Up @@ -355,8 +353,7 @@ func (paths Paths) JSONLookup(token string) (any, error) {
} else if ref := v.Ref; ref != "" {
return &Ref{Ref: ref}, nil
} else {
var vv *PathItem = v
return vv, nil
return v, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (addProps *AdditionalProperties) UnmarshalJSON(data []byte) error {
addProps.Schema = &SchemaRef{Value: &Schema{}}
} else {
buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(y)
_ = json.NewEncoder(buf).Encode(y)
if err := json.NewDecoder(buf).Decode(&addProps.Schema); err != nil {
return err
}
Expand Down
23 changes: 1 addition & 22 deletions openapi3filter/req_resp_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,26 +899,6 @@ func deepSet(m map[string]any, keys []string, value any) {
m[keys[len(keys)-1]] = value
}

func findNestedSchema(parentSchema *openapi3.SchemaRef, keys []string) (*openapi3.SchemaRef, error) {
currentSchema := parentSchema
for _, key := range keys {
if currentSchema.Value.Type.Includes(openapi3.TypeArray) {
currentSchema = currentSchema.Value.Items
} else {
propertySchema, ok := currentSchema.Value.Properties[key]
if !ok {
if currentSchema.Value.AdditionalProperties.Schema == nil {
return nil, fmt.Errorf("nested schema for key %q not found", key)
}
currentSchema = currentSchema.Value.AdditionalProperties.Schema
continue
}
currentSchema = propertySchema
}
}
return currentSchema, nil
}

// makeObject returns an object that contains properties from props.
func makeObject(props map[string]string, schema *openapi3.SchemaRef) (map[string]any, error) {
mobj := make(map[string]any)
Expand Down Expand Up @@ -1482,8 +1462,7 @@ func MultipartBodyDecoder(body io.Reader, header http.Header, schema *openapi3.S
}

// Parse primitive types when no content type is explicitely provided, or the content type is set to text/plain
contentType := partHeader.Get(headerCT)
if contentType == "" || contentType == "text/plain" {
if contentType := partHeader.Get(headerCT); contentType == "" || contentType == "text/plain" {
if value, err = parsePrimitive(value.(string), valueSchema); err != nil {
if v, ok := err.(*ParseError); ok {
return nil, &ParseError{path: []any{name}, Cause: v}
Expand Down
3 changes: 1 addition & 2 deletions openapi3filter/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ func validateSecurityRequirement(ctx context.Context, input *RequestValidationIn
defer input.Request.Body.Close()

var err error
data, err = io.ReadAll(input.Request.Body)
if err != nil {
if data, err = io.ReadAll(input.Request.Body); err != nil {
return &RequestError{
Input: input,
Reason: "reading failed",
Expand Down
10 changes: 5 additions & 5 deletions routers/gorillamux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ func newSrv(serverURL string, server *openapi3.Server, varsUpdater varsf) (srv,
var blURL, brURL = strings.Repeat("-", 50), strings.Repeat("_", 50)

func bEncode(s string) string {
s = strings.Replace(s, "{", blURL, -1)
s = strings.Replace(s, "}", brURL, -1)
s = strings.ReplaceAll(s, "{", blURL)
s = strings.ReplaceAll(s, "}", brURL)
return s
}
func bDecode(s string) string {
s = strings.Replace(s, blURL, "{", -1)
s = strings.Replace(s, brURL, "}", -1)
s = strings.ReplaceAll(s, blURL, "{")
s = strings.ReplaceAll(s, brURL, "}")
return s
}

Expand Down Expand Up @@ -250,7 +250,7 @@ func permutePart(part0 string, srv *openapi3.Server) []string {
for i := 0; i < max; i++ {
part := part0
for name, mas := range var2val {
part = strings.Replace(part, name, mas.s[i%len(mas.s)], -1)
part = strings.ReplaceAll(part, name, mas.s[i%len(mas.s)])
}
partsMap[part] = struct{}{}
}
Expand Down
Loading