Compare commits
9 Commits
v3.8.2
...
e4433a0257
Author | SHA1 | Date | |
---|---|---|---|
e4433a0257 | |||
4f94497f82 | |||
3e1a0a83cf | |||
|
91c4cba229 | ||
|
76e6924d40 | ||
2da3760acb | |||
6e47e59542 | |||
fc716500c4 | |||
|
8d8d570880 |
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v2
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@@ -3,6 +3,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
@@ -13,7 +14,7 @@ jobs:
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
@@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.1.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
23
.github/workflows/codeql-analysis.yml
vendored
23
.github/workflows/codeql-analysis.yml
vendored
@@ -9,7 +9,7 @@
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
@@ -17,16 +17,16 @@ on:
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
@@ -42,11 +42,14 @@ jobs:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
@@ -57,7 +60,7 @@ jobs:
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
@@ -71,5 +74,5 @@ jobs:
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
73
.github/workflows/dependabot-automerge.yml
vendored
73
.github/workflows/dependabot-automerge.yml
vendored
@@ -1,66 +1,27 @@
|
||||
name: "prautomerge"
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
Dependabot-Automerge:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR
|
||||
# The the github.event.workflow_run.event value is 'push' and not 'pull_request'
|
||||
# dont work with multiple workflows when last returns success
|
||||
if: >-
|
||||
github.event.workflow_run.conclusion == 'success'
|
||||
&& github.actor == 'dependabot[bot]'
|
||||
&& github.event.sender.login == 'dependabot[bot]'
|
||||
&& github.event.sender.type == 'Bot'
|
||||
&& (github.event.workflow_run.event == 'pull_request'
|
||||
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
||||
uses: actions/github-script@v6
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.0
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
console.log(context.payload.workflow_run);
|
||||
|
||||
var labelNames = await github.paginate(
|
||||
github.issues.listLabelsOnIssue,
|
||||
{
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
issue_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
},
|
||||
(response) => response.data.map(
|
||||
(label) => label.name
|
||||
)
|
||||
);
|
||||
|
||||
console.log(labelNames);
|
||||
|
||||
if (labelNames.includes('dependencies')) {
|
||||
console.log('Found label');
|
||||
|
||||
await github.pulls.createReview({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
event: 'APPROVE'
|
||||
});
|
||||
console.log('Approved PR');
|
||||
|
||||
await github.pulls.merge({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
});
|
||||
|
||||
console.log('Merged PR');
|
||||
}
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
|
7
.github/workflows/pr.yml
vendored
7
.github/workflows/pr.yml
vendored
@@ -3,6 +3,7 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
@@ -13,7 +14,7 @@ jobs:
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
@@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.1.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.16
|
||||
|
||||
require (
|
||||
github.com/fatih/structtag v1.2.0
|
||||
go.unistack.org/micro-proto/v3 v3.2.3
|
||||
go.unistack.org/micro-proto/v3 v3.2.7
|
||||
golang.org/x/tools v0.1.9
|
||||
google.golang.org/protobuf v1.27.1
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@@ -68,8 +68,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.unistack.org/micro-proto/v3 v3.2.3 h1:vSRI6VoZrlv0pUdo69irHv6HbbnD+oZOGEUE/TS5XBQ=
|
||||
go.unistack.org/micro-proto/v3 v3.2.3/go.mod h1:ZltVWNECD5yK+40+OCONzGw4OtmSdTpVi8/KFgo9dqM=
|
||||
go.unistack.org/micro-proto/v3 v3.2.7 h1:zG6d69kHc+oij2lwQ3AfrCgdjiEVRG2A7TlsxjusWs4=
|
||||
go.unistack.org/micro-proto/v3 v3.2.7/go.mod h1:ZltVWNECD5yK+40+OCONzGw4OtmSdTpVi8/KFgo9dqM=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
|
100
openapiv3.go
100
openapiv3.go
@@ -22,13 +22,14 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.unistack.org/micro-proto/v3/api"
|
||||
// v2 "go.unistack.org/micro-proto/v3/openapiv2"
|
||||
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -47,6 +48,19 @@ type openapiv3Generator struct {
|
||||
namedPathPattern *regexp.Regexp
|
||||
}
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
protofiles = &protoregistry.Files{}
|
||||
)
|
||||
|
||||
func protofilesAdd(plugin *protogen.Plugin) {
|
||||
for path, f := range plugin.FilesByPath {
|
||||
if _, err := protofiles.FindFileByPath(path); err != nil {
|
||||
protofiles.RegisterFile(f.Desc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// openapiv3Generate creates a new generator for a protoc plugin invocation.
|
||||
func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin) error {
|
||||
og := &openapiv3Generator{
|
||||
@@ -61,6 +75,8 @@ func (g *Generator) openapiv3Generate(component string, plugin *protogen.Plugin)
|
||||
namedPathPattern: regexp.MustCompile("{(.+)=(.+)}"),
|
||||
}
|
||||
|
||||
protofilesAdd(plugin)
|
||||
|
||||
d := og.buildDocumentV3(plugin)
|
||||
bytes, err := d.YAMLValue("Generated with protoc-gen-go-micro\n")
|
||||
if err != nil {
|
||||
@@ -245,14 +261,6 @@ func (g *openapiv3Generator) addPathsToDocumentV3(d *v3.Document, file *protogen
|
||||
outputMessage := method.Output
|
||||
operationID := service.GoName + "_" + method.GoName
|
||||
|
||||
/*
|
||||
e2opt := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
||||
if e2opt != nil && e2opt != v2.E_Openapiv2Operation.InterfaceOf(v2.E_Openapiv2Operation.Zero()) {
|
||||
if opt, ok := e2opt.(*v2.Operation); ok && opt.OperationId != "" {
|
||||
operationID = opt.OperationId
|
||||
}
|
||||
}
|
||||
*/
|
||||
e3opt := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
||||
if e3opt != nil && e3opt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||
if opt, ok := e3opt.(*v3.Operation); ok && opt.OperationId != "" {
|
||||
@@ -640,22 +648,71 @@ func (g *openapiv3Generator) buildOperationV3(
|
||||
}
|
||||
}
|
||||
|
||||
// Create the response.
|
||||
responses := &v3.Responses{
|
||||
ResponseOrReference: []*v3.NamedResponseOrReference{
|
||||
{
|
||||
Name: "200",
|
||||
Value: &v3.ResponseOrReference{
|
||||
Oneof: &v3.ResponseOrReference_Response{
|
||||
Response: &v3.Response{
|
||||
Description: "OK",
|
||||
Content: g.responseContentForMessage(outputMessage),
|
||||
},
|
||||
var responses *v3.Responses
|
||||
if eopt != nil && eopt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||
opt := eopt.(*v3.Operation)
|
||||
if r := opt.Responses; r != nil {
|
||||
responses = r
|
||||
}
|
||||
|
||||
if ref := responses.Default.GetReference(); ref != nil && ref.GetXRef() != "" {
|
||||
xref := strings.TrimPrefix(ref.GetXRef(), ".")
|
||||
description := "Default"
|
||||
if strings.Contains(xref, "micro.errors.Error") {
|
||||
description += " Error"
|
||||
}
|
||||
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
|
||||
if err != nil {
|
||||
log.Printf("unknown ref type %s err %v", xref, err)
|
||||
} else {
|
||||
responses.Default.Oneof = &v3.ResponseOrReference_Response{
|
||||
Response: &v3.Response{
|
||||
Description: description,
|
||||
Content: g.responseContentForMessage(&protogen.Message{
|
||||
Desc: desc.(protoreflect.MessageDescriptor),
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, rref := range responses.GetResponseOrReference() {
|
||||
if ref := rref.Value.GetReference(); ref != nil && ref.GetXRef() != "" {
|
||||
xref := strings.TrimPrefix(ref.GetXRef(), ".")
|
||||
description := "Default"
|
||||
if strings.Contains(xref, "micro.errors.Error") {
|
||||
description += " Error"
|
||||
}
|
||||
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
|
||||
if err != nil {
|
||||
log.Printf("unknown ref type %s err %v", xref, err)
|
||||
} else {
|
||||
responses.Default.Oneof = &v3.ResponseOrReference_Response{
|
||||
Response: &v3.Response{
|
||||
Description: description,
|
||||
Content: g.responseContentForMessage(&protogen.Message{
|
||||
Desc: desc.(protoreflect.MessageDescriptor),
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
responses = &v3.Responses{}
|
||||
}
|
||||
|
||||
// Create the response.
|
||||
responses.ResponseOrReference = append(responses.ResponseOrReference, &v3.NamedResponseOrReference{
|
||||
Name: "200",
|
||||
Value: &v3.ResponseOrReference{
|
||||
Oneof: &v3.ResponseOrReference_Response{
|
||||
Response: &v3.Response{
|
||||
Description: "OK",
|
||||
Content: g.responseContentForMessage(outputMessage),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// Create the operation.
|
||||
op := &v3.Operation{
|
||||
@@ -682,7 +739,6 @@ func (g *openapiv3Generator) buildOperationV3(
|
||||
// Pass the entire request message as the request body.
|
||||
typeName := g.fullMessageTypeName(inputMessage.Desc)
|
||||
requestSchema = g.schemaOrReferenceForType(typeName)
|
||||
|
||||
} else {
|
||||
// If body refers to a message field, use that type.
|
||||
for _, field := range inputMessage.Fields {
|
||||
|
@@ -16,8 +16,8 @@ var (
|
||||
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v3/server")
|
||||
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v3")
|
||||
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v3")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro/v3/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v3/errors")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v3/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v3/errors")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v3.5.3"
|
||||
|
Reference in New Issue
Block a user