update return type to be nullable

This commit is contained in:
Hayden 2022-10-19 21:27:48 -08:00
parent 88bb9a4f52
commit 63406747df
4 changed files with 58 additions and 8 deletions

View file

@ -1232,6 +1232,10 @@ const docTemplate = `{
}, },
"name": { "name": {
"type": "string" "type": "string"
},
"parentId": {
"type": "string",
"x-nullable": true
} }
} }
}, },
@ -1270,6 +1274,12 @@ const docTemplate = `{
"$ref": "#/definitions/repo.ItemAttachment" "$ref": "#/definitions/repo.ItemAttachment"
} }
}, },
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.ItemSummary"
}
},
"createdAt": { "createdAt": {
"type": "string" "type": "string"
}, },
@ -1277,7 +1287,6 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"fields": { "fields": {
"description": "Future",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/repo.ItemField" "$ref": "#/definitions/repo.ItemField"
@ -1316,6 +1325,11 @@ const docTemplate = `{
"description": "Extras", "description": "Extras",
"type": "string" "type": "string"
}, },
"parent": {
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.ItemSummary"
},
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },
@ -1439,6 +1453,10 @@ const docTemplate = `{
"description": "Extras", "description": "Extras",
"type": "string" "type": "string"
}, },
"parentId": {
"type": "string",
"x-nullable": true
},
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },

View file

@ -1224,6 +1224,10 @@
}, },
"name": { "name": {
"type": "string" "type": "string"
},
"parentId": {
"type": "string",
"x-nullable": true
} }
} }
}, },
@ -1262,6 +1266,12 @@
"$ref": "#/definitions/repo.ItemAttachment" "$ref": "#/definitions/repo.ItemAttachment"
} }
}, },
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.ItemSummary"
}
},
"createdAt": { "createdAt": {
"type": "string" "type": "string"
}, },
@ -1269,7 +1279,6 @@
"type": "string" "type": "string"
}, },
"fields": { "fields": {
"description": "Future",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/repo.ItemField" "$ref": "#/definitions/repo.ItemField"
@ -1308,6 +1317,11 @@
"description": "Extras", "description": "Extras",
"type": "string" "type": "string"
}, },
"parent": {
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.ItemSummary"
},
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },
@ -1431,6 +1445,10 @@
"description": "Extras", "description": "Extras",
"type": "string" "type": "string"
}, },
"parentId": {
"type": "string",
"x-nullable": true
},
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string"
}, },

View file

@ -62,6 +62,9 @@ definitions:
type: string type: string
name: name:
type: string type: string
parentId:
type: string
x-nullable: true
type: object type: object
repo.ItemField: repo.ItemField:
properties: properties:
@ -86,12 +89,15 @@ definitions:
items: items:
$ref: '#/definitions/repo.ItemAttachment' $ref: '#/definitions/repo.ItemAttachment'
type: array type: array
children:
items:
$ref: '#/definitions/repo.ItemSummary'
type: array
createdAt: createdAt:
type: string type: string
description: description:
type: string type: string
fields: fields:
description: Future
items: items:
$ref: '#/definitions/repo.ItemField' $ref: '#/definitions/repo.ItemField'
type: array type: array
@ -118,6 +124,10 @@ definitions:
notes: notes:
description: Extras description: Extras
type: string type: string
parent:
$ref: '#/definitions/repo.ItemSummary'
x-nullable: true
x-omitempty: true
purchaseFrom: purchaseFrom:
type: string type: string
purchasePrice: purchasePrice:
@ -202,6 +212,9 @@ definitions:
notes: notes:
description: Extras description: Extras
type: string type: string
parentId:
type: string
x-nullable: true
purchaseFrom: purchaseFrom:
type: string type: string
purchasePrice: purchasePrice:

View file

@ -40,7 +40,7 @@ type (
ItemCreate struct { ItemCreate struct {
ImportRef string `json:"-"` ImportRef string `json:"-"`
ParentID uuid.UUID `json:"parentId"` ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
@ -49,7 +49,7 @@ type (
LabelIDs []uuid.UUID `json:"labelIds"` LabelIDs []uuid.UUID `json:"labelIds"`
} }
ItemUpdate struct { ItemUpdate struct {
ParentID uuid.UUID `json:"parentId"` ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
@ -102,7 +102,7 @@ type (
} }
ItemOut struct { ItemOut struct {
Parent ItemSummary `json:"parent,omitempty"` Parent *ItemSummary `json:"parent,omitempty" extensions:"x-nullable,x-omitempty"`
ItemSummary ItemSummary
SerialNumber string `json:"serialNumber"` SerialNumber string `json:"serialNumber"`
@ -202,9 +202,10 @@ func mapItemOut(item *ent.Item) ItemOut {
children = mapEach(item.Edges.Children, mapItemSummary) children = mapEach(item.Edges.Children, mapItemSummary)
} }
var parent ItemSummary var parent *ItemSummary
if item.Edges.Parent != nil { if item.Edges.Parent != nil {
parent = mapItemSummary(item.Edges.Parent) v := mapItemSummary(item.Edges.Parent)
parent = &v
} }
return ItemOut{ return ItemOut{