Skip to content

Commit

Permalink
Fix openapi3.referencedDocumentPath (getkin#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshlm authored and Eliott B committed Jan 27, 2022
1 parent 2392e46 commit 09b642f
Show file tree
Hide file tree
Showing 57 changed files with 149 additions and 86 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CI](https://github.com/getkin/kin-openapi/workflows/go/badge.svg)](https://github.com/getkin/kin-openapi/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/getkin/kin-openapi)](https://goreportcard.com/report/github.com/getkin/kin-openapi)
[![GoDoc](https://godoc.org/github.com/getkin/kin-openapi?status.svg)](https://godoc.org/github.com/getkin/kin-openapi)
[![CI](https://github.com/eliottness/kin-openapi/workflows/go/badge.svg)](https://github.com/eliottness/kin-openapi/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/eliottness/kin-openapi)](https://goreportcard.com/report/github.com/eliottness/kin-openapi)
[![GoDoc](https://godoc.org/github.com/eliottness/kin-openapi?status.svg)](https://godoc.org/github.com/eliottness/kin-openapi)
[![Join Gitter Chat Channel -](https://badges.gitter.im/getkin/kin.svg)](https://gitter.im/getkin/kin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

# Introduction
Expand All @@ -17,25 +17,25 @@ Here's some projects that depend on _kin-openapi_:
* [github.com/deepmap/oapi-codegen](https://github.com/deepmap/oapi-codegen) - Generate Go server boilerplate from an OpenAPI 3 spec
* [github.com/dunglas/vulcain](https://github.com/dunglas/vulcain) - "Use HTTP/2 Server Push to create fast and idiomatic client-driven REST APIs"
* [github.com/danielgtaylor/restish](https://github.com/danielgtaylor/restish) - "...a CLI for interacting with REST-ish HTTP APIs with some nice features built-in"
* (Feel free to add your project by [creating an issue](https://github.com/getkin/kin-openapi/issues/new) or a pull request)
* (Feel free to add your project by [creating an issue](https://github.com/eliottness/kin-openapi/issues/new) or a pull request)

## Alternative projects
* [go-openapi](https://github.com/go-openapi)
* Supports OpenAPI version 2.
* See [this list](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/IMPLEMENTATIONS.md).

# Structure
* _openapi2_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi2))
* _openapi2_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/openapi2))
* Support for OpenAPI 2 files, including serialization, deserialization, and validation.
* _openapi2conv_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi2conv))
* _openapi2conv_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/openapi2conv))
* Converts OpenAPI 2 files into OpenAPI 3 files.
* _openapi3_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3))
* _openapi3_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/openapi3))
* Support for OpenAPI 3 files, including serialization, deserialization, and validation.
* _openapi3filter_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3filter))
* _openapi3filter_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/openapi3filter))
* Validates HTTP requests and responses
* _openapi3gen_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3gen))
* _openapi3gen_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/openapi3gen))
* Generates `*openapi3.Schema` values for Go types.
* _pathpattern_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/pathpattern))
* _pathpattern_ ([godoc](https://godoc.org/github.com/eliottness/kin-openapi/pathpattern))
* Matches strings with OpenAPI path patterns ("/path/{parameter}")

# Some recipes
Expand Down Expand Up @@ -73,7 +73,7 @@ import (
"log"
"net/http"

"github.com/getkin/kin-openapi/openapi3filter"
"github.com/eliottness/kin-openapi/openapi3filter"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/getkin/kin-openapi
module github.com/eliottness/kin-openapi

go 1.14
go 1.13

require (
github.com/ghodss/yaml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions jsoninfo/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
"time"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/openapi3"
)

type Simple struct {
Expand Down
2 changes: 1 addition & 1 deletion jsoninfo/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"testing"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions openapi2/openapi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"fmt"
"net/http"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/openapi3"
)

type Swagger struct {
Expand Down
4 changes: 2 additions & 2 deletions openapi2conv/issue187_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"testing"

"github.com/getkin/kin-openapi/openapi2"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi2"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/ghodss/yaml"
"github.com/stretchr/testify/require"
)
Expand Down
4 changes: 2 additions & 2 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/url"
"strings"

"github.com/getkin/kin-openapi/openapi2"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi2"
"github.com/eliottness/kin-openapi/openapi3"
)

// ToV3Swagger converts an OpenAPIv2 spec to an OpenAPIv3 spec
Expand Down
4 changes: 2 additions & 2 deletions openapi2conv/openapi2_conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"testing"

"github.com/getkin/kin-openapi/openapi2"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi2"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"regexp"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Components is specified by OpenAPI/Swagger standard version 3.0.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3
import (
"context"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Discriminator is specified by OpenAPI/Swagger standard version 3.0.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/discriminator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3_test
import (
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Encoding is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/examples.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package openapi3

import (
"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Example is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/extension.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package openapi3

import (
"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// ExtensionProps provides support for OpenAPI extensions.
Expand Down
4 changes: 2 additions & 2 deletions openapi3/extension_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package openapi3_test

import (
"github.com/getkin/kin-openapi/jsoninfo"
"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion openapi3/external_docs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package openapi3

import (
"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3
import (
"context"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

type Header struct {
Expand Down
2 changes: 1 addition & 1 deletion openapi3/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Info is specified by OpenAPI/Swagger standard version 3.0.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Link is specified by OpenAPI/Swagger standard version 3.0.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/media_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3
import (
"context"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// MediaType is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/media_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"strconv"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Operation represents "operation" specified by" OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Parameters is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/path_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

type PathItem struct {
Expand Down
2 changes: 1 addition & 1 deletion openapi3/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3
import (
"context"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

type CallbackRef struct {
Expand Down
2 changes: 1 addition & 1 deletion openapi3/request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package openapi3
import (
"context"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// RequestBody is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"strconv"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

// Responses is specified by OpenAPI/Swagger 3.0 standard.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"unicode/utf16"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion openapi3/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/security_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

type SecurityScheme struct {
Expand Down
2 changes: 1 addition & 1 deletion openapi3/security_scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/eliottness/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi3/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/getkin/kin-openapi/jsoninfo"
"github.com/eliottness/kin-openapi/jsoninfo"
)

type Swagger struct {
Expand Down
23 changes: 13 additions & 10 deletions openapi3/swagger_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,16 +876,19 @@ func unescapeRefString(ref string) string {
}

func referencedDocumentPath(documentPath *url.URL, ref string) (*url.URL, error) {
newDocumentPath := documentPath
if documentPath != nil {
refDirectory, err := url.Parse(path.Dir(ref))
if err != nil {
return nil, err
}
joinedDirectory := path.Join(path.Dir(documentPath.String()), refDirectory.String())
if newDocumentPath, err = url.Parse(joinedDirectory + "/"); err != nil {
return nil, err
}
if documentPath == nil {
return nil, nil
}

newDocumentPath, err := copyURL(documentPath)
if err != nil {
return nil, err
}
refPath, err := url.Parse(ref)
if err != nil {
return nil, err
}
newDocumentPath.Path = path.Join(path.Dir(newDocumentPath.Path), path.Dir(refPath.Path)) + "/"

return newDocumentPath, nil
}
Loading

0 comments on commit 09b642f

Please sign in to comment.