Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions internal/schemas/generator/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
pythonPackageRoot = "models"
pythonAdoptModelsStructure = "sorted"
pythonGeneratedFolder = "models/workdir"
pythonImage = "docker.io/koxudaxi/datamodel-code-generator:0.31.2"
pythonImage = "docker.io/koxudaxi/datamodel-code-generator:0.59.0"
)

var importRE = regexp.MustCompile(`^(from\s+)(\.*)([^\s]+)(.*)`)
Expand Down Expand Up @@ -542,19 +542,6 @@ func processOpenAPIContent(doc *openapi3.T) *openapi3.T { //nolint:gocognit // s
return doc
}

func fixAliasedTypesInFile(fs afero.Fs, filePath string) error {
fileContent, err := afero.ReadFile(fs, filePath)
if err != nil {
return errors.Wrapf(err, "reading file %s", filePath)
}

content := string(fileContent)
content = strings.ReplaceAll(content, "bool_aliased", "bool")
content = strings.ReplaceAll(content, "int_aliased", "int")

return afero.WriteFile(fs, filePath, []byte(content), os.ModePerm)
}

func postTransformOpenAPI(fs afero.Fs, sourceDir, targetDir string) error {
createdInitDirs := make(map[string]bool)

Expand Down Expand Up @@ -587,8 +574,8 @@ func postTransformOpenAPI(fs afero.Fs, sourceDir, targetDir string) error {
return err
}

if err := postProcessFile(fs, destPath); err != nil {
return err
if err := adjustImportsInFile(fs, destPath); err != nil {
return errors.Wrapf(err, "adjusting imports")
Comment on lines +577 to +578
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Restore actionable context in the wrapped import-adjustment error.

At Line 578, the wrap message dropped file context, which makes failures hard to act on during generation. Can we include destPath and a brief user-facing hint?

💡 Proposed fix
-		if err := adjustImportsInFile(fs, destPath); err != nil {
-			return errors.Wrapf(err, "adjusting imports")
+		if err := adjustImportsInFile(fs, destPath); err != nil {
+			return errors.Wrapf(err, "cannot adjust generated python imports for %q; verify generated model paths and try again", destPath)
 		}

As per coding guidelines, "CRITICAL: Ensure all error messages are meaningful to end users, not just developers - avoid technical jargon, include context about what the user was trying to do, and suggest next steps when possible."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err := adjustImportsInFile(fs, destPath); err != nil {
return errors.Wrapf(err, "adjusting imports")
if err := adjustImportsInFile(fs, destPath); err != nil {
return errors.Wrapf(err, "cannot adjust generated python imports for %q; verify generated model paths and try again", destPath)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/schemas/generator/python.go` around lines 577 - 578, The wrapped
error from adjustImportsInFile drops the file context making failure messages
unhelpful; update the errors.Wrapf call in the caller that invokes
adjustImportsInFile (the block containing if err := adjustImportsInFile(fs,
destPath); err != nil) to include destPath and a short user-facing hint (e.g.,
"unable to update imports for generated file %s; check file permissions or
import paths and re-run generation") so the error becomes errors.Wrapf(err,
"unable to update imports for generated file %s; check file permissions or
import paths and re-run generation", destPath).

}

return transformMetaImportsInFile(fs, destPath)
Expand Down Expand Up @@ -679,13 +666,6 @@ func copyFileWithInit(fs afero.Fs, srcPath, destPath, destDir string, created ma
return nil
}

func postProcessFile(fs afero.Fs, path string) error {
if err := adjustImportsInFile(fs, path); err != nil {
return errors.Wrapf(err, "adjusting imports")
}
return errors.Wrapf(fixAliasedTypesInFile(fs, path), "fixing aliased types")
}

func isMetaV1File(path string) bool {
return strings.HasSuffix(filepath.ToSlash(path), "apis/meta/v1.py")
}
Expand Down
Loading