Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger #25

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ WORKDIR /go/src/github.com/bavix/gripmock

EXPOSE 4770 4771

HEALTHCHECK CMD curl --fail http://127.0.0.1:4771/health
HEALTHCHECK CMD curl --fail http://127.0.0.1:4771/api/health/readiness

ENTRYPOINT ["gripmock"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ lint-fix:

intgr-test: build
docker compose -f deployments/docker-compose/docker-compose.yml up

# before: go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
gen:
oapi-codegen -generate gorilla,types -package rest ./api/openapi/api.yaml > internal/domain/rest/api.gen.go
oapi-codegen -generate client,types -package sdk ./api/openapi/api.yaml > pkg/sdk/api.gen.go
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![GripMock](https://github.com/bavix/gripmock/assets/5111255/1471ddff-b0f7-48b7-851c-67d26edf271b)
![GripMock](https://github.com/bavix/gripmock/assets/5111255/bbb14393-2b71-4136-875f-e2e4d0b6bcb9)

# GripMock
GripMock is a **mock server** for **GRPC** services. It's using a `.proto` file to generate implementation of gRPC service for you.
Expand Down
249 changes: 249 additions & 0 deletions api/openapi/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
openapi: 3.0.2
servers:
- url: /api
info:
version: 2.0.0
title: GripMock API Schema
tags:
- name: stubs
description: Stubs storage management
- name: healthcheck
description: Healthcheck
paths:
# healthcheck
/health/liveness:
get:
tags:
- healthcheck
summary: Liveness check
description: The test says that the service is alive and yet
operationId: liveness
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/MessageOK'
/health/readiness:
get:
tags:
- healthcheck
summary: Readiness check
description: The test indicates readiness to receive traffic
operationId: readiness
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/MessageOK'

# stubs
/stubs:
get:
tags:
- stubs
summary: Getting a list of stubs
description: The list of stubs is required to view all added stubs
operationId: listStubs
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/StubList'
post:
tags:
- stubs
summary: Add a new stub to the store
description: Add a new stub to the store
operationId: addStub
responses:
'200':
description: Successful operation
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ListID'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/StubList'
- $ref: '#/components/schemas/Stub'
delete:
tags:
- stubs
summary: Remove all stubs
description: Completely clears the stub storage
operationId: purgeStubs
responses:
'204':
description: Successful operation
'/stubs/{uuid}':
delete:
tags:
- stubs
summary: Deletes stub by ID
description: The method removes the stub by ID
operationId: deleteStubByID
parameters:
- name: uuid
in: path
description: ID of stub
required: true
schema:
$ref: '#/components/schemas/ID'
responses:
'204':
description: successful operation
'404':
description: Pet not found
'/stubs/search':
post:
tags:
- stubs
summary: Stub storage search
description: Performs a search for a stub by the given conditions
operationId: searchStubs
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/SearchResponse'
requestBody:
description: Description of filtering
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SearchRequest'
components:
schemas:
# health
MessageOK:
type: object
required:
- message
- time
properties:
message:
type: string
time:
type: string
format: date-time
# stubs
ID:
type: string
format: uuid
example: 51c50050-ec27-4dae-a583-a32ca71a1dd5
ListID:
type: array
items:
$ref: '#/components/schemas/ID'
StubList:
type: array
items:
$ref: '#/components/schemas/Stub'
SearchRequest:
type: object
required:
- service
- method
- data
properties:
service:
type: string
example: Gripmock
method:
type: string
example: SayHello
data:
type: object
x-go-type: interface{}
additionalProperties: true
SearchResponse:
type: object
required:
- data
- error
properties:
data:
type: object
x-go-type: interface{}
additionalProperties: true
error:
type: string
example: Message not found
code:
type: integer
format: uint32
x-go-type: codes.Code
x-go-type-import:
name: codes
path: google.golang.org/grpc/codes
example: 3
Stub:
type: object
required:
- service
- method
- input
- output
properties:
id:
$ref: '#/components/schemas/ID'
service:
type: string
example: Gripmock
method:
type: string
example: SayHello
input:
$ref: '#/components/schemas/StubInput'
output:
$ref: '#/components/schemas/StubOutput'
StubInput:
type: object
properties:
equals:
type: object
additionalProperties: true
x-go-type-skip-optional-pointer: true
contains:
type: object
additionalProperties: true
x-go-type-skip-optional-pointer: true
matches:
type: object
additionalProperties: true
x-go-type-skip-optional-pointer: true
StubOutput:
type: object
required:
- data
- error
properties:
data:
type: object
additionalProperties: true
error:
type: string
example: Message not found
code:
type: integer
format: uint32
x-go-type: codes.Code
x-go-type-import:
name: codes
path: google.golang.org/grpc/codes
example: 3
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

---

![GripMock](https://github.com/bavix/gripmock/assets/5111255/11e1aa7f-80a7-4e48-980b-15f66451d2ab)
![GripMock](https://github.com/bavix/gripmock/assets/5111255/353dcdcf-747f-4332-8432-c9ba876f3760)

`GripMock` is a mock server for GRPC services.

Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@ require (
github.com/bavix/gripmock/protogen v0.0.0
github.com/bavix/gripmock/protogen/example v0.0.0
github.com/goccy/go-yaml v1.11.0
github.com/google/uuid v1.3.0
github.com/google/uuid v1.3.1
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/lithammer/fuzzysearch v1.1.8
github.com/oapi-codegen/runtime v1.0.0
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.12.0
golang.org/x/text v0.13.0
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading