Skip to content

Commit

Permalink
Add constant type for ImageHandler to enhance clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Dec 23, 2024
1 parent 77810f0 commit d9d7cd0
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 19 deletions.
62 changes: 59 additions & 3 deletions api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8465,6 +8465,7 @@ const docTemplate = `{
"OSDiskType",
"OSDistribution",
"OSPlatform",
"Status",
"Status"
],
"properties": {
Expand Down Expand Up @@ -8494,7 +8495,11 @@ const docTemplate = `{
},
"OSArchitecture": {
"description": "arm64, x86_64 etc.",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.OSArchitecture"
}
],
"example": "x86_64"
},
"OSDiskSize": {
Expand All @@ -8514,16 +8519,37 @@ const docTemplate = `{
},
"OSPlatform": {
"description": "Linux/UNIX, Windows, NA",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.OSPlatform"
}
],
"example": "Linux/UNIX"
},
"Status": {
"description": "Available, Unavailable",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.ImageStatus"
}
],
"example": "Available"
}
}
},
"spider.ImageStatus": {
"type": "string",
"enum": [
"Available",
"Unavailable",
"NA"
],
"x-enum-varnames": [
"ImageAvailable",
"ImageUnavailable",
"ImageNA"
]
},
"spider.ImageType": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -8915,6 +8941,36 @@ const docTemplate = `{
"NodeGroupDeleting"
]
},
"spider.OSArchitecture": {
"type": "string",
"enum": [
"arm64",
"arm64_mac",
"x86_64",
"x86_64_mac",
"NA"
],
"x-enum-varnames": [
"ARM64",
"ARM64_MAC",
"X86_64",
"X86_64_MAC",
"ArchitectureNA"
]
},
"spider.OSPlatform": {
"type": "string",
"enum": [
"Linux/UNIX",
"Windows",
"NA"
],
"x-enum-varnames": [
"Linux_UNIX",
"Windows",
"PlatformNA"
]
},
"spider.Platform": {
"type": "string",
"enum": [
Expand Down
62 changes: 59 additions & 3 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8462,6 +8462,7 @@
"OSDiskType",
"OSDistribution",
"OSPlatform",
"Status",
"Status"
],
"properties": {
Expand Down Expand Up @@ -8491,7 +8492,11 @@
},
"OSArchitecture": {
"description": "arm64, x86_64 etc.",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.OSArchitecture"
}
],
"example": "x86_64"
},
"OSDiskSize": {
Expand All @@ -8511,16 +8516,37 @@
},
"OSPlatform": {
"description": "Linux/UNIX, Windows, NA",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.OSPlatform"
}
],
"example": "Linux/UNIX"
},
"Status": {
"description": "Available, Unavailable",
"type": "string",
"allOf": [
{
"$ref": "#/definitions/spider.ImageStatus"
}
],
"example": "Available"
}
}
},
"spider.ImageStatus": {
"type": "string",
"enum": [
"Available",
"Unavailable",
"NA"
],
"x-enum-varnames": [
"ImageAvailable",
"ImageUnavailable",
"ImageNA"
]
},
"spider.ImageType": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -8912,6 +8938,36 @@
"NodeGroupDeleting"
]
},
"spider.OSArchitecture": {
"type": "string",
"enum": [
"arm64",
"arm64_mac",
"x86_64",
"x86_64_mac",
"NA"
],
"x-enum-varnames": [
"ARM64",
"ARM64_MAC",
"X86_64",
"X86_64_MAC",
"ArchitectureNA"
]
},
"spider.OSPlatform": {
"type": "string",
"enum": [
"Linux/UNIX",
"Windows",
"NA"
],
"x-enum-varnames": [
"Linux_UNIX",
"Windows",
"PlatformNA"
]
},
"spider.Platform": {
"type": "string",
"enum": [
Expand Down
44 changes: 41 additions & 3 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ definitions:
example: ami-00aa5a103ddf4509f
type: string
OSArchitecture:
allOf:
- $ref: '#/definitions/spider.OSArchitecture'
description: arm64, x86_64 etc.
example: x86_64
type: string
OSDiskSize:
description: 35, etc., GB
example: "35"
Expand All @@ -357,13 +358,15 @@ definitions:
example: Ubuntu 22.04~
type: string
OSPlatform:
allOf:
- $ref: '#/definitions/spider.OSPlatform'
description: Linux/UNIX, Windows, NA
example: Linux/UNIX
type: string
Status:
allOf:
- $ref: '#/definitions/spider.ImageStatus'
description: Available, Unavailable
example: Available
type: string
required:
- GuestOS
- IId
Expand All @@ -374,7 +377,18 @@ definitions:
- OSDistribution
- OSPlatform
- Status
- Status
type: object
spider.ImageStatus:
enum:
- Available
- Unavailable
- NA
type: string
x-enum-varnames:
- ImageAvailable
- ImageUnavailable
- ImageNA
spider.ImageType:
enum:
- PublicImage
Expand Down Expand Up @@ -647,6 +661,30 @@ definitions:
- NodeGroupInactive
- NodeGroupUpdating
- NodeGroupDeleting
spider.OSArchitecture:
enum:
- arm64
- arm64_mac
- x86_64
- x86_64_mac
- NA
type: string
x-enum-varnames:
- ARM64
- ARM64_MAC
- X86_64
- X86_64_MAC
- ArchitectureNA
spider.OSPlatform:
enum:
- Linux/UNIX
- Windows
- NA
type: string
x-enum-varnames:
- Linux_UNIX
- Windows
- PlatformNA
spider.Platform:
enum:
- LINUX/UNIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,45 @@ type ImageReqInfo struct {
// @todo
}

type OSArchitecture string

const (
ARM64 OSArchitecture = "arm64"
ARM64_MAC OSArchitecture = "arm64_mac"
X86_64 OSArchitecture = "x86_64"
X86_64_MAC OSArchitecture = "x86_64_mac"
ArchitectureNA OSArchitecture = "NA"
)

type OSPlatform string

const (
Linux_UNIX OSPlatform = "Linux/UNIX"
Windows OSPlatform = "Windows"
PlatformNA OSPlatform = "NA"
)

type ImageStatus string

const (
ImageAvailable ImageStatus = "Available"
ImageUnavailable ImageStatus = "Unavailable"
ImageNA ImageStatus = "NA"
)

// ImageInfo represents the information of an Image.
type ImageInfo struct {
IId IID `json:"IId" validate:"required" description:"The ID of the image."` // {NameId, SystemId} // Deprecated
GuestOS string `json:"GuestOS" validate:"required" example:"Ubuntu 18.04" description:"The operating system of the image."` // Windows7, Ubuntu etc. // Deprecated

Name string `json:"Name" validate:"required" example:"ami-00aa5a103ddf4509f" description:"The name of the image."` // ami-00aa5a103ddf4509f
OSArchitecture string `json:"OSArchitecture" validate:"required" example:"x86_64" description:"The architecture of the operating system of the image."` // arm64, x86_64 etc.
OSPlatform string `json:"OSPlatform" validate:"required" example:"Linux/UNIX" description:"The platform of the operating system of the image."` // Linux/UNIX, Windows, NA
OSDistribution string `json:"OSDistribution" validate:"required" example:"Ubuntu 22.04~" description:"The distribution of the operating system of the image."` // Ubuntu 22.04~, CentOS 8 etc.
OSDiskType string `json:"OSDiskType" validate:"required" example:"gp3" description:"The type of the disk of the image."` // gp3, etc.
OSDiskSize string `json:"OSDiskSize" validate:"required" example:"35" description:"The size of the disk of the image."` // 35, etc., GB
Status string `json:"Status" validate:"required" example:"Available" description:"The status of the image, e.g., Available or Unavailable."` // Available, Unavailable
IId IID `json:"IId" validate:"required" description:"The ID of the image."` // {NameId, SystemId} // Deprecated
GuestOS string `json:"GuestOS" validate:"required" example:"Ubuntu 18.04" description:"The operating system of the image."` // Windows7, Ubuntu etc. // Deprecated
Status string `json:"Status" validate:"required" example:"available" description:"The status of the image, e.g., available or unavailable."` // available, unavailable // Deprecated

Name string `json:"Name" validate:"required" example:"ami-00aa5a103ddf4509f" description:"The name of the image."` // ami-00aa5a103ddf4509f
OSArchitecture OSArchitecture `json:"OSArchitecture" validate:"required" example:"x86_64" description:"The architecture of the operating system of the image."` // arm64, x86_64 etc.
OSPlatform OSPlatform `json:"OSPlatform" validate:"required" example:"Linux/UNIX" description:"The platform of the operating system of the image."` // Linux/UNIX, Windows, NA
OSDistribution string `json:"OSDistribution" validate:"required" example:"Ubuntu 22.04~" description:"The distribution of the operating system of the image."` // Ubuntu 22.04~, CentOS 8 etc.
OSDiskType string `json:"OSDiskType" validate:"required" example:"gp3" description:"The type of the disk of the image."` // gp3, etc.
OSDiskSize string `json:"OSDiskSize" validate:"required" example:"35" description:"The size of the disk of the image."` // 35, etc., GB
ImageStatus ImageStatus `json:"Status" validate:"required" example:"Available" description:"The status of the image, e.g., Available or Unavailable."` // Available, Unavailable

KeyValueList []KeyValue `json:"KeyValueList,omitempty" validate:"omitempty" description:"A list of key-value pairs associated with the image."`
}
Expand Down

0 comments on commit d9d7cd0

Please sign in to comment.