Commit f309896f authored by He Weiwei's avatar He Weiwei
Browse files

refactor(api): generate project apis by go-swagger


Signed-off-by: default avatarHe Weiwei <hweiwei@vmware.com>
parent 6c168174
......@@ -310,7 +310,7 @@ endif
SWAGGER_IMAGENAME=goharbor/swagger
SWAGGER_VERSION=v0.21.0
SWAGGER=$(DOCKERCMD) run --rm -u $(shell id -u):$(shell id -g) -v $(BUILDPATH):$(BUILDPATH) -w $(BUILDPATH) ${SWAGGER_IMAGENAME}:${SWAGGER_VERSION}
SWAGGER_GENERATE_SERVER=${SWAGGER} generate server --template-dir=$(TOOLSPATH)/swagger/templates --exclude-main
SWAGGER_GENERATE_SERVER=${SWAGGER} generate server --template-dir=$(TOOLSPATH)/swagger/templates --exclude-main --additional-initialism=CVE
SWAGGER_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/swagger/Dockerfile --build-arg SWAGGER_VERSION=${SWAGGER_VERSION} -t ${SWAGGER_IMAGENAME}:$(SWAGGER_VERSION) .
SWAGGER_IMAGENAME:
......
......@@ -53,214 +53,6 @@ paths:
$ref: '#/definitions/Search'
'500':
description: Unexpected internal errors.
/projects:
get:
summary: List projects
description: |
This endpoint returns all projects created by Harbor, and can be filtered by project name.
parameters:
- name: name
in: query
description: The name of project.
required: false
type: string
- name: public
in: query
description: The project is public or private.
required: false
type: boolean
format: int32
- name: owner
in: query
description: The name of project owner.
required: false
type: string
- name: page
in: query
type: integer
format: int32
required: false
description: 'The page number, default is 1.'
- name: page_size
in: query
type: integer
format: int32
required: false
description: 'The size of per page, default is 10, maximum is 100.'
tags:
- Products
responses:
'200':
description: Return all matched projects.
schema:
type: array
items:
$ref: '#/definitions/Project'
headers:
X-Total-Count:
description: The total count of projects
type: integer
Link:
description: Link refers to the previous page and next page
type: string
'401':
description: User need to log in first.
'500':
description: Internal errors.
head:
summary: Check if the project name user provided already exists.
description: |
This endpoint is used to check if the project name user provided already exist.
parameters:
- name: project_name
in: query
description: Project name for checking exists.
required: true
type: string
tags:
- Products
responses:
'200':
description: Project name exists.
'404':
description: Project name does not exist.
'500':
description: Unexpected internal errors.
post:
summary: Create a new project.
description: |
This endpoint is for user to create a new project.
parameters:
- name: project
in: body
description: New created project.
required: true
schema:
$ref: '#/definitions/ProjectReq'
tags:
- Products
responses:
'201':
description: Project created successfully.
'400':
description: Unsatisfied with constraints of the project creation.
'401':
description: User need to log in first.
'409':
description: Project name already exists.
'415':
$ref: '#/responses/UnsupportedMediaType'
'500':
description: Unexpected internal errors.
'/projects/{project_id}':
get:
summary: Return specific project detail information
description: |
This endpoint returns specific project information by project ID.
parameters:
- name: project_id
in: path
description: Project ID for filtering results.
required: true
type: integer
format: int64
tags:
- Products
responses:
'200':
description: Return matched project information.
schema:
$ref: '#/definitions/Project'
'401':
description: User need to log in first.
'500':
description: Internal errors.
put:
summary: Update properties for a selected project.
description: |
This endpoint is aimed to update the properties of a project.
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Selected project ID.
- name: project
in: body
required: true
schema:
$ref: '#/definitions/ProjectReq'
description: Updates of project.
tags:
- Products
responses:
'200':
description: Updated project properties successfully.
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User does not have permission to the project.
'404':
description: Project ID does not exist.
'500':
description: Unexpected internal errors.
delete:
summary: Delete project by projectID
description: |
This endpoint is aimed to delete project by project ID.
parameters:
- name: project_id
in: path
description: Project ID of project which will be deleted.
required: true
type: integer
format: int64
tags:
- Products
responses:
'200':
description: Project is deleted successfully.
'400':
description: Invalid project id.
'403':
description: User need to log in first.
'404':
description: Project does not exist.
'412':
description: 'Project contains policies, can not be deleted.'
'500':
description: Internal errors.
'/projects/{project_id}/summary':
get:
summary: Get summary of the project.
description: Get summary of the project.
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Relevant project ID
tags:
- Products
responses:
'200':
description: Get summary of the project successfully.
schema:
$ref: '#/definitions/ProjectSummary'
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User does not have permission to get summary of the project.
'404':
description: Project ID does not exist.
'500':
description: Unexpected internal errors.
'/projects/{project_id}/metadatas':
get:
summary: Get project metadata.
......
......@@ -20,6 +20,213 @@ security:
- basic: []
- {}
paths:
/projects:
get:
summary: List projects
description: This endpoint returns projects created by Harbor.
tags:
- project
operationId: listProjects
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: name
in: query
description: The name of project.
required: false
type: string
- name: public
in: query
description: The project is public or private.
required: false
type: boolean
format: int32
- name: owner
in: query
description: The name of project owner.
required: false
type: string
responses:
'200':
description: Return all matched projects.
schema:
type: array
items:
$ref: '#/definitions/Project'
headers:
X-Total-Count:
description: The total count of projects
type: integer
Link:
description: Link refers to the previous page and next page
type: string
'401':
$ref: '#/responses/401'
'500':
$ref: '#/responses/500'
head:
summary: Check if the project name user provided already exists.
description: This endpoint is used to check if the project name provided already exist.
tags:
- project
operationId: headProject
parameters:
- $ref: '#/parameters/requestId'
- name: project_name
in: query
description: Project name for checking exists.
required: true
type: string
responses:
'200':
$ref: '#/responses/200'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
post:
summary: Create a new project.
description: This endpoint is for user to create a new project.
tags:
- project
operationId: createProject
parameters:
- $ref: '#/parameters/requestId'
- name: project
in: body
description: New created project.
required: true
schema:
$ref: '#/definitions/ProjectReq'
responses:
'201':
$ref: '#/responses/201'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'409':
$ref: '#/responses/409'
'500':
$ref: '#/responses/500'
'/projects/{project_id}':
get:
summary: Return specific project detail information
description: This endpoint returns specific project information by project ID.
tags:
- project
operationId: getProject
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectId'
responses:
'200':
description: Return matched project information.
schema:
$ref: '#/definitions/Project'
'401':
$ref: '#/responses/401'
'500':
$ref: '#/responses/500'
put:
summary: Update properties for a selected project.
description: This endpoint is aimed to update the properties of a project.
tags:
- project
operationId: updateProject
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectId'
- name: project
in: body
required: true
schema:
$ref: '#/definitions/ProjectReq'
description: Updates of project.
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
delete:
summary: Delete project by projectID
description: This endpoint is aimed to delete project by project ID.
tags:
- project
operationId: deleteProject
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectId'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'412':
$ref: '#/responses/412'
'500':
$ref: '#/responses/500'
/projects/{project_id}/_deletable:
get:
summary: Get the deletable status of the project
description: Get the deletable status of the project
tags:
- project
operationId: getProjectDeletable
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectId'
responses:
'200':
description: Return deletable status of the project.
schema:
$ref: '#/definitions/ProjectDeletable'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
'/projects/{project_id}/summary':
get:
summary: Get summary of the project.
description: Get summary of the project.
tags:
- project
operationId: getProjectSummary
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectId'
responses:
'200':
description: Get summary of the project successfully.
schema:
$ref: '#/definitions/ProjectSummary'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories:
get:
summary: List repositories
......@@ -1252,7 +1459,8 @@ parameters:
in: path
description: The ID of the project
required: true
type: string
type: integer
format: int64
repositoryName:
name: repository_name
in: path
......@@ -1293,6 +1501,7 @@ parameters:
required: false
description: The size of per page
default: 10
maximum: 100
instanceName:
name: preheat_instance_name
in: path
......@@ -1387,6 +1596,14 @@ responses:
type: string
schema:
$ref: '#/definitions/Errors'
'412':
description: Precondition failed
headers:
X-Request-Id:
description: The ID of the corresponding request for the response
type: string
schema:
$ref: '#/definitions/Errors'
'500':
description: Internal server error
headers:
......@@ -1958,3 +2175,243 @@ definitions:
content:
type: string
description: The base64 encoded content of the icon
ProjectReq:
type: object
properties:
project_name:
type: string
description: The name of the project.
public:
type: boolean
description: deprecated, reserved for project creation in replication
x-nullable: true
metadata:
description: The metadata of the project.
$ref: '#/definitions/ProjectMetadata'
cve_allowlist:
description: The CVE allowlist of the project.
$ref: '#/definitions/CVEAllowlist'
storage_limit:
type: integer
format: int64
description: The storage quota of the project.
x-nullable: true
registry_id:
type: integer
format: int64
description: The ID of referenced registry when creating the proxy cache project
x-nullable: true
Project:
type: object
properties:
project_id:
type: integer
format: int32
description: Project ID
owner_id:
type: integer
format: int32
description: The owner ID of the project always means the creator of the project.
name:
type: string
description: The name of the project.
registry_id:
type: integer
format: int64
description: The ID of referenced registry when the project is a proxy cache project.
creation_time:
type: string
format: date-time
description: The creation time of the project.
update_time:
type: string
format: date-time
description: The update time of the project.
deleted:
type: boolean
description: A deletion mark of the project.
owner_name:
type: string
description: The owner name of the project.
togglable:
type: boolean
description: Correspond to the UI about whether the project's publicity is updatable (for UI)
current_user_role_id:
type: integer
description: The role ID with highest permission of the current user who triggered the API (for UI). This attribute is deprecated and will be removed in future versions.
current_user_role_ids:
type: array
items:
type: integer
format: int32
description: The list of role ID of the current user who triggered the API (for UI)
repo_count:
type: integer
description: The number of the repositories under this project.
chart_count:
type: integer
description: The total number of charts under this project.
metadata:
description: The metadata of the project.
$ref: '#/definitions/ProjectMetadata'
cve_allowlist:
description: The CVE allowlist of this project.
$ref: '#/definitions/CVEAllowlist'
ProjectDeletable:
type: object
properties:
deletable:
type: boolean
description: Whether the project can be deleted.
message:
type: string
description: The detail message when the project can not be deleted.
ProjectMetadata:
type: object
properties:
public:
type: string
description: 'The public status of the project. The valid values are "true", "false".'
enable_content_trust:
type: string
description: 'Whether content trust is enabled or not. If it is enabled, user can''t pull unsigned images from this project. The valid values are "true", "false".'
x-nullable: true
prevent_vul:
type: string
description: 'Whether prevent the vulnerable images from running. The valid values are "true", "false".'
x-nullable: true
severity:
type: string
description: 'If the vulnerability is high than severity defined here, the images can''t be pulled. The valid values are "none", "low", "medium", "high", "critical".'
x-nullable: true
auto_scan:
type: string
description: 'Whether scan images automatically when pushing. The valid values are "true", "false".'
x-nullable: true
reuse_sys_cve_allowlist:
type: string
description: 'Whether this project reuse the system level CVE allowlist as the allowlist of its own. The valid values are "true", "false".
If it is set to "true" the actual allowlist associate with this project, if any, will be ignored.'
x-nullable: true
retention_id:
type: string
description: 'The ID of the tag retention policy for the project'
x-nullable: true
ProjectSummary:
type: object
properties:
repo_count:
type: integer
description: The number of the repositories under this project.
chart_count:
type: integer
description: The total number of charts under this project.
project_admin_count:
type: integer
description: The total number of project admin members.
maintainer_count:
type: integer
description: The total number of maintainer members.
developer_count:
type: integer
description: The total number of developer members.
guest_count:
type: integer