Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: adopt embedfs #174

Merged
merged 2 commits into from
Dec 5, 2023
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# OAI object model
# OpenAPI v2 object model [![Build Status](https://github.com/go-openapi/spec/actions/workflows/go-test.yaml/badge.svg)](https://github.com/go-openapi/strfmt/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/spec/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/spec)

[![Build Status](https://travis-ci.org/go-openapi/spec.svg?branch=master)](https://travis-ci.org/go-openapi/spec)
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/x377t5o9ennm847o/branch/master?svg=true)](https://ci.appveyor.com/project/casualjim/go-openapi/spec/branch/master) -->
[![codecov](https://codecov.io/gh/go-openapi/spec/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/spec)
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://github.com/raw/go-openapi/spec/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/spec.svg)](https://pkg.go.dev/github.com/go-openapi/spec)
Expand Down
297 changes: 0 additions & 297 deletions bindata.go

This file was deleted.

4 changes: 2 additions & 2 deletions circular_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package spec

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestExpandCircular_Bitbucket(t *testing.T) {

func TestExpandCircular_ResponseWithRoot(t *testing.T) {
rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join("fixtures", "more_circulars", "resp.json"))
b, err := os.ReadFile(filepath.Join("fixtures", "more_circulars", "resp.json"))
require.NoError(t, err)

require.NoError(t, json.Unmarshal(b, rootDoc))
Expand Down
3 changes: 1 addition & 2 deletions debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package spec

import (
"io/ioutil"
"os"
"sync"
"testing"
Expand All @@ -28,7 +27,7 @@ var (
)

func TestDebug(t *testing.T) {
tmpFile, _ := ioutil.TempFile("", "debug-test")
tmpFile, _ := os.CreateTemp("", "debug-test")
tmpName := tmpFile.Name()
defer func() {
Debug = false
Expand Down
17 changes: 17 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package spec

import (
"embed"
"path"
)

//go:embed schemas/*.json schemas/*/*.json
var assets embed.FS

func jsonschemaDraft04JSONBytes() ([]byte, error) {
return assets.ReadFile(path.Join("schemas", "jsonschema-draft-04.json"))
}

func v2SchemaJSONBytes() ([]byte, error) {
return assets.ReadFile(path.Join("schemas", "v2", "schema.json"))
}
10 changes: 5 additions & 5 deletions expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package spec

import (
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestExpand_ContinueOnError(t *testing.T) {
specPath := filepath.Join("fixtures", "expansion", "missingRef.json")

defer log.SetOutput(os.Stdout)
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

// missing $ref in spec
missingRefDoc, err := jsonDoc(specPath)
Expand Down Expand Up @@ -816,7 +816,7 @@ func resolutionContextServer() *httptest.Server {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/resolution.json" {

b, _ := ioutil.ReadFile(filepath.Join(specs, "resolution.json"))
b, _ := os.ReadFile(filepath.Join(specs, "resolution.json"))
var ctnt map[string]interface{}
_ = json.Unmarshal(b, &ctnt)
ctnt["id"] = servedAt
Expand All @@ -828,7 +828,7 @@ func resolutionContextServer() *httptest.Server {
return
}
if req.URL.Path == "/resolution2.json" {
b, _ := ioutil.ReadFile(filepath.Join(specs, "resolution2.json"))
b, _ := os.ReadFile(filepath.Join(specs, "resolution2.json"))
var ctnt map[string]interface{}
_ = json.Unmarshal(b, &ctnt)
ctnt["id"] = servedAt
Expand Down Expand Up @@ -936,7 +936,7 @@ func TestExpand_RemoteRefWithNestedResolutionContextWithFragment(t *testing.T) {
func TestExpand_TransitiveRefs(t *testing.T) {
basePath := filepath.Join(specs, "todos.json")

rawSpec, err := ioutil.ReadFile(basePath)
rawSpec, err := os.ReadFile(basePath)
require.NoError(t, err)

var spec *Swagger
Expand Down
19 changes: 14 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
module github.com/go-openapi/spec

require (
github.com/go-openapi/jsonpointer v0.19.5
github.com/go-openapi/jsonreference v0.20.0
github.com/go-openapi/swag v0.19.15
github.com/stretchr/testify v1.6.1
github.com/go-openapi/jsonpointer v0.20.0
github.com/go-openapi/jsonreference v0.20.2
github.com/go-openapi/swag v0.22.4
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v2 v2.4.0
)

go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.19
49 changes: 25 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,41 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ=
github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
22 changes: 11 additions & 11 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package spec

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -132,7 +132,7 @@ func TestResolveRemoteRef_RootSame(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand Down Expand Up @@ -160,7 +160,7 @@ func TestResolveRemoteRef_FromFragment(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand All @@ -180,7 +180,7 @@ func TestResolveRemoteRef_FromInvalidFragment(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand All @@ -199,7 +199,7 @@ func TestResolveRemoteRef_FromInvalidFragment(t *testing.T) {
// defer server.Close()
//
// rootDoc := new(Swagger)
// b, err := ioutil.ReadFile("fixtures/specs/refed.json")
// b, err := os.ReadFile("fixtures/specs/refed.json")
// require.NoError(t, err) && assert.NoError(t, json.Unmarshal(b, rootDoc))
//
// var tgt Schema
Expand All @@ -217,7 +217,7 @@ func TestResolveRemoteRef_ToParameter(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand All @@ -242,7 +242,7 @@ func TestResolveRemoteRef_ToPathItem(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand All @@ -261,7 +261,7 @@ func TestResolveRemoteRef_ToResponse(t *testing.T) {
defer server.Close()

rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)
require.NoError(t, json.Unmarshal(b, rootDoc))

Expand Down Expand Up @@ -312,7 +312,7 @@ func TestResolveLocalRef_FromInvalidFragment(t *testing.T) {

func TestResolveLocalRef_Parameter(t *testing.T) {
rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)

basePath := filepath.Join(specs, "refed.json")
Expand All @@ -335,7 +335,7 @@ func TestResolveLocalRef_Parameter(t *testing.T) {

func TestResolveLocalRef_PathItem(t *testing.T) {
rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)

basePath := filepath.Join(specs, "refed.json")
Expand All @@ -352,7 +352,7 @@ func TestResolveLocalRef_PathItem(t *testing.T) {

func TestResolveLocalRef_Response(t *testing.T) {
rootDoc := new(Swagger)
b, err := ioutil.ReadFile(filepath.Join(specs, "refed.json"))
b, err := os.ReadFile(filepath.Join(specs, "refed.json"))
require.NoError(t, err)

basePath := filepath.Join(specs, "refed.json")
Expand Down
4 changes: 2 additions & 2 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func MustLoadJSONSchemaDraft04() *Schema {

// JSONSchemaDraft04 loads the json schema document for json shema draft04
func JSONSchemaDraft04() (*Schema, error) {
b, err := Asset("jsonschema-draft-04.json")
b, err := jsonschemaDraft04JSONBytes()
if err != nil {
return nil, err
}
Expand All @@ -65,7 +65,7 @@ func MustLoadSwagger20Schema() *Schema {
// Swagger20Schema loads the swagger 2.0 schema from the embedded assets
func Swagger20Schema() (*Schema, error) {

b, err := Asset("v2/schema.json")
b, err := v2SchemaJSONBytes()
if err != nil {
return nil, err
}
Expand Down
Loading