Skip to content

Commit a7e9ebd

Browse files
authored
Remove output-only fields from JSON schema (#3878)
## Changes Instead of marking output-only fields with `doNotSuggest` (see #3599), completely exclude them from the schema. This is done by: - Marking fields as `OUTPUT_ONLY` in `FieldBehaviors` during annotation - Adding removeOutputOnlyFields transformation to remove these fields - Also removing them from required lists This removes 77 output-only properties from the schema. ## Why Output-only field must not show up in the generated code for Python support. ## Tests A few fields were removed from the Python code.
1 parent 1f8ca6c commit a7e9ebd

File tree

6 files changed

+39
-457
lines changed

6 files changed

+39
-457
lines changed

bundle/internal/schema/annotations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) {
139139
}
140140

141141
if a.OutputOnly != nil && *a.OutputOnly {
142-
s.DoNotSuggest = true
142+
s.FieldBehaviors = []string{"OUTPUT_ONLY"}
143143
}
144144

145145
s.MarkdownDescription = convertLinksToAbsoluteUrl(a.MarkdownDescription)

bundle/internal/schema/main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,43 @@ func makeVolumeTypeOptional(typ reflect.Type, s jsonschema.Schema) jsonschema.Sc
145145
return s
146146
}
147147

148+
func removeOutputOnlyFields(typ reflect.Type, s jsonschema.Schema) jsonschema.Schema {
149+
// Only process object types with properties
150+
if s.Type != jsonschema.ObjectType || s.Properties == nil {
151+
return s
152+
}
153+
154+
// Collect property names to remove
155+
var toRemove []string
156+
for name, prop := range s.Properties {
157+
// Check if this property is marked as output-only via FieldBehaviors
158+
if prop.FieldBehaviors != nil {
159+
for _, behavior := range prop.FieldBehaviors {
160+
if behavior == "OUTPUT_ONLY" {
161+
toRemove = append(toRemove, name)
162+
break
163+
}
164+
}
165+
}
166+
}
167+
168+
// Remove output-only properties
169+
for _, name := range toRemove {
170+
delete(s.Properties, name)
171+
172+
// Also remove from required list if present
173+
var newRequired []string
174+
for _, r := range s.Required {
175+
if r != name {
176+
newRequired = append(newRequired, r)
177+
}
178+
}
179+
s.Required = newRequired
180+
}
181+
182+
return s
183+
}
184+
148185
func main() {
149186
if len(os.Args) != 3 {
150187
fmt.Println("Usage: go run main.go <work-dir> <output-file>")
@@ -189,6 +226,7 @@ func generateSchema(workdir, outputFile string) {
189226
removePipelineFields,
190227
makeVolumeTypeOptional,
191228
a.addAnnotations,
229+
removeOutputOnlyFields,
192230
addInterpolationPatterns,
193231
})
194232

0 commit comments

Comments
 (0)