-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenAPI generation and swagger to update-codegen.sh
And fix #1271 along the way by using the same scripting as in tektoncd/pipeline#4402 to ignore API rule violations for `name_match` which already exist. Any new mismatch will cause an error. Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
- Loading branch information
1 parent
91a821e
commit c8ca0ed
Showing
8 changed files
with
4,714 additions
and
0 deletions.
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.