8000 Add tests with optional body for go-server (#22034) · OpenAPITools/openapi-generator@c1931c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1931c1

Browse files
authored
Add tests with optional body for go-server (#22034)
* add tests with optional body for go-server * update workfllow
1 parent d8d9744 commit c1931c1

File tree

20 files changed

+958
-3
lines changed

20 files changed

+958
-3
lines changed

.github/workflows/samples-go.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ on:
66
- 'samples/server/petstore/go-echo-server/**'
77
- 'samples/server/petstore/go-api-server/**'
88
- 'samples/server/petstore/go-chi-server/**'
9-
- 'samples/server/others/go-server/no-body-path-params/**'
9+
- 'samples/server/others/go-server/**'
1010
pull_request:
1111
paths:
1212
- 'samples/server/petstore/go-echo-server/**'
1313
- 'samples/server/petstore/go-api-server/**'
1414
- 'samples/server/petstore/go-chi-server/**'
15-
- 'samples/server/others/go-server/no-body-path-params/**'
15+
- 'samples/server/others/go-server/**'
1616

1717
jobs:
1818
build:
@@ -26,6 +26,7 @@ jobs:
2626
- samples/server/petstore/go-api-server/
2727
- samples/server/petstore/go-chi-server/
2828
- samples/server/others/go-server/no-body-path-params/
29+
- samples/server/others/go-server/optional-body/
2930
steps:
3031
- uses: actions/checkout@v5
3132
- uses: actions/setup-go@v6
@@ -58,4 +59,4 @@ jobs:
5859
go mod tidy
5960
- name: Run tests
6061
working-directory: ${{ matrix.sample }}
61-
run: go test ./samples_tests -v
62+
run: go test ./samples_tests -v
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: go-server
2+
outputDir: samples/server/others/go-server/optional-body
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/optional_body.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/go-server
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"
7+
packageName: petstoreserver
8+
addResponseHeaders: true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.0.3
2+
info:
3+
title: optional body
4+
version: 1.0.1
5+
servers:
6+
- url: https://api.123.com/api/v1
7+
tags:
8+
- name: just-api
9+
description: Everything about API functions
10+
paths:
11+
/silly:
12+
post:
13+
tags:
14+
- just-api
15+
operationId: send_optional_payload
16+
requestBody:
17+
content:
18+
application/json:
19+
schema:
20+
$ref: "#/components/schemas/Payload"
21+
responses:
22+
'200':
23+
description: Successful operation
24+
content:
25+
application/text:
26+
schema:
27+
type: string
28+
components:
29+
schemas:
30+
Payload:
31+
type: object
32+
properties:
33+
token:
34+
type: string
35+
description: Some kind of token - usually received by Email
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Dockerfile
2+
README.md
3+
api/openapi.yaml
4+
go.mod
5+
go/api.go
6+
go/api_just_api.go
7+
go/api_just_api_service.go
8+
go/error.go
9+
go/helpers.go
10+
go/impl.go
11+
go/logger.go
12+
go/model_payload.go
13+
go/routers.go
14+
main.go
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.16.0-SNAPSHOT
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM golang:1.19 AS build
2+
WORKDIR /go/src
3+
COPY go ./go
4+
COPY main.go .
5+
COPY go.sum .
6+
COPY go.mod .
7+
8+
ENV CGO_ENABLED=0
9+
10+
RUN go build -o petstoreserver .
11+
12+
FROM scratch AS runtime
13+
COPY --from=build /go/src/petstoreserver ./
14+
EXPOSE 8080/tcp
15+
ENTRYPOINT ["./petstoreserver"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Go API Server for petstoreserver
2+
3+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4+
5+
## Overview
6+
This server was generated by the [openapi-generator]
7+
(https://openapi-generator.tech) project.
8+
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
9+
10+
To see how to make this your own, look here:
11+
12+
[README](https://openapi-generator.tech)
13+
14+
- API version: 1.0.1
15+
- Generator version: 7.16.0-SNAPSHOT
16+
17+
18+
### Running the server
19+
To run the server, follow these simple steps:
20+
21+
```
22+
go run main.go
23+
```
24+
25+
The server will be available on `http://localhost:8080`.
26+
27+
To run the server in a docker container
28+
```
29+
docker build --network=host -t petstoreserver .
30+
```
31+
32+
Once image is built use
33+
```
34+
docker run --rm -it petstoreserver
35+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.0.3
2+
info:
3+
title: optional body
4+
version: 1.0.1
5+
servers:
6+
- url: https://api.123.com/api/v1
7+
tags:
8+
- description: Everything about API functions
9+
name: just-api
10+
paths:
11+
/silly:
12+
post:
13+
operationId: send_optional_payload
14+
requestBody:
15+
content:
16+
application/json:
17+
schema:
18+
$ref: "#/components/schemas/Payload"
19+
responses:
20+
"200":
21+
content:
22+
application/text:
23+
schema:
24+
type: string
25+
description: Successful operation
26+
tags:
27+
- just-api
28+
components:
29+
schemas:
30+
Payload:
31+
example:
32+
token: token
33+
properties:
34+
token:
35+
description: Some kind of token - usually received by Email
36+
type: string
37+
type: object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module github.com/GIT_USER_ID/GIT_REPO_ID
2+
3+
go 1.18
4+

0 commit comments

Comments
 (0)
0