Skip to content

Commit

Permalink
feat: schemas are now static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 6, 2020
1 parent 96028d8 commit 1776d58
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
16 changes: 16 additions & 0 deletions selfservice/strategy/password/.schema/registration.schema.json
@@ -0,0 +1,16 @@
{
"$id": "https://schemas.ory.sh/kratos/selfservice/strategy/password/registration.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"password",
"traits"
],
"properties": {
"password": {
"type": "string",
"minLength": 1
},
"traits": {}
}
}
18 changes: 1 addition & 17 deletions selfservice/strategy/password/registration.go
Expand Up @@ -30,22 +30,6 @@ import (

const (
RegistrationPath = "/self-service/browser/flows/registration/strategies/password"
registrationFormPayloadSchema = `{
"$id": "https://schemas.ory.sh/kratos/selfservice/password/registration/config.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"password",
"traits"
],
"properties": {
"password": {
"type": "string",
"minLength": 1
},
"traits": {}
}
}`
)

type RegistrationFormPayload struct {
Expand Down Expand Up @@ -81,7 +65,7 @@ func (s *Strategy) handleRegistrationError(w http.ResponseWriter, r *http.Reques
}

func (s *Strategy) decoderRegistration() (decoderx.HTTPDecoderOption, error) {
raw, err := sjson.SetBytes([]byte(registrationFormPayloadSchema), "properties.traits.$ref", s.c.DefaultIdentityTraitsSchemaURL().String()+"#/properties/traits")
raw, err := sjson.SetBytes(registrationSchema, "properties.traits.$ref", s.c.DefaultIdentityTraitsSchemaURL().String()+"#/properties/traits")
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
10 changes: 10 additions & 0 deletions selfservice/strategy/password/schema.go
@@ -0,0 +1,10 @@
package password

import (
"github.com/markbates/pkger"

"github.com/ory/kratos/x/pkgerx"
)

var loginSchema = pkgerx.MustRead(pkger.Open("/selfservice/strategy/password/.schema/login.schema.json"))
var registrationSchema = pkgerx.MustRead(pkger.Open("/selfservice/strategy/password/.schema/registration.schema.json"))
17 changes: 17 additions & 0 deletions x/pkgerx/pkgerx.go
@@ -0,0 +1,17 @@
package pkgerx

import (
"io"
"io/ioutil"
)

func MustRead(closer io.ReadCloser, err error) []byte {
out, err := ioutil.ReadAll(closer)
if err != nil {
_ = closer.Close()
panic(err)
}

_ = closer.Close()
return out
}

0 comments on commit 1776d58

Please sign in to comment.