Skip to content

Commit

Permalink
Add handler option to document text req body, fix req setter and load…
Browse files Browse the repository at this point in the history
…er (#135)
  • Loading branch information
vearutop authored Feb 9, 2023
1 parent f931b97 commit 9e8e48a
Show file tree
Hide file tree
Showing 38 changed files with 276 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
GO111MODULE: "on"
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
GO_VERSION: 1.18.x
GO_VERSION: 1.20.x
jobs:
bench:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
GO111MODULE: "on"
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
GO_VERSION: 1.19.x
GO_VERSION: 1.20.x
jobs:
bench:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.20.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.1
uses: golangci/golangci-lint-action@v3.4.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.50.1
version: v1.51.1

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.19.x
GO_VERSION: 1.20.x
jobs:
gorelease:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x ]
go-version: [1.20.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ concurrency:
env:
GO111MODULE: "on"
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
COV_GO_VERSION: 1.18.x # Version of Go to collect coverage
COV_GO_VERSION: 1.20.x # Version of Go to collect coverage
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x ]
go-version: [ 1.13.x, 1.19.x, 1.20.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.50.1" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.51.1" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
94 changes: 69 additions & 25 deletions _examples/advanced-generic/_testdata/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"paths":{
"/deeper-with-session/one":{
"get":{
"summary":"Dummy","operationId":"_examples/advanced-generic.dummy2",
"tags":["Other"],"summary":"Dummy","operationId":"_examples/advanced-generic.dummy2",
"responses":{
"204":{"description":"No Content"},
"401":{
Expand All @@ -17,7 +17,7 @@
},
"/deeper-with-session/two":{
"get":{
"summary":"Dummy","operationId":"_examples/advanced-generic.dummy3",
"tags":["Other"],"summary":"Dummy","operationId":"_examples/advanced-generic.dummy3",
"responses":{
"204":{"description":"No Content"},
"401":{
Expand All @@ -30,7 +30,7 @@
},
"/error-response":{
"get":{
"summary":"Declare Expected Errors",
"tags":["Response"],"summary":"Declare Expected Errors",
"description":"This use case demonstrates documentation of expected errors.",
"operationId":"_examples/advanced-generic.errorResponse",
"parameters":[
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"/file-multi-upload":{
"post":{
"summary":"Files Uploads With 'multipart/form-data'",
"tags":["Request"],"summary":"Files Uploads With 'multipart/form-data'",
"operationId":"_examples/advanced-generic.fileMultiUploader",
"parameters":[
{
Expand All @@ -87,7 +87,8 @@
},
"/file-upload":{
"post":{
"summary":"File Upload With 'multipart/form-data'","operationId":"_examples/advanced-generic.fileUploader",
"tags":["Request"],"summary":"File Upload With 'multipart/form-data'",
"operationId":"_examples/advanced-generic.fileUploader",
"parameters":[
{
"name":"in_query","in":"query","description":"Simple scalar value in query.",
Expand All @@ -103,7 +104,7 @@
},
"/form":{
"post":{
"summary":"Request With Form",
"tags":["Request"],"summary":"Request With Form",
"description":"The `form` field tag acts as `query` and `formData`, with priority on `formData`.\n\nIt is decoded with `http.Request.Form` values.",
"operationId":"_examples/advanced-generic.form",
"parameters":[
Expand All @@ -123,7 +124,7 @@
},
"/gzip-pass-through":{
"get":{
"summary":"Direct Gzip","operationId":"_examples/advanced-generic.directGzip",
"tags":["Response"],"summary":"Direct Gzip","operationId":"_examples/advanced-generic.directGzip",
"parameters":[
{
"name":"plainStruct","in":"query","description":"Output plain structure instead of gzip container.",
Expand All @@ -143,7 +144,7 @@
"x-forbid-unknown-query":true
},
"head":{
"summary":"Direct Gzip","operationId":"_examples/advanced-generic.directGzip2",
"tags":["Response"],"summary":"Direct Gzip","operationId":"_examples/advanced-generic.directGzip2",
"parameters":[
{
"name":"plainStruct","in":"query","description":"Output plain structure instead of gzip container.",
Expand All @@ -165,8 +166,8 @@
},
"/html-response/{id}":{
"get":{
"summary":"Request With HTML Response","description":"Request with templated HTML response.",
"operationId":"_examples/advanced-generic.htmlResponse",
"tags":["Response"],"summary":"Request With HTML Response",
"description":"Request with templated HTML response.","operationId":"_examples/advanced-generic.htmlResponse",
"parameters":[
{"name":"filter","in":"query","schema":{"type":"string"}},
{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},
Expand All @@ -183,7 +184,7 @@
},
"/json-body-manual/{in-path}":{
"post":{
"summary":"Request With JSON Body and manual decoder",
"tags":["Request"],"summary":"Request With JSON Body and manual decoder",
"description":"Request with JSON body and query/header/path params, response with JSON body and data from request.",
"operationId":"_examples/advanced-generic.jsonBodyManual",
"parameters":[
Expand Down Expand Up @@ -212,7 +213,7 @@
},
"/json-body-validation/{in-path}":{
"post":{
"summary":"Request With JSON Body and non-trivial validation",
"tags":["Request","Response","Validation"],"summary":"Request With JSON Body and non-trivial validation",
"description":"Request with JSON body and query/header/path params, response with JSON body and data from request.",
"operationId":"_examples/advanced-generic.jsonBodyValidation",
"parameters":[
Expand Down Expand Up @@ -241,7 +242,7 @@
},
"/json-body/{in-path}":{
"post":{
"summary":"Request With JSON Body",
"tags":["Request"],"summary":"Request With JSON Body",
"description":"Request with JSON body and query/header/path params, response with JSON body and data from request.",
"operationId":"_examples/advanced-generic.jsonBody",
"parameters":[
Expand Down Expand Up @@ -270,8 +271,8 @@
},
"/json-map-body":{
"post":{
"summary":"Request With JSON Map In Body","description":"Request with JSON object (map) body.",
"operationId":"_examples/advanced-generic.jsonMapBody",
"tags":["Request"],"summary":"Request With JSON Map In Body",
"description":"Request with JSON object (map) body.","operationId":"_examples/advanced-generic.jsonMapBody",
"parameters":[
{
"name":"in_query","in":"query","description":"Simple scalar value in query.",
Expand All @@ -294,7 +295,7 @@
},
"/json-param/{in-path}":{
"get":{
"summary":"Request With JSON Query Parameter",
"tags":["Request"],"summary":"Request With JSON Query Parameter",
"description":"Request with JSON body and query/header/path params, response with JSON body and data from request.",
"operationId":"_examples/advanced-generic.jsonParam",
"parameters":[
Expand Down Expand Up @@ -330,7 +331,8 @@
},
"/json-slice-body":{
"post":{
"summary":"Request With JSON Array In Body","operationId":"_examples/advanced-generic.jsonSliceBody",
"tags":["Request"],"summary":"Request With JSON Array In Body",
"operationId":"_examples/advanced-generic.jsonSliceBody",
"parameters":[
{
"name":"in_query","in":"query","description":"Simple scalar value in query.",
Expand All @@ -353,7 +355,7 @@
},
"/no-validation":{
"post":{
"summary":"No Validation","description":"Input/Output without validation.",
"tags":["Request","Response"],"summary":"No Validation","description":"Input/Output without validation.",
"operationId":"_examples/advanced-generic.noValidation",
"parameters":[
{"name":"q","in":"query","schema":{"type":"boolean"}},
Expand All @@ -375,7 +377,7 @@
},
"/output-csv-writer":{
"get":{
"summary":"Output With Stream Writer","description":"Output with stream writer.",
"tags":["Response"],"summary":"Output With Stream Writer","description":"Output with stream writer.",
"operationId":"_examples/advanced-generic.outputCSVWriter",
"responses":{
"200":{
Expand All @@ -397,7 +399,7 @@
},
"/output-headers":{
"get":{
"summary":"Output With Headers","description":"Output with headers.",
"tags":["Response"],"summary":"Output With Headers","description":"Output with headers.",
"operationId":"_examples/advanced-generic.outputHeaders",
"responses":{
"200":{
Expand All @@ -413,7 +415,7 @@
}
},
"head":{
"summary":"Output With Headers","description":"Output with headers.",
"tags":["Response"],"summary":"Output With Headers","description":"Output with headers.",
"operationId":"_examples/advanced-generic.outputHeaders2",
"responses":{
"200":{
Expand All @@ -431,7 +433,8 @@
},
"/query-object":{
"get":{
"summary":"Request With Object As Query Parameter","operationId":"_examples/advanced-generic.queryObject",
"tags":["Request"],"summary":"Request With Object As Query Parameter",
"operationId":"_examples/advanced-generic.queryObject",
"parameters":[
{
"name":"in_query","in":"query","description":"Object value in query.","style":"deepObject","explode":true,
Expand All @@ -449,7 +452,7 @@
},
"/req-resp-mapping":{
"post":{
"summary":"Request Response Mapping",
"tags":["Request","Response"],"summary":"Request Response Mapping",
"description":"This use case has transport concerns fully decoupled with external req/resp mapping.",
"operationId":"reqRespMapping",
"parameters":[
Expand Down Expand Up @@ -480,7 +483,7 @@
},
"/root-with-session":{
"get":{
"summary":"Dummy","operationId":"_examples/advanced-generic.dummy",
"tags":["Other"],"summary":"Dummy","operationId":"_examples/advanced-generic.dummy",
"responses":{
"204":{"description":"No Content"},
"401":{
Expand All @@ -491,9 +494,48 @@
"security":[{"User":[]}]
}
},
"/text-req-body-ptr/{path}":{
"post":{
"tags":["Request"],"summary":"Request With Text Body (ptr input)",
"description":"This usecase allows direct access to original `*http.Request` while keeping automated decoding of parameters.",
"operationId":"_examples/advanced-generic.textReqBodyPtr",
"parameters":[
{"name":"query","in":"query","schema":{"type":"integer"}},
{"name":"path","in":"path","required":true,"schema":{"type":"string"}}
],
"requestBody":{"content":{"text/csv":{"schema":{"type":"string"}}}},
"responses":{
"200":{
"description":"OK",
"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdvancedOutputType3"}}}
}
},
"x-forbid-unknown-path":true,"x-forbid-unknown-query":true
}
},
"/text-req-body/{path}":{
"post":{
"tags":["Request"],"summary":"Request With Text Body",
"description":"This usecase allows direct access to original `*http.Request` while keeping automated decoding of parameters.",
"operationId":"_examples/advanced-generic.textReqBody",
"parameters":[
{"name":"query","in":"query","schema":{"type":"integer"}},
{"name":"path","in":"path","required":true,"schema":{"type":"string"}}
],
"requestBody":{"content":{"text/csv":{"schema":{"type":"string"}}}},
"responses":{
"200":{
"description":"OK",
"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdvancedOutputType2"}}}
}
},
"x-forbid-unknown-path":true,"x-forbid-unknown-query":true
}
},
"/validation":{
"post":{
"summary":"Validation","description":"Input/Output with validation. Custom annotation.",
"tags":["Request","Response","Validation"],"summary":"Validation",
"description":"Input/Output with validation. Custom annotation.",
"operationId":"_examples/advanced-generic.validation",
"parameters":[
{
Expand Down Expand Up @@ -622,6 +664,8 @@
"type":"object",
"properties":{"inQuery":{"type":"object","additionalProperties":{"type":"number"},"nullable":true}}
},
"AdvancedOutputType2":{"type":"object","properties":{"path":{"type":"string"},"query":{"type":"integer"},"text":{"type":"string"}}},
"AdvancedOutputType3":{"type":"object","properties":{"path":{"type":"string"},"query":{"type":"integer"},"text":{"type":"string"}}},
"AdvancedOutputWithJSON":{
"type":"object",
"properties":{
Expand Down
5 changes: 4 additions & 1 deletion _examples/advanced-generic/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
)

func dummy() usecase.Interactor {
return usecase.NewInteractor(func(ctx context.Context, input struct{}, output *struct{}) error {
u := usecase.NewInteractor(func(ctx context.Context, input struct{}, output *struct{}) error {
return nil
})
u.SetTags("Other")

return u
}
1 change: 1 addition & 0 deletions _examples/advanced-generic/error_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func errorResponse() usecase.Interactor {
u.SetTitle("Declare Expected Errors")
u.SetDescription("This use case demonstrates documentation of expected errors.")
u.SetExpectedErrors(status.InvalidArgument, anotherErr{}, status.FailedPrecondition, status.AlreadyExists)
u.SetTags("Response")

return u
}
Expand Down
1 change: 1 addition & 0 deletions _examples/advanced-generic/file_multi_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func fileMultiUploader() usecase.Interactor {
})

u.SetTitle("Files Uploads With 'multipart/form-data'")
u.SetTags("Request")

return u
}
1 change: 1 addition & 0 deletions _examples/advanced-generic/file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func fileUploader() usecase.Interactor {
})

u.SetTitle("File Upload With 'multipart/form-data'")
u.SetTags("Request")

return u
}
1 change: 1 addition & 0 deletions _examples/advanced-generic/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func form() usecase.Interactor {
u.SetTitle("Request With Form")
u.SetDescription("The `form` field tag acts as `query` and `formData`, with priority on `formData`.\n\n" +
"It is decoded with `http.Request.Form` values.")
u.SetTags("Request")

return u
}
1 change: 1 addition & 0 deletions _examples/advanced-generic/gzip_pass_through.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func directGzip() usecase.Interactor {

return nil
})
u.SetTags("Response")

return u
}
1 change: 1 addition & 0 deletions _examples/advanced-generic/html_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func htmlResponse() usecase.Interactor {

u.SetTitle("Request With HTML Response")
u.SetDescription("Request with templated HTML response.")
u.SetTags("Response")

return u
}
Loading

0 comments on commit 9e8e48a

Please sign in to comment.