-
Notifications
You must be signed in to change notification settings - Fork 0
/
genschema.go
53 lines (49 loc) · 1.4 KB
/
genschema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"reflect"
"fmt"
"os"
"bytes"
"encoding/json"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/go-webauthn/webauthn/protocol"
"github.com/invopop/jsonschema"
)
type WebAuthn4JS struct {
Config webauthn.Config
User User
CredentialCreation protocol.CredentialCreation
CredentialCreationResponse protocol.CredentialCreationResponse
CredentialAssertion protocol.CredentialAssertion
CredentialAssertionResponse protocol.CredentialAssertionResponse
SessionData webauthn.SessionData
Credential protocol.Credential
CredentialDescriptor protocol.CredentialDescriptor
PublicKeyCredentialCreationOptions protocol.PublicKeyCredentialCreationOptions
PublicKeyCredentialRequestOptions protocol.PublicKeyCredentialRequestOptions
}
func main() {
//jsonschema.Version = "" // json-schema-to-typescript doesn't like $schema and $ref together
typ := reflect.TypeOf((*WebAuthn4JS)(nil)).Elem()
reflector := jsonschema.Reflector{
DoNotReference: false,
ExpandedStruct: true,
/*TypeMapper: func(typ reflect.Type) *jsonschema.Type {
if typ == reflect.TypeOf((*protocol.Challenge)(nil)).Elem() {
return &jsonschema.Type{
Type: "string",
}
}
return nil
},*/
}
schema := reflector.ReflectFromType(typ)
b, err := schema.MarshalJSON()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
var out bytes.Buffer
json.Indent(&out, b, "", " ")
out.WriteTo(os.Stdout)
}