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

Fix resource types and field names in docs #2

Merged
merged 1 commit into from
Jun 12, 2024
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
4 changes: 2 additions & 2 deletions docs/spec/components/schemas/Authorize.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allOf:
- $ref: '#/components/schemas/UserKey'
- $ref: '#/components/schemas/AuthorizeKey'
- type: object
x-go-is-request: true
required:
Expand All @@ -13,4 +13,4 @@ allOf:
proof:
type: object
format: json.RawMessage
description: JSON encoded ZK proof AuthV2 proof.
description: JSON-encoded Query ZK-proof.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ properties:
description: User nullifier 32 bytes
type:
type: string
enum:
- request-authorize
- request-challenge
- token
- validation
- challenge
enum: [ authorize ]
6 changes: 4 additions & 2 deletions docs/spec/components/schemas/Challenge.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allOf:
- $ref: '#/components/schemas/UserKey'
- $ref: '#/components/schemas/ChallengeKey'
- type: object
required:
- attributes
Expand All @@ -10,5 +10,7 @@ allOf:
properties:
challenge:
type: string
description: Base64 encoded challenge. Use it to generate AuthV2 ZK proof. Decode base64 string and convert into big-endian decimal number.
description: |
Base64 encoded challenge. Use it to generate Query ZK-proof.
Decode base64 string and convert into big-endian decimal number.
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
13 changes: 13 additions & 0 deletions docs/spec/components/schemas/ChallengeKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
required:
- id
- type
properties:
id:
type: string
example: "0x123...abc"
pattern: '^0x[0-9a-fA-F]{64}$'
description: User nullifier 32 bytes
type:
type: string
enum: [ challenge ]
4 changes: 0 additions & 4 deletions docs/spec/components/schemas/Claim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ type: object
required:
- nullifier
properties:
address:
type: string
example: "0xF65F3f18D9087c4E35BAC5b9746492082e186872"
description: User EVM address hex-encoded
nullifier:
type: string
example: "0x123...abc"
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/components/schemas/JWT.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ description: 'JWT token'
type: object
required:
- token
- tokenType
- token_type
properties:
token:
type: string
description: Base64 encoded JWT
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
tokenType:
token_type:
type: string
enum: [ access, refresh ]
10 changes: 5 additions & 5 deletions docs/spec/components/schemas/Token.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
allOf:
- $ref: '#/components/schemas/UserKey'
- $ref: '#/components/schemas/TokenKey'
- type: object
required:
- attributes
properties:
attributes:
required:
- accessToken
- refreshToken
- access_token
- refresh_token
type: object
properties:
accessToken:
access_token:
$ref: '#/components/schemas/JWT'
refreshToken:
refresh_token:
$ref: '#/components/schemas/JWT'
13 changes: 13 additions & 0 deletions docs/spec/components/schemas/TokenKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
required:
- id
- type
properties:
id:
type: string
example: "0x123...abc"
pattern: '^0x[0-9a-fA-F]{64}$'
description: User nullifier 32 bytes
type:
type: string
enum: [ token ]
2 changes: 1 addition & 1 deletion docs/spec/components/schemas/ValidationResult.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allOf:
- $ref: '#/components/schemas/UserKey'
- $ref: '#/components/schemas/ValidationResultKey'
- type: object
required:
- attributes
Expand Down
13 changes: 13 additions & 0 deletions docs/spec/components/schemas/ValidationResultKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
required:
- id
- type
properties:
id:
type: string
example: "0x123...abc"
pattern: '^0x[0-9a-fA-F]{64}$'
description: User nullifier 32 bytes
type:
type: string
enum: [ validation ]
2 changes: 1 addition & 1 deletion docs/spec/paths/v1@authorize@{nullifier}@challenge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ get:
- Authorize
summary: Request challenge
description: |
Request challenge to generate AuthV2 proof with
Request challenge to generate Query proof with
operationId: challenge
parameters:
- $ref: '#/components/parameters/pathNullifier'
Expand Down
8 changes: 5 additions & 3 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

GENERATOR_IMAGE=tokend/openapi-generator:v0.1.0

[[ ! -x "$(command -v go 2>/dev/null)" ]] && echo "go is not installed" && exit 1

GENERATED="${GOPATH}/src/github.com/rarimo/decentralized-auth-svc/resources"
OPENAPI_DIR="${GOPATH}/src/github.com/rarimo/decentralized-auth-svc/docs/web_deploy"
GENERATED="$PWD/resources"
OPENAPI_DIR="$PWD/docs/web_deploy"
PACKAGE_NAME=resources

function printHelp {
Expand Down Expand Up @@ -50,7 +51,8 @@ function parseArgs {

function generate {
(cd docs && npm run build)
docker run -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types
docker run --rm -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" \
generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types --meta-for-lists
goimports -w ${GENERATED}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/service/requests/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewAuthorizeRequest(r *http.Request) (*resources.AuthorizeRequest, error) {

req.Data.ID = strings.ToLower(req.Data.ID)
return req, validation.Errors{
"data/id": validation.Validate(req.Data.ID, validation.Required, validation.Match(zkp.NullifierRegexp)),
"data/id": validation.Validate(req.Data.ID, validation.Required, validation.Match(zkp.NullifierRegexp)),
"data/type": validation.Validate(req.Data.Type, validation.Required, validation.In(resources.AUTHORIZE)),
}.Filter()
}
18 changes: 15 additions & 3 deletions resources/model_authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package resources

import "encoding/json"

type Authorize struct {
Key
Attributes AuthorizeAttributes `json:"attributes"`
Expand All @@ -14,9 +16,19 @@ type AuthorizeRequest struct {
}

type AuthorizeListRequest struct {
Data []Authorize `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Data []Authorize `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Meta json.RawMessage `json:"meta,omitempty"`
}

func (r *AuthorizeListRequest) PutMeta(v interface{}) (err error) {
r.Meta, err = json.Marshal(v)
return err
}

func (r *AuthorizeListRequest) GetMeta(out interface{}) error {
return json.Unmarshal(r.Meta, out)
}

// MustAuthorize - returns Authorize from include collection.
Expand Down
2 changes: 1 addition & 1 deletion resources/model_authorize_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package resources
import "encoding/json"

type AuthorizeAttributes struct {
// JSON encoded ZK proof AuthV2 proof.
// JSON-encoded Query ZK-proof.
Proof json.RawMessage `json:"proof"`
}
18 changes: 15 additions & 3 deletions resources/model_challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package resources

import "encoding/json"

type Challenge struct {
Key
Attributes ChallengeAttributes `json:"attributes"`
Expand All @@ -14,9 +16,19 @@ type ChallengeResponse struct {
}

type ChallengeListResponse struct {
Data []Challenge `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Data []Challenge `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Meta json.RawMessage `json:"meta,omitempty"`
}

func (r *ChallengeListResponse) PutMeta(v interface{}) (err error) {
r.Meta, err = json.Marshal(v)
return err
}

func (r *ChallengeListResponse) GetMeta(out interface{}) error {
return json.Unmarshal(r.Meta, out)
}

// MustChallenge - returns Challenge from include collection.
Expand Down
2 changes: 1 addition & 1 deletion resources/model_challenge_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
package resources

type ChallengeAttributes struct {
// Base64 encoded challenge. Use it to generate AuthV2 ZK proof. Decode base64 string and convert into big-endian decimal number.
// Base64 encoded challenge. Use it to generate Query ZK-proof. Decode base64 string and convert into big-endian decimal number.
Challenge string `json:"challenge"`
}
2 changes: 0 additions & 2 deletions resources/model_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package resources

// Authorized user personal data
type Claim struct {
// User EVM address hex-encoded
Address *string `json:"address,omitempty"`
// Nullifier authorized with
Nullifier string `json:"nullifier"`
}
2 changes: 1 addition & 1 deletion resources/model_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ package resources
type Jwt struct {
// Base64 encoded JWT
Token string `json:"token"`
TokenType string `json:"tokenType"`
TokenType string `json:"token_type"`
}
9 changes: 4 additions & 5 deletions resources/model_resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ type ResourceType string

// List of ResourceType
const (
REQUEST_AUTHORIZE ResourceType = "request-authorize"
REQUEST_CHALLENGE ResourceType = "request-challenge"
TOKEN ResourceType = "token"
VALIDATION ResourceType = "validation"
CHALLENGE ResourceType = "challenge"
AUTHORIZE ResourceType = "authorize"
CHALLENGE ResourceType = "challenge"
TOKEN ResourceType = "token"
VALIDATION ResourceType = "validation"
)
18 changes: 15 additions & 3 deletions resources/model_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package resources

import "encoding/json"

type Token struct {
Key
Attributes TokenAttributes `json:"attributes"`
Expand All @@ -14,9 +16,19 @@ type TokenResponse struct {
}

type TokenListResponse struct {
Data []Token `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Data []Token `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Meta json.RawMessage `json:"meta,omitempty"`
}

func (r *TokenListResponse) PutMeta(v interface{}) (err error) {
r.Meta, err = json.Marshal(v)
return err
}

func (r *TokenListResponse) GetMeta(out interface{}) error {
return json.Unmarshal(r.Meta, out)
}

// MustToken - returns Token from include collection.
Expand Down
4 changes: 2 additions & 2 deletions resources/model_token_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
package resources

type TokenAttributes struct {
AccessToken Jwt `json:"accessToken"`
RefreshToken Jwt `json:"refreshToken"`
AccessToken Jwt `json:"access_token"`
RefreshToken Jwt `json:"refresh_token"`
}
12 changes: 12 additions & 0 deletions resources/model_validation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package resources

import "encoding/json"

type ValidationResult struct {
Key
Attributes ValidationResultAttributes `json:"attributes"`
Expand All @@ -17,6 +19,16 @@ type ValidationResultListResponse struct {
Data []ValidationResult `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Meta json.RawMessage `json:"meta,omitempty"`
}

func (r *ValidationResultListResponse) PutMeta(v interface{}) (err error) {
r.Meta, err = json.Marshal(v)
return err
}

func (r *ValidationResultListResponse) GetMeta(out interface{}) error {
return json.Unmarshal(r.Meta, out)
}

// MustValidationResult - returns ValidationResult from include collection.
Expand Down
Loading