-
Notifications
You must be signed in to change notification settings - Fork 420
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
Add OpenAPI generation and swagger to update-codegen.sh #1297
Merged
+4,714
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,EventListenerConfig,GeneratedResourceName | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,InterceptorRequest,InterceptorParams | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,KubernetesResource,WithPodSpec | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,StatusError,s | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerContext,EventID | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerContext,EventURL | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerContext,TriggerID | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerSpecBinding,APIVersion | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerSpecTemplate,APIVersion | ||
API rule violation: names_match,github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,TriggerTemplateSpec,ResourceTemplates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2020 The Tekton Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
|
||
"k8s.io/klog" | ||
"k8s.io/kube-openapi/pkg/common" | ||
spec "k8s.io/kube-openapi/pkg/validation/spec" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) <= 1 { | ||
klog.Fatal("Supply a version") | ||
} | ||
version := os.Args[1] | ||
if !strings.HasPrefix(version, "v") { | ||
version = "v" + version | ||
} | ||
oAPIDefs := tekton.GetOpenAPIDefinitions(func(name string) spec.Ref { | ||
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name))) | ||
}) | ||
defs := spec.Definitions{} | ||
for defName, val := range oAPIDefs { | ||
defs[swaggify(defName)] = val.Schema | ||
} | ||
swagger := spec.Swagger{ | ||
SwaggerProps: spec.SwaggerProps{ | ||
Swagger: "2.0", | ||
Definitions: defs, | ||
Paths: &spec.Paths{Paths: map[string]spec.PathItem{}}, | ||
Info: &spec.Info{ | ||
InfoProps: spec.InfoProps{ | ||
Title: "Tekton", | ||
Description: "Tekton Pipeline", | ||
Version: version, | ||
}, | ||
}, | ||
}, | ||
} | ||
jsonBytes, err := json.MarshalIndent(swagger, "", " ") | ||
if err != nil { | ||
klog.Fatal(err.Error()) | ||
} | ||
fmt.Println(string(jsonBytes)) | ||
} | ||
|
||
func swaggify(name string) string { | ||
name = strings.ReplaceAll(name, "./pkg/apis/pipeline/", "") | ||
name = strings.ReplaceAll(name, "./pkg/apis/resource/", "") | ||
name = strings.ReplaceAll(name, "github.com/tektoncd/pipeline/pkg/apis/pipeline/", "") | ||
name = strings.ReplaceAll(name, "github.com/tektoncd/pipeline/pkg/apis/resource/", "") | ||
name = strings.ReplaceAll(name, "k8s.io/api/core/", "") | ||
name = strings.ReplaceAll(name, "k8s.io/apimachinery/pkg/apis/meta/", "") | ||
name = strings.ReplaceAll(name, "knative.dev/pkg/apis.", "knative/") | ||
name = strings.ReplaceAll(name, "knative.dev/pkg/apis/duck/v1beta1.", "knative/") | ||
name = strings.ReplaceAll(name, "/", ".") | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 The Tekton Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scripts/library.sh | ||
|
||
cd "${REPO_ROOT_DIR}" | ||
|
||
readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)" | ||
|
||
cleanup() { | ||
rm -rf "${TMP_DIFFROOT}" | ||
} | ||
|
||
cleanup | ||
|
||
mkdir -p "${TMP_DIFFROOT}" | ||
|
||
trap cleanup EXIT | ||
|
||
echo "Generating OpenAPI specification ..." | ||
go run k8s.io/kube-openapi/cmd/openapi-gen \ | ||
--input-dirs github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1,knative.dev/pkg/apis,knative.dev/pkg/apis/duck/v1beta1 \ | ||
--output-package ./pkg/apis/triggers/v1beta1 -o ./ \ | ||
--go-header-file hack/boilerplate/boilerplate.go.txt \ | ||
-r "${TMP_DIFFROOT}/api-report" | ||
|
||
violations=$(diff --changed-group-format='%>' --unchanged-group-format='' "hack/ignored-openapi-violations.list" "${TMP_DIFFROOT}/api-report" || echo "") | ||
if [ -n "${violations}" ]; then | ||
echo "" | ||
echo "New API rule violations found which are not present in hack/ignored-openapi-violations.list. Please fix these violations:" | ||
echo "" | ||
echo "${violations}" | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
echo "Generating swagger file ..." | ||
go run hack/spec-gen/main.go v0.17.2 > pkg/apis/triggers/v1beta1/swagger.json |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Why do we need to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I literally just copied this over from Pipelines - I assume it does something relating to
swagger.json
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok. was curious as to why we need to have this custom function.