[TFgen] Implement tracking-field decoder + duplicate artifact name detection#3853
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ede0af4 to
e6a7a1c
Compare
301490f to
5eb0064
Compare
e6a7a1c to
085ec78
Compare
5eb0064 to
bf3cc22
Compare
085ec78 to
bb3aa38
Compare
This comment has been minimized.
This comment has been minimized.
bb3aa38 to
87082c5
Compare
bf3cc22 to
10f43de
Compare
87082c5 to
5c7c167
Compare
|
Need to add coverage to ignore collisions when both the resource and datasource have the same artifact name. Right now the |
| "minLength": 1, | ||
| "maxLength": 64, | ||
| "description": "Terraform-facing artifact name without the 'datadog_' prefix. Must be lowercase snake_case. Must be unique across the entire spec." | ||
| "description": "Terraform-facing artifact name without the 'datadog_' prefix. Must be lowercase snake_case. Must be unique per artifact_kind — resources and data sources are separate Terraform namespaces, so a resource and a data source may share a name." |
There was a problem hiding this comment.
@Supam is this a valid statement? Should the OAS extension contract be updated?
cd57259 to
b98b820
Compare
5a70fec to
121dbbd
Compare
|
There technically is already some differentiation for both datasources and resources, it is just not obvious at the OAS level. In the OAS we will be asking for the artefact name, this name will be used in both datasources and resources. |
121dbbd to
c4630e5
Compare

Changes
Decodes the
x-datadog-tf-generatorvendor extension into typed metadata onmodel.Operation.TrackingduringLoadSpec, and enforces global uniqueness of the resultingartifact_name. Both run inside a singleLoadSpeccall, which now returns a fully-populated*model.Specor an actionable error.parser.DecodeTracking(op, path, method, extensionName) (*model.TrackingFieldMetadata, error)— parses the extension into a typed*model.TrackingFieldMetadata(artifact_kind,artifact_name,group,id_strategy,sensitive,skip) for downstream codegen,applying the
id_strategydefault (data.id). Before populating the struct it validates theraw value at runtime against the committed JSON Schema
(
internal/contracts/tracking-field.schema.json, embedded via a newcontractspackage), socallers only ever get well-formed metadata back. Returns
(nil, nil)when the operation isout of scope (no extension, or
skip: true), and a typed*TrackingErrornaming the OpenAPIlocation (method + path + operationId) when the extension is malformed (unknown
artifact_kind, missing required field, unknown property, bad name pattern, …).parser.CheckDuplicateArtifactNames(spec)— walks everyOperation.Trackingand failswith a single aggregated
*DuplicateArtifactNameErrorlisting eachartifact_namecollisionand all of its source locations, sorted by name then (path, method) for deterministic
output.
metadata on
Operation.Tracking, fail-fast on a malformed extension); the duplicate checkruns after the deterministic sort.
--tracking-fieldseam — adds aWithTrackingFieldNameLoadSpecoption and threadsflags.trackingFieldthrough thegeneratecommand, mirroring the existing--max-depthwiring.
github.com/santhosh-tekuri/jsonschema/v6(a JSON-Schema validator,not a second OAS parser).
Test Plan
New coverage — decode (asserts the returned metadata): valid resource / valid data source
(kind, name, group, id_strategy populated), absent extension,
skip:true, missing requiredfields, unknown
artifact_kind, unknown property (additionalProperties:false), badartifact_namepattern, appliedid_strategydefault, error-carries-OpenAPI-path, customextension name. Duplicates: none / single collision / all-sources-listed /
multiple-collisions-sorted / ignores-untracked / deterministic-across-input-order. LoadSpec
wiring fixtures: tracking populated (resource + data source + unflagged op), duplicate →
typed error naming both ops, malformed → typed error carrying the real OpenAPI path.
Follow-ups / action items
Remove the parser-side default extension name once the global CLI flags are wired into
the cobra root (APIR-2923).
DefaultTrackingFieldNameand the empty-name fallback are atemporary stopgap so
LoadSpecis usable standalone — the real default(
x-datadog-tf-generator) already lives on the--tracking-fieldflag inroot.go. Once thewiring guarantees the name is always supplied, delete:
DefaultTrackingFieldNameconst —internal/parser/tracking.goif name != ""fallback inWithTrackingFieldNameand thetrackingFieldName: DefaultTrackingFieldNameseed inLoadSpec—internal/parser/parser.go…so the extension name has a single source of truth (the CLI flag), instead of a default
defined in two places.
Update OAS extension contract