Commit b0d0791
authored
refactor: (class-generator) Migrate schema extraction from OpenAPI v2 to v3 (#2473)
* fix: Extract schemas from CRDs with OpenAPIV3Schema for class generation
* fix: Handle Python reserved keywords in generated resource classes
- Add keyword module import and sanitization mapping
- Create sanitize_python_name() to append underscore to Python keywords
- Update prepare_property_dict() to apply keyword sanitization
- Modify Jinja template to document renamed parameters
- Ensure to_dict() maps sanitized names back to original field names
This fixes syntax errors when CRD fields use Python reserved keywords
like 'finally' in Tekton Pipeline resources. The solution automatically
renames conflicting parameters (e.g., 'finally' → 'finally_') while
preserving the original field names in the API representation.
Example: Pipeline.finally becomes finally_ parameter but still maps to
spec["finally"] in to_dict() method.
* fix: Replace mapping.clear() with atomic update in CRD schema extraction
- Use enumerate to track mapping index for in-place replacement
- Create new mapping dictionary from full_schema.copy()
- Add namespaced field to new mapping
- Replace old mapping atomically without intermediate empty state
This prevents potential data loss if an error occurs between clearing
and updating the mapping. The new approach ensures the update is atomic
and the original data remains intact if any step fails.
* refactor: Extract helper functions from extract_crd_schemas for better maintainability
- Extract _should_update_schema() to determine if schema needs updating
- Extract _format_crd_schema() to handle schema formatting logic
- Extract _update_resource_mapping() to manage resource mapping updates
- Reduce main function from 124 to ~50 lines
This refactoring improves code maintainability by following the Single
Responsibility Principle. Each helper function now has a focused purpose,
making the code easier to test, understand, and modify. The main function
now clearly shows the high-level flow of CRD schema extraction.
* update schema
* refactor: Remove individual schema files from git
- Keep only __resources-mappings.json and _definitions.json in git
- Add other schema files to .gitignore
- Schema files remain locally but are removed from repository
- This reduces repo size by ~2000 files that are generated during build
* refactor: (class-generator) Migrate schema extraction from OpenAPI v2 to v3
* fix(class-generator): migrate to OpenAPI v3, fix duplicate imports and allOf spec handling, improve namespacing detection1 parent e88d456 commit b0d0791
2,093 files changed
Lines changed: 16791 additions & 855164 deletions
File tree
- class_generator
- manifests
- schema
- scripts
- tests
- tests/manifests
- Machine
- NMState
- Pipeline
- Pod
- ocp_resources/utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
4 | 13 | | |
5 | 14 | | |
6 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | 141 | | |
143 | 142 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | 143 | | |
158 | 144 | | |
159 | 145 | | |
| |||
172 | 158 | | |
173 | 159 | | |
174 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
0 commit comments