Skip to content

Commit 78852ba

Browse files
denikclaude
andauthored
direct: Add support for apitypes.yml to override apitypes.generated.yml (#4433)
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent 28ed3c6 commit 78852ba

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ generate-direct-clean:
183183
bundle/direct/dresources/apitypes.generated.yml: ./bundle/direct/tools/generate_apitypes.py .codegen/openapi.json acceptance/bundle/refschema/out.fields.txt
184184
python3 $^ > $@
185185

186-
bundle/direct/dresources/resources.generated.yml: ./bundle/direct/tools/generate_resources.py .codegen/openapi.json bundle/direct/dresources/apitypes.generated.yml acceptance/bundle/refschema/out.fields.txt
186+
bundle/direct/dresources/resources.generated.yml: ./bundle/direct/tools/generate_resources.py .codegen/openapi.json bundle/direct/dresources/apitypes.generated.yml bundle/direct/dresources/apitypes.yml acceptance/bundle/refschema/out.fields.txt
187187
python3 $^ > $@
188188

189189
.PHONY: lint lintfull tidy lintcheck fmt fmtfull test test-unit test-acc test-slow test-slow-unit test-slow-acc cover showcover build snapshot snapshot-release schema integration integration-short acc-cover acc-showcover docs ws wsfix links checks test-update test-update-templates generate-out-test-toml test-update-aws test-update-all generate-validation
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Override apitypes.generated.yml here.
2+
# This file is not auto-generated and can be manually edited.
3+
#
4+
# Set a value to null to remove a type:
5+
# jobs: null

bundle/direct/tools/generate_resources.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
import yaml
1313

1414

15-
def parse_apitypes(path):
16-
"""Parse apitypes.generated.yml to get resource types."""
17-
data = yaml.safe_load(path.read_text())
18-
return {resource: type_name for resource, type_name in data.items() if type_name}
15+
def parse_apitypes(generated_path, override_path):
16+
"""Parse apitypes.generated.yml and override with apitypes.yml."""
17+
result = yaml.safe_load(generated_path.read_text()) or {}
18+
19+
# Override with non-generated apitypes.yml (null values remove entries)
20+
override_data = yaml.safe_load(override_path.read_text()) or {}
21+
for resource, type_name in override_data.items():
22+
if type_name:
23+
result[resource] = type_name
24+
else:
25+
result.pop(resource, None)
26+
27+
return result
1928

2029

2130
def parse_out_fields(path):
@@ -139,11 +148,11 @@ def main():
139148
parser = argparse.ArgumentParser(description="Generate resources YAML from OpenAPI schema")
140149
parser.add_argument("apischema", type=Path, help="Path to OpenAPI schema JSON file")
141150
parser.add_argument("apitypes", type=Path, help="Path to apitypes.generated.yml file")
142-
# TODO: add non-generated apitypes.yml here once the need to override generated ones arises
151+
parser.add_argument("apitypes_override", type=Path, help="Path to apitypes.yml override file")
143152
parser.add_argument("out_fields", type=Path, help="Path to out.fields.txt file")
144153
args = parser.parse_args()
145154

146-
resource_types = parse_apitypes(args.apitypes)
155+
resource_types = parse_apitypes(args.apitypes, args.apitypes_override)
147156
state_fields = parse_out_fields(args.out_fields)
148157
schemas = json.loads(args.apischema.read_text()).get("components", {}).get("schemas", {})
149158

yamlfmt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ exclude:
22
- libs/dyn/yamlloader/testdata
33
- acceptance/selftest/bundleconfig # https://github.com/google/yamlfmt/issues/254
44
- acceptance/bundle/artifacts/nil_artifacts/databricks.yml # https://github.com/google/yamlfmt/issues/253
5+
- bundle/direct/dresources/apitypes.yml # remove comments
56
formatter:
67
type: basic
78
retain_line_breaks_single: true

0 commit comments

Comments
 (0)