schema: generate code

This commit is contained in:
Bobby Rullo 2016-04-15 17:23:27 -07:00
parent 1bbca1d43c
commit 35cefb7da9
4 changed files with 112 additions and 86 deletions

View file

@ -20,32 +20,41 @@ __Version:__ v1
}
```
### Client
```
{
clientName: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
clientURI: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
id: string // The client ID. Ignored in client create requests.,
isAdmin: boolean,
logoURI: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
redirectURIs: [
string
],
secret: string
}
```
### ClientCreateRequest
A request to register a client with dex.
```
{
client: {
client_name: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
client_uri: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
logo_uri: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
redirect_uris: [
string
]
},
isAdmin: boolean
client: Client
}
```
### ClientRegistrationResponse
### ClientCreateResponse
Upon successful registration, an ID and secret is assigned to the client.
```
{
client_id: string,
client_secret: string
client: Client
}
```
@ -137,7 +146,7 @@ Upon successful registration, an ID and secret is assigned to the client.
> |Code|Description|Type|
|:-----|:-----|:-----|
| 200 | | [ClientRegistrationResponse](#clientregistrationresponse) |
| 200 | | [ClientCreateResponse](#clientcreateresponse) |
| default | Unexpected error | |

View file

@ -97,49 +97,52 @@ type Admin struct {
Password string `json:"password,omitempty"`
}
type ClientCreateRequest struct {
Client *ClientCreateRequestClient `json:"client,omitempty"`
IsAdmin bool `json:"isAdmin,omitempty"`
}
type ClientCreateRequestClient struct {
// Client_name: OPTIONAL. Name of the Client to be presented to the
type Client struct {
// ClientName: OPTIONAL. Name of the Client to be presented to the
// End-User. If desired, representation of this Claim in different
// languages and scripts is represented as described in Section 2.1 (
// Metadata Languages and Scripts ) .
Client_name string `json:"client_name,omitempty"`
ClientName string `json:"clientName,omitempty"`
// Client_uri: OPTIONAL. URL of the home page of the Client. The value
// of this field MUST point to a valid Web page. If present, the server
// ClientURI: OPTIONAL. URL of the home page of the Client. The value of
// this field MUST point to a valid Web page. If present, the server
// SHOULD display this URL to the End-User in a followable fashion. If
// desired, representation of this Claim in different languages and
// scripts is represented as described in Section 2.1 ( Metadata
// Languages and Scripts ) .
Client_uri string `json:"client_uri,omitempty"`
ClientURI string `json:"clientURI,omitempty"`
// Logo_uri: OPTIONAL. URL that references a logo for the Client
// Id: The client ID. Ignored in client create requests.
Id string `json:"id,omitempty"`
IsAdmin bool `json:"isAdmin,omitempty"`
// LogoURI: OPTIONAL. URL that references a logo for the Client
// application. If present, the server SHOULD display this image to the
// End-User during approval. The value of this field MUST point to a
// valid image file. If desired, representation of this Claim in
// different languages and scripts is represented as described in
// Section 2.1 ( Metadata Languages and Scripts ) .
Logo_uri string `json:"logo_uri,omitempty"`
LogoURI string `json:"logoURI,omitempty"`
// Redirect_uris: REQUIRED. Array of Redirection URI values used by the
// RedirectURIs: REQUIRED. Array of Redirection URI values used by the
// Client. One of these registered Redirection URI values MUST exactly
// match the redirect_uri parameter value used in each Authorization
// Request, with the matching performed as described in Section 6.2.1 of
// [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter,
// “Uniform Resource Identifier (URI): Generic Syntax,” January
// 2005. ) (Simple String Comparison).
Redirect_uris []string `json:"redirect_uris,omitempty"`
RedirectURIs []string `json:"redirectURIs,omitempty"`
Secret string `json:"secret,omitempty"`
}
type ClientRegistrationResponse struct {
Client_id string `json:"client_id,omitempty"`
type ClientCreateRequest struct {
Client *Client `json:"client,omitempty"`
}
Client_secret string `json:"client_secret,omitempty"`
type ClientCreateResponse struct {
Client *Client `json:"client,omitempty"`
}
type State struct {
@ -310,7 +313,7 @@ func (c *ClientCreateCall) Fields(s ...googleapi.Field) *ClientCreateCall {
return c
}
func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) {
func (c *ClientCreateCall) Do() (*ClientCreateResponse, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.clientcreaterequest)
if err != nil {
@ -336,7 +339,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) {
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *ClientRegistrationResponse
var ret *ClientCreateResponse
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
@ -350,7 +353,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) {
// "$ref": "ClientCreateRequest"
// },
// "response": {
// "$ref": "ClientRegistrationResponse"
// "$ref": "ClientCreateResponse"
// }
// }

View file

@ -51,53 +51,66 @@ const DiscoveryJSON = `{
}
}
},
"ClientCreateRequest": {
"id": "ClientCreateRequest",
"type": "object",
"description": "A request to register a client with dex.",
"properties": {
"isAdmin": {
"type": "boolean"
},
"client": {
"type": "object",
"properties": {
"redirect_uris": {
"type": "array",
"items": {
"type": "string"
},
"description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)."
},
"client_name": {
"type": "string",
"description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
},
"logo_uri": {
"type": "string",
"description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
},
"client_uri": {
"type": "string",
"description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
}
}
}
"Client": {
"id": "Client",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The client ID. Ignored in client create requests."
},
"secret": {
"type": "string",
"description": "The client secret. Ignored in client create requests."
},
"secret": {
"type": "string",
"format": "byte"
},
"isAdmin": {
"type": "boolean"
},
"redirectURIs": {
"type": "array",
"items": {
"type": "string"
},
"description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)."
},
"clientName": {
"type": "string",
"description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
},
"logoURI": {
"type": "string",
"description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
},
"clientURI": {
"type": "string",
"description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
}
}
},
"ClientRegistrationResponse": {
"id": "ClientRegistrationResponse",
"type": "object",
"description": "Upon successful registration, an ID and secret is assigned to the client.",
"properties": {
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
}
}
"ClientCreateRequest": {
"id": "ClientCreateRequest",
"type": "object",
"description": "A request to register a client with dex.",
"properties": {
"client": {
"$ref": "Client"
}
}
},
"ClientCreateResponse": {
"id": "ClientCreateResponse",
"type": "object",
"description": "Upon successful registration, an ID and secret is assigned to the client.",
"properties": {
"client":{
"$ref": "Client"
}
}
}
},
"resources": {
"Admin": {
@ -160,7 +173,7 @@ const DiscoveryJSON = `{
"$ref": "ClientCreateRequest"
},
"response": {
"$ref": "ClientRegistrationResponse"
"$ref": "ClientCreateResponse"
}
}
}

View file

@ -4,11 +4,12 @@ import (
"errors"
"net/url"
"github.com/coreos/dex/client"
"github.com/coreos/go-oidc/oidc"
)
func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
ci := oidc.ClientIdentity{
func MapSchemaClientToClient(sc Client) (client.Client, error) {
ci := client.Client{
Credentials: oidc.ClientCredentials{
ID: sc.Id,
},
@ -19,12 +20,12 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
for i, ru := range sc.RedirectURIs {
if ru == "" {
return oidc.ClientIdentity{}, errors.New("redirect URL empty")
return client.Client{}, errors.New("redirect URL empty")
}
u, err := url.Parse(ru)
if err != nil {
return oidc.ClientIdentity{}, errors.New("redirect URL invalid")
return client.Client{}, errors.New("redirect URL invalid")
}
ci.Metadata.RedirectURIs[i] = *u
@ -33,7 +34,7 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
return ci, nil
}
func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client {
func MapClientToSchemaClient(c client.Client) Client {
cl := Client{
Id: c.Credentials.ID,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
@ -44,7 +45,7 @@ func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client {
return cl
}
func MapClientIdentityToSchemaClientWithSecret(c oidc.ClientIdentity) ClientWithSecret {
func MapClientToSchemaClientWithSecret(c client.Client) ClientWithSecret {
cl := ClientWithSecret{
Id: c.Credentials.ID,
Secret: c.Credentials.Secret,