diff --git a/_example/doc/schema/schema.json b/_example/doc/schema/schema.json
index f285cd6..f9e2358 100644
--- a/_example/doc/schema/schema.json
+++ b/_example/doc/schema/schema.json
@@ -87,76 +87,6 @@
"detail"
]
},
- "misc": {
- "$schema": "http://json-schema.org/draft-04/hyper-schema",
- "title": "Misc",
- "description": "Misc",
- "stability": "prototype",
- "strictProperties": true,
- "type": [
- "object"
- ],
- "definitions": {
- "id": {
- "description": "misc id",
- "example": "ec0a1edc-062e-11e7-8b1e-040ccee2aa06",
- "readOnly": true,
- "format": "uuid",
- "type": [
- "string"
- ]
- }
- },
- "links": [
- {
- "description": "Register bool value",
- "href": "/bool/register",
- "title": "detail",
- "method": "POST",
- "rel": "create",
- "schema": {
- "properties": {
- "bool": {
- "description": "bool",
- "example": true,
- "type": [
- "boolean"
- ]
- }
- },
- "required": [
- "bool"
- ]
- },
- "targetSchema": {
- "properties": {
- "id": {
- "$ref": "#/definitions/misc/definitions/id"
- },
- "isTrue": {
- "description": "isTrue",
- "example": true,
- "type": [
- "boolean"
- ]
- }
- },
- "required": [
- "id",
- "isTrue"
- ]
- }
- }
- ],
- "properties": {
- "id": {
- "$ref": "#/definitions/user/definitions/id"
- }
- },
- "required": [
- "id"
- ]
- },
"task": {
"$schema": "http://json-schema.org/draft-04/hyper-schema",
"title": "Task",
@@ -423,9 +353,6 @@
"error": {
"$ref": "#/definitions/error"
},
- "misc": {
- "$ref": "#/definitions/misc"
- },
"task": {
"$ref": "#/definitions/task"
},
diff --git a/_example/doc/schema/schema.md b/_example/doc/schema/schema.md
index da82d0f..204a75b 100644
--- a/_example/doc/schema/schema.md
+++ b/_example/doc/schema/schema.md
@@ -24,8 +24,6 @@ Tasky-App-Version 1.0.0
## The table of contents
- Error
-- Misc
- - POST /bool/register
- Task
- GET /tasks/{task_id}
- POST /tasks
@@ -49,59 +47,6 @@ This resource represents API error
| **errorFields/name** | *string* | param field name | `"status"` |
-## Misc
-
-Stability: `prototype`
-
-Misc
-
-### Attributes
-
-| Name | Type | Description | Example |
-| ------- | ------- | ------- | ------- |
-| **[id](#resource-user)** | *uuid* | user id | `"ec0a1edc-062e-11e7-8b1e-040ccee2aa06"` |
-
-### Misc detail
-
-Register bool value
-
-```
-POST /bool/register
-```
-
-#### Required Parameters
-
-| Name | Type | Description | Example |
-| ------- | ------- | ------- | ------- |
-| **bool** | *boolean* | bool | `true` |
-
-
-
-#### Curl Example
-
-```bash
-$ curl -n -X POST https://tasky.io/v1/bool/register \
- -d '{
- "bool": true
-}' \
- -H "Content-Type: application/json"
-```
-
-
-#### Response Example
-
-```
-HTTP/1.1 201 Created
-```
-
-```json
-{
- "id": "ec0a1edc-062e-11e7-8b1e-040ccee2aa06",
- "isTrue": true
-}
-```
-
-
## Task
Stability: `prototype`
diff --git a/_example/doc/schema/schemata/misc.yml b/_example/doc/schema/schemata/misc.yml
deleted file mode 100644
index e81d40a..0000000
--- a/_example/doc/schema/schemata/misc.yml
+++ /dev/null
@@ -1,48 +0,0 @@
----
-"$schema": http://json-schema.org/draft-04/hyper-schema
-title: Misc
-description: Misc
-stability: prototype
-strictProperties: true
-type:
- - object
-
-definitions:
- id:
- description: misc id
- example: "ec0a1edc-062e-11e7-8b1e-040ccee2aa06"
- readOnly: true
- format: uuid
- type: string
-
-links:
- - description: "Register bool value"
- href: "/bool/register"
- title: detail
- method: POST
- rel: create
- schema:
- properties:
- bool:
- description: bool
- example: true
- type: boolean
- required:
- - bool
- targetSchema:
- properties:
- id:
- $ref: "/schemata/misc#/definitions/id"
- isTrue:
- description: isTrue
- example: true
- type: boolean
- required:
- - id
- - isTrue
-properties:
- id:
- $ref: "/schemata/user#/definitions/id"
-required:
- - id
-id: schemata/misc
diff --git a/_example/struct.go b/_example/struct.go
index 4eb9acf..bc915fc 100644
--- a/_example/struct.go
+++ b/_example/struct.go
@@ -12,11 +12,6 @@ type Error struct {
} `json:"errorFields,omitempty"`
}
-// Misc struct for misc resource
-type Misc struct {
- ID string `json:"id"`
-}
-
// Task struct for task resource
type Task struct {
CompletedAt time.Time `json:"completedAt"`
@@ -36,16 +31,6 @@ type User struct {
Name string `json:"name"`
}
-// MiscCreateRequest struct for misc
-// POST: /bool/register
-type MiscCreateRequest struct {
- Bool bool `json:"bool,omitempty"`
-}
-
-// MiscCreateResponse struct for misc
-// POST: /bool/register
-type MiscCreateResponse Misc
-
// TaskInstancesRequest struct for task
// GET: /tasks
type TaskInstancesRequest struct {
diff --git a/_example/validator.go b/_example/validator.go
index 7a376b8..5e53d9a 100644
--- a/_example/validator.go
+++ b/_example/validator.go
@@ -2,7 +2,6 @@ package taskyapi
import "github.com/lestrrat-go/jsval"
-var MiscCreateValidator *jsval.JSVal
var TaskCreateValidator *jsval.JSVal
var TaskInstancesValidator *jsval.JSVal
var TaskSelfValidator *jsval.JSVal
@@ -23,21 +22,6 @@ func init() {
R1 = jsval.String()
M.SetReference("#/definitions/task/definitions/tags", R0)
M.SetReference("#/definitions/task/definitions/title", R1)
- MiscCreateValidator = jsval.New().
- SetName("MiscCreateValidator").
- SetConstraintMap(M).
- SetRoot(
- jsval.Object().
- Required("bool").
- AdditionalProperties(
- jsval.EmptyConstraint,
- ).
- AddProp(
- "bool",
- jsval.Boolean(),
- ),
- )
-
TaskCreateValidator = jsval.New().
SetName("TaskCreateValidator").
SetConstraintMap(M).
diff --git a/parser.go b/parser.go
index 9e6e93c..ac23da2 100644
--- a/parser.go
+++ b/parser.go
@@ -105,7 +105,7 @@ func sortValidator(vals []*jsval.JSVal) []*jsval.JSVal {
}
// NewProperty new property
-func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema.Schema, method string, schemaRequired bool) (*Property, error) {
+func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema.Schema, method string) (*Property, error) {
// save reference before resolving ref
ref := tp.Reference
fieldSchema, err := resolveSchema(tp, root)
@@ -116,7 +116,7 @@ func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema
Name: name,
Format: string(fieldSchema.Format),
Types: fieldSchema.Type,
- Required: df.IsPropRequired(name) || schemaRequired,
+ Required: df.IsPropRequired(name),
Pattern: fieldSchema.Pattern,
Reference: ref,
Schema: fieldSchema,
@@ -145,7 +145,7 @@ func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema
// log.Printf("inline obj: %s: %v", name, fieldSchema.Properties)
var inlineFields []*Property
for k, prop := range fieldSchema.Properties {
- f, err := NewProperty(k, prop, df, root, method, false)
+ f, err := NewProperty(k, prop, df, root, method)
if err != nil {
return nil, errors.Wrapf(err, "failed to perse inline object: %s", k)
}
@@ -167,7 +167,7 @@ func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema
// log.Printf("resolved inline obj: %s: %v", name, item.Properties)
var inlineFields []*Property
for k, prop := range item.Properties {
- f, err := NewProperty(k, prop, df, root, method, false)
+ f, err := NewProperty(k, prop, df, root, method)
if err != nil {
return nil, errors.Wrapf(err, "failed to perse inline object: %s", k)
}
@@ -179,7 +179,7 @@ func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema
// log.Printf("resolved inline obj: %s: %v", name, resolvedItem.Properties)
var inlineFields []*Property
for k, prop := range resolvedItem.Properties {
- f, err := NewProperty(k, prop, df, root, method, false)
+ f, err := NewProperty(k, prop, df, root, method)
if err != nil {
return nil, errors.Wrapf(err, "failed to perse inline object: %s", k)
}
@@ -196,7 +196,7 @@ func NewProperty(name string, tp *schema.Schema, df *schema.Schema, root *schema
// inline object without definitions
var inlineFields []*Property
for k, prop := range fieldSchema.Properties {
- f, err := NewProperty(k, prop, df, root, method, false)
+ f, err := NewProperty(k, prop, df, root, method)
if err != nil {
return nil, errors.Wrapf(err, "failed to perse inline object: %s", k)
}
@@ -248,15 +248,7 @@ func (p *Parser) ParseResources() (map[string]Resource, error) {
// parse resource field
var flds []*Property
for name, tp := range df.Properties {
- schemaRequired := false
- for _, required := range df.Required {
- if required == name {
- schemaRequired = true
- break
- }
- }
-
- fld, err := NewProperty(name, tp, df, p.schema, "", schemaRequired)
+ fld, err := NewProperty(name, tp, df, p.schema, "")
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", id)
}
@@ -302,15 +294,7 @@ func (p *Parser) ParseActions(res map[string]Resource) (map[string][]Action, err
if e.Schema != nil {
var flds []*Property
for name, tp := range e.Schema.Properties {
- schemaRequired := false
- for _, required := range e.Schema.Required {
- if required == name {
- schemaRequired = true
- break
- }
- }
-
- fld, err := NewProperty(name, tp, df, p.schema, e.Method, schemaRequired)
+ fld, err := NewProperty(name, tp, df, p.schema, e.Method)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", id)
}
@@ -330,14 +314,7 @@ func (p *Parser) ParseActions(res map[string]Resource) (map[string][]Action, err
case e.TargetSchema.Reference == "":
var flds []*Property
for name, tp := range e.TargetSchema.Properties {
- schemaRequired := false
- for _, required := range e.TargetSchema.Required {
- if required == name {
- schemaRequired = true
- break
- }
- }
- fld, err := NewProperty(name, tp, df, p.schema, e.Method, schemaRequired)
+ fld, err := NewProperty(name, tp, df, p.schema, e.Method)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", id)
}
@@ -358,7 +335,7 @@ func (p *Parser) ParseActions(res map[string]Resource) (map[string][]Action, err
IsPrimary: false,
}
case e.TargetSchema.Reference != "" && !IsRefToMainResource(e.TargetSchema.Reference):
- fld, err := NewProperty(e.TargetSchema.ID, e.TargetSchema, df, p.schema, e.Method, false)
+ fld, err := NewProperty(e.TargetSchema.ID, e.TargetSchema, df, p.schema, e.Method)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", id)
}
diff --git a/parser_test.go b/parser_test.go
index 4586a24..d2387b5 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -68,37 +68,3 @@ func TestParseActions(t *testing.T) {
}
}
}
-
-func TestParseActions_SchemaRequired(t *testing.T) {
- parser := testNewParser(t)
- r, err := parser.ParseResources()
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := parser.ParseActions(r)
- if err != nil {
- t.Fatal(err)
- }
-
- a := res["misc"][0]
- if a.Href != "/bool/register" {
- t.Fatalf("href is not /bool/register, %s", a.Href)
- }
-
- name := a.Request.Properties[0]
- if name.Name != "bool" {
- t.Fatalf("not a target: %s", name.Name)
- }
- if !name.Required {
- t.Fatal("bool is required")
- }
-
- isTrue := a.Response.Properties[1]
- if isTrue.Name != "isTrue" {
- t.Fatalf("not a target: %s", isTrue.Name)
- }
- if !isTrue.Required {
- t.Fatal("isTrue is required")
- }
-}