Skip to content

Commit 572ae4f

Browse files
authored
fix: omit status field when empty (#2654)
This PR omits that `status` field when it is empty. The `status` field is always empty in `generate-request.json`, so this change ensures that `generate-request.json` no longer contains the `status` field. This aligns with what we have in the docs: https://github.com/googleapis/librarian/blob/main/doc/language-onboarding.md We only need the `status` field in `configure-request.json`, and the value is expected to be either `new` or `existing` as per the above docs.
1 parent 1179829 commit 572ae4f

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

internal/config/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ type API struct {
245245
ServiceConfig string `yaml:"service_config" json:"service_config"`
246246
// The status of the API, one of "new" or "existing".
247247
// This field is ignored when writing to state.yaml.
248-
Status string `yaml:"-" json:"status"`
248+
Status string `yaml:"-" json:"status,omitempty"`
249249
}
250250

251251
// Validate checks that the API is valid.

internal/docker/docker_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,36 @@ func TestWriteLibraryState(t *testing.T) {
715715
filename: "a-library-example.json",
716716
wantFile: "successful-marshaling-and-writing.json",
717717
},
718+
{
719+
name: "omit empty status",
720+
state: &config.LibrarianState{
721+
Image: "v1.0.0",
722+
Libraries: []*config.LibraryState{
723+
{
724+
ID: "google-cloud-go",
725+
Version: "1.0.0",
726+
APIs: []*config.API{
727+
{
728+
Path: "google/cloud/compute/v1",
729+
ServiceConfig: "example_service_config.yaml",
730+
},
731+
},
732+
SourceRoots: []string{
733+
"src/example/path",
734+
},
735+
PreserveRegex: []string{
736+
"example-preserve-regex",
737+
},
738+
RemoveRegex: []string{
739+
"example-remove-regex",
740+
},
741+
},
742+
},
743+
},
744+
path: os.TempDir(),
745+
filename: "omit-empty-status.json",
746+
wantFile: "omit-empty-status.json",
747+
},
718748
{
719749
name: "empty library state",
720750
state: &config.LibrarianState{},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"id": "google-cloud-go",
3+
"version": "1.0.0",
4+
"apis": [
5+
{
6+
"path": "google/cloud/compute/v1",
7+
"service_config": "example_service_config.yaml"
8+
}
9+
],
10+
"source_roots": [
11+
"src/example/path"
12+
],
13+
"preserve_regex": [
14+
"example-preserve-regex"
15+
],
16+
"remove_regex": [
17+
"example-remove-regex"
18+
]
19+
}

0 commit comments

Comments
 (0)