Skip to content

Commit ed12880

Browse files
authored
Ensured that property names are lowercase in kptfile schema (#2520)
1 parent 892bed3 commit ed12880

File tree

8 files changed

+350
-185
lines changed

8 files changed

+350
-185
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ fix:
4343

4444
fmt:
4545
go fmt ./...
46+
47+
schema:
48+
GOBIN=$(GOBIN) scripts/generate-schema.sh
4649

4750
generate:
4851
go install ./mdtogo
49-
(which swagger || go install github.com/go-swagger/go-swagger/cmd/[email protected])
5052
rm -rf internal/docs/generated
5153
mkdir internal/docs/generated
5254
GOBIN=$(GOBIN) go generate ./...

internal/docs/generated/fndocs/docs.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//go:generate $GOBIN/mdtogo site/reference/cli/pkg internal/docs/generated/pkgdocs --license=none --recursive=true --strategy=cmdDocs
1717
//go:generate $GOBIN/mdtogo site/reference/cli/fn internal/docs/generated/fndocs --license=none --recursive=true --strategy=cmdDocs
1818
//go:generate $GOBIN/mdtogo site/reference/cli/README.md internal/docs/generated/overview --license=none --strategy=cmdDocs
19-
//go:generate $GOBIN/swagger generate spec -m -w pkg/api/kptfile/v1 -o site/reference/schema/kptfile/kptfile.yaml
2019
package main
2120

2221
import (

pkg/api/kptfile/v1/types.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ var TypeMeta = yaml.ResourceMeta{
4444
type KptFile struct {
4545
yaml.ResourceMeta `yaml:",inline"`
4646

47-
Upstream *Upstream `yaml:"upstream,omitempty"`
47+
Upstream *Upstream `yaml:"upstream,omitempty" json:"upstream,omitempty"`
4848

4949
// UpstreamLock is a resolved locator for the last fetch of the package.
50-
UpstreamLock *UpstreamLock `yaml:"upstreamLock,omitempty"`
50+
UpstreamLock *UpstreamLock `yaml:"upstreamLock,omitempty" json:"upstreamLock,omitempty"`
5151

5252
// Info contains metadata such as license, documentation, etc.
53-
Info *PackageInfo `yaml:"info,omitempty"`
53+
Info *PackageInfo `yaml:"info,omitempty" json:"info,omitempty"`
5454

5555
// Pipeline declares the pipeline of functions.
56-
Pipeline *Pipeline `yaml:"pipeline,omitempty"`
56+
Pipeline *Pipeline `yaml:"pipeline,omitempty" json:"pipeline,omitempty"`
5757

5858
// Inventory contains parameters for the inventory object used in apply.
59-
Inventory *Inventory `yaml:"inventory,omitempty"`
59+
Inventory *Inventory `yaml:"inventory,omitempty" json:"inventory,omitempty"`
6060
}
6161

6262
// OriginType defines the type of origin for a package.
@@ -116,55 +116,55 @@ func UpdateStrategiesAsStrings() []string {
116116
// Upstream is a user-specified upstream locator for a package.
117117
type Upstream struct {
118118
// Type is the type of origin.
119-
Type OriginType `yaml:"type,omitempty"`
119+
Type OriginType `yaml:"type,omitempty" json:"type,omitempty"`
120120

121121
// Git is the locator for a package stored on Git.
122-
Git *Git `yaml:"git,omitempty"`
122+
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
123123

124124
// UpdateStrategy declares how a package will be updated from upstream.
125-
UpdateStrategy UpdateStrategyType `yaml:"updateStrategy,omitempty"`
125+
UpdateStrategy UpdateStrategyType `yaml:"updateStrategy,omitempty" json:"updateStrategy,omitempty"`
126126
}
127127

128128
// Git is the user-specified locator for a package on Git.
129129
type Git struct {
130130
// Repo is the git repository the package.
131131
// e.g. 'https://github.com/kubernetes/examples.git'
132-
Repo string `yaml:"repo,omitempty"`
132+
Repo string `yaml:"repo,omitempty" json:"repo,omitempty"`
133133

134134
// Directory is the sub directory of the git repository.
135135
// e.g. 'staging/cockroachdb'
136-
Directory string `yaml:"directory,omitempty"`
136+
Directory string `yaml:"directory,omitempty" json:"directory,omitempty"`
137137

138138
// Ref can be a Git branch, tag, or a commit SHA-1.
139-
Ref string `yaml:"ref,omitempty"`
139+
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
140140
}
141141

142142
// UpstreamLock is a resolved locator for the last fetch of the package.
143143
type UpstreamLock struct {
144144
// Type is the type of origin.
145-
Type OriginType `yaml:"type,omitempty"`
145+
Type OriginType `yaml:"type,omitempty" json:"type,omitempty"`
146146

147147
// Git is the resolved locator for a package on Git.
148-
Git *GitLock `yaml:"git,omitempty"`
148+
Git *GitLock `yaml:"git,omitempty" json:"git,omitempty"`
149149
}
150150

151151
// GitLock is the resolved locator for a package on Git.
152152
type GitLock struct {
153153
// Repo is the git repository that was fetched.
154154
// e.g. 'https://github.com/kubernetes/examples.git'
155-
Repo string `yaml:"repo,omitempty"`
155+
Repo string `yaml:"repo,omitempty" json:"repo,omitempty"`
156156

157157
// Directory is the sub directory of the git repository that was fetched.
158158
// e.g. 'staging/cockroachdb'
159-
Directory string `yaml:"directory,omitempty"`
159+
Directory string `yaml:"directory,omitempty" json:"directory,omitempty"`
160160

161161
// Ref can be a Git branch, tag, or a commit SHA-1 that was fetched.
162162
// e.g. 'master'
163-
Ref string `yaml:"ref,omitempty"`
163+
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
164164

165165
// Commit is the SHA-1 for the last fetch of the package.
166166
// This is set by kpt for bookkeeping purposes.
167-
Commit string `yaml:"commit,omitempty"`
167+
Commit string `yaml:"commit,omitempty" json:"commit,omitempty"`
168168
}
169169

170170
// PackageInfo contains optional information about the package such as license, documentation, etc.
@@ -173,37 +173,37 @@ type GitLock struct {
173173
// `metadata.annotations` as the extension mechanism.
174174
type PackageInfo struct {
175175
// Site is the URL for package web page.
176-
Site string `yaml:"site,omitempty"`
176+
Site string `yaml:"site,omitempty" json:"site,omitempty"`
177177

178178
// Email is the list of emails for the package authors.
179-
Emails []string `yaml:"emails,omitempty"`
179+
Emails []string `yaml:"emails,omitempty" json:"emails,omitempty"`
180180

181181
// SPDX license identifier (e.g. "Apache-2.0"). See: https://spdx.org/licenses/
182-
License string `yaml:"license,omitempty"`
182+
License string `yaml:"license,omitempty" json:"license,omitempty"`
183183

184184
// Relative slash-delimited path to the license file (e.g. LICENSE.txt)
185-
LicenseFile string `yaml:"licenseFile,omitempty"`
185+
LicenseFile string `yaml:"licenseFile,omitempty" json:"licenseFile,omitempty"`
186186

187187
// Description contains a short description of the package.
188-
Description string `yaml:"description,omitempty"`
188+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
189189

190190
// Keywords is a list of keywords for this package.
191-
Keywords []string `yaml:"keywords,omitempty"`
191+
Keywords []string `yaml:"keywords,omitempty" json:"keywords,omitempty"`
192192

193193
// Man is the path to documentation about the package
194-
Man string `yaml:"man,omitempty"`
194+
Man string `yaml:"man,omitempty" json:"man,omitempty"`
195195
}
196196

197197
// Subpackages declares a local or remote subpackage.
198198
type Subpackage struct {
199199
// Name of the immediate subdirectory relative to this Kptfile where the suppackage
200200
// either exists (local subpackages) or will be fetched to (remote subpckages).
201201
// This must be unique across all subpckages of a package.
202-
LocalDir string `yaml:"localDir,omitempty"`
202+
LocalDir string `yaml:"localDir,omitempty" json:"localDir,omitempty"`
203203

204204
// Upstream is a reference to where the subpackage should be fetched from.
205205
// Whether a subpackage is local or remote is determined by whether Upstream is specified.
206-
Upstream *Upstream `yaml:"upstream,omitempty"`
206+
Upstream *Upstream `yaml:"upstream,omitempty" json:"upstream,omitempty"`
207207
}
208208

209209
// Pipeline declares a pipeline of functions used to mutate or validate resources.
@@ -228,11 +228,11 @@ type Pipeline struct {
228228
// Order of operation: mutators, validators
229229

230230
// Mutators defines a list of of KRM functions that mutate resources.
231-
Mutators []Function `yaml:"mutators,omitempty"`
231+
Mutators []Function `yaml:"mutators,omitempty" json:"mutators,omitempty"`
232232

233233
// Validators defines a list of KRM functions that validate resources.
234234
// Validators are not permitted to mutate resources.
235-
Validators []Function `yaml:"validators,omitempty"`
235+
Validators []Function `yaml:"validators,omitempty" json:"validators,omitempty"`
236236
}
237237

238238
// String returns the string representation of Pipeline struct
@@ -266,33 +266,33 @@ type Function struct {
266266
// e.g. The following resolves to gcr.io/kpt-fn/set-labels:
267267
//
268268
// image: set-labels
269-
Image string `yaml:"image,omitempty"`
269+
Image string `yaml:"image,omitempty" json:"image,omitempty"`
270270

271271
// `ConfigPath` specifies a slash-delimited relative path to a file in the current directory
272272
// containing a KRM resource used as the function config. This resource is
273273
// excluded when resolving 'sources', and as a result cannot be operated on
274274
// by the pipeline.
275-
ConfigPath string `yaml:"configPath,omitempty"`
275+
ConfigPath string `yaml:"configPath,omitempty" json:"configPath,omitempty"`
276276

277277
// `ConfigMap` is a convenient way to specify a function config of kind ConfigMap.
278-
ConfigMap map[string]string `yaml:"configMap,omitempty"`
278+
ConfigMap map[string]string `yaml:"configMap,omitempty" json:"configMap,omitempty"`
279279

280280
// `Selectors` are used to specify resources on which the function should be executed
281281
// if not specified, all resources are selected
282-
Selectors []Selector `yaml:"selectors,omitempty"`
282+
Selectors []Selector `yaml:"selectors,omitempty" json:"selectors,omitempty"`
283283
}
284284

285285
// Selector specifies the selection criteria
286286
// please update IsEmpty method if more properties are added
287287
type Selector struct {
288288
// APIVersion of the target resources
289-
APIVersion string `yaml:"apiVersion,omitempty"`
289+
APIVersion string `yaml:"apiVersion,omitempty" json:"apiVersion,omitempty"`
290290
// Kind of the target resources
291-
Kind string `yaml:"kind,omitempty"`
291+
Kind string `yaml:"kind,omitempty" json:"kind,omitempty"`
292292
// Name of the target resources
293-
Name string `yaml:"name,omitempty"`
293+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
294294
// Namespace of the target resources
295-
Namespace string `yaml:"namespace,omitempty"`
295+
Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
296296
}
297297

298298
// IsEmpty returns true of none of the selection criteria is specified
@@ -307,11 +307,11 @@ func (s Selector) IsEmpty() bool {
307307
// All of the the parameters are required if any are set.
308308
type Inventory struct {
309309
// Namespace for the inventory resource.
310-
Namespace string `yaml:"namespace,omitempty"`
310+
Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
311311
// Name of the inventory resource.
312-
Name string `yaml:"name,omitempty"`
312+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
313313
// Unique label to identify inventory resource in cluster.
314-
InventoryID string `yaml:"inventoryID,omitempty"`
315-
Labels map[string]string `yaml:"labels,omitempty"`
316-
Annotations map[string]string `yaml:"annotations,omitempty"`
314+
InventoryID string `yaml:"inventoryID,omitempty" json:"inventoryID,omitempty"`
315+
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
316+
Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
317317
}

scripts/generate-schema.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
if ! command -v jq >/dev/null; then
18+
echo "jq must be installed. Follow https://stedolan.github.io/jq/download/ to install jq."
19+
exit 1
20+
fi
21+
which swagger || go install github.com/go-swagger/go-swagger/cmd/[email protected]
22+
$GOBIN/swagger generate spec -m -w pkg/api/kptfile/v1 -o site/reference/schema/kptfile/kptfile.yaml
23+
$GOBIN/swagger generate spec -m -w pkg/api/kptfile/v1 -o site/reference/schema/kptfile/kptfile.json
24+
# We need to add schema header for schema to work in cloud-code.
25+
# See https://github.com/GoogleContainerTools/kpt/pull/2520/files/aac23473c121252ec6341fdb2bcce389ae6cb122#r717867089
26+
jq -s '.[0] * .[1]' scripts/schema-header.json site/reference/schema/kptfile/kptfile.json > /tmp/kptfile-schema.json
27+
mv /tmp/kptfile-schema.json site/reference/schema/kptfile/kptfile.json

scripts/schema-header.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "http://json-schema.org/draft/2019-09/schema#",
3+
"type": "object",
4+
"anyOf": ["#/definitions/kptfile"]
5+
}

0 commit comments

Comments
 (0)