2024-02-01 18:57:25 +00:00
|
|
|
openapi: 3.0.0
|
|
|
|
info:
|
|
|
|
version: 1.0.0
|
|
|
|
title: golang-rest-example
|
|
|
|
license:
|
|
|
|
name: MIT
|
|
|
|
url: https://opensource.org/license/MIT/
|
|
|
|
description: >
|
|
|
|
Example OpenAPI Golang server.
|
|
|
|
servers:
|
2024-02-02 14:39:13 +00:00
|
|
|
- url: http://localhost:1234
|
2024-02-01 18:57:25 +00:00
|
|
|
description: Local server
|
|
|
|
tags:
|
|
|
|
- name: health
|
|
|
|
description: Health check
|
|
|
|
- name: users
|
|
|
|
description: User management
|
|
|
|
- name: groups
|
|
|
|
description: Group management
|
|
|
|
paths:
|
|
|
|
/healthz:
|
|
|
|
description: Health check
|
|
|
|
get:
|
|
|
|
tags:
|
|
|
|
- health
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
$ref: '#/components/responses/Ok'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
/users:
|
|
|
|
get:
|
|
|
|
description: Get all users
|
|
|
|
tags:
|
|
|
|
- users
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/components/schemas/User'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
post:
|
|
|
|
description: Create user
|
|
|
|
tags:
|
|
|
|
- users
|
|
|
|
requestBody:
|
|
|
|
description: User object
|
|
|
|
required: true
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/UserUpdate'
|
|
|
|
responses:
|
|
|
|
'201':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/User'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
/users/{id}:
|
|
|
|
get:
|
|
|
|
description: Get user by id
|
|
|
|
tags:
|
|
|
|
- users
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/User'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
put:
|
|
|
|
description: Update user by id
|
|
|
|
tags:
|
|
|
|
- users
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
requestBody:
|
|
|
|
description: User object
|
|
|
|
required: true
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/UserUpdate'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/User'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
delete:
|
|
|
|
description: Delete user by id
|
|
|
|
tags:
|
|
|
|
- users
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
$ref: '#/components/responses/Ok'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
/groups:
|
|
|
|
get:
|
|
|
|
description: Get all groups
|
|
|
|
tags:
|
|
|
|
- groups
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
type: array
|
|
|
|
items:
|
|
|
|
$ref: '#/components/schemas/Group'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
post:
|
|
|
|
description: Create group
|
|
|
|
tags:
|
|
|
|
- groups
|
|
|
|
requestBody:
|
|
|
|
description: Group object
|
|
|
|
required: true
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/GroupUpdate'
|
|
|
|
responses:
|
|
|
|
'201':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Group'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
/groups/{id}:
|
|
|
|
get:
|
|
|
|
description: Get group by id
|
|
|
|
tags:
|
|
|
|
- groups
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Group'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
put:
|
|
|
|
description: Update group by id
|
|
|
|
tags:
|
|
|
|
- groups
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
requestBody:
|
|
|
|
description: Group object
|
|
|
|
required: true
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/GroupUpdate'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Group'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
delete:
|
|
|
|
description: Delete group by id
|
|
|
|
tags:
|
|
|
|
- groups
|
|
|
|
parameters:
|
|
|
|
- name: id
|
|
|
|
in: path
|
|
|
|
required: true
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
responses:
|
|
|
|
'200':
|
|
|
|
$ref: '#/components/responses/Ok'
|
|
|
|
'404':
|
|
|
|
$ref: '#/components/responses/NotFound'
|
|
|
|
default:
|
|
|
|
$ref: '#/components/responses/UnexpectedError'
|
|
|
|
components:
|
|
|
|
responses:
|
|
|
|
Ok:
|
|
|
|
description: OK
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Ok'
|
|
|
|
NotFound:
|
|
|
|
description: Not found
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Error'
|
|
|
|
UnexpectedError:
|
|
|
|
description: Unexpected error
|
|
|
|
content:
|
|
|
|
application/json:
|
|
|
|
schema:
|
|
|
|
$ref: '#/components/schemas/Error'
|
|
|
|
schemas:
|
|
|
|
Ok:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- message
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
example: OK
|
|
|
|
Error:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- message
|
|
|
|
- code
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
message:
|
|
|
|
type: string
|
|
|
|
example: Not found
|
|
|
|
code:
|
|
|
|
type: integer
|
|
|
|
example: 404
|
|
|
|
Id:
|
|
|
|
type: integer
|
|
|
|
format: int64
|
|
|
|
example: 1
|
|
|
|
User:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- id
|
|
|
|
- name
|
|
|
|
- email
|
2024-02-02 14:39:13 +00:00
|
|
|
- group_id
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
example: John
|
|
|
|
email:
|
|
|
|
type: string
|
|
|
|
example: john@example.com
|
2024-02-02 14:39:13 +00:00
|
|
|
group_id:
|
|
|
|
$ref: '#/components/schemas/Id'
|
2024-02-01 18:57:25 +00:00
|
|
|
UserUpdate:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- name
|
|
|
|
- email
|
2024-02-02 14:39:13 +00:00
|
|
|
- group_id
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
example: John
|
|
|
|
email:
|
|
|
|
type: string
|
|
|
|
example: john@example.com
|
2024-02-02 14:39:13 +00:00
|
|
|
group_id:
|
|
|
|
$ref: '#/components/schemas/Id'
|
2024-02-01 18:57:25 +00:00
|
|
|
Group:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- id
|
|
|
|
- name
|
2024-02-02 14:39:13 +00:00
|
|
|
- user_ids
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
id:
|
|
|
|
$ref: '#/components/schemas/Id'
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
example: admins
|
2024-02-02 14:39:13 +00:00
|
|
|
user_ids:
|
2024-02-01 18:57:25 +00:00
|
|
|
type: array
|
|
|
|
items:
|
2024-02-02 14:39:13 +00:00
|
|
|
$ref: '#/components/schemas/Id'
|
2024-02-01 18:57:25 +00:00
|
|
|
GroupUpdate:
|
|
|
|
type: object
|
2024-02-01 22:09:09 +00:00
|
|
|
required:
|
|
|
|
- name
|
2024-02-01 18:57:25 +00:00
|
|
|
properties:
|
|
|
|
name:
|
|
|
|
type: string
|
|
|
|
example: admins
|