Skip to content

Commit

Permalink
Fix last review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate Döen committed Sep 16, 2021
1 parent b430ce1 commit 2517dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
20 changes: 4 additions & 16 deletions schema/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (h *Handler) getByID(w http.ResponseWriter, r *http.Request, ps httprouter.

// Raw identity Schema list
//
// swagger:model IdentitySchemas
// swagger:model identitySchemas
type IdentitySchemas []identitySchema

// swagger:model identitySchema
Expand Down Expand Up @@ -147,7 +147,7 @@ type listIdentitySchemas struct {
// Schemes: http, https
//
// Responses:
// 200: IdentitySchemas
// 200: identitySchemas
// 500: jsonError
func (h *Handler) getAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
page, itemsPerPage := x.ParsePagination(r)
Expand Down Expand Up @@ -177,26 +177,14 @@ func (h *Handler) getAll(w http.ResponseWriter, r *http.Request, ps httprouter.P
return
}

var p json.RawMessage
err = json.Unmarshal(raw, &p)
if err != nil {
h.r.Writer().WriteError(w, r, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("The file for this JSON Schema ID could not be found or opened. This is a configuration issue.").WithDebugf("%+v", err)))
return
}

ss = append(ss, identitySchema{
ID: s.ID,
Schema: p,
Schema: raw,
})
}

x.PaginationHeader(w, urlx.AppendPaths(h.r.Config(r.Context()).SelfPublicURL(r), fmt.Sprintf("/%s", SchemasPath)), int64(total), page, itemsPerPage)

w.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(ss); err != nil {
h.r.Writer().WriteError(w, r, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("The file for this JSON Schema ID could not be found or opened. This is a configuration issue.").WithDebugf("%+v", err)))
return
}
h.r.Writer().Write(w, r, ss)
}

func ReadSchema(schema *Schema) (src io.ReadCloser, err error) {
Expand Down
13 changes: 5 additions & 8 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
_ "github.com/ory/jsonschema/v3/fileloader"
_ "github.com/ory/jsonschema/v3/httploader"
"github.com/ory/kratos/driver/config"
"github.com/ory/x/pagination"
"github.com/ory/x/urlx"
)

Expand Down Expand Up @@ -46,15 +47,11 @@ func (s Schemas) List(page, perPage int) Schemas {
if page < 0 {
page = 0
}
upper := (page + 1) * perPage
if upper > len(s) {
upper = len(s)
if perPage < 1 {
perPage = 1
}
lower := page * perPage
if lower > upper {
lower = upper
}
return s[lower:upper]
start, end := pagination.Index((page+1)*perPage, page*perPage, len(s))
return s[start:end]
}

var orderedKeyCacheMutex sync.RWMutex
Expand Down

0 comments on commit 2517dff

Please sign in to comment.