Skip to content

Conversation

@orcswang-lang
Copy link

Fix the Swagger documentation generated when useDefinitions is set to true in the API file info. For POST type interfaces, although the parameter definitions are fully generated in the definitions, the parameters will be missing.

@orcswang-lang orcswang-lang changed the title fix(swagger): 修复POST JSON参数判断逻辑错误 fix(swagger): Fix logic error in POST JSON parameter validation. Jun 25, 2025
@codecov
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.89%. Comparing base (8690859) to head (a29e13f).
Report is 368 commits behind head on master.

Additional details and impacted files

see 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… enum value parsing

Correctly handle $ref references for composite types, including structs, pointers, arrays, and map types.

Optimize the enum value parsing logic to support mixed enums of boolean and string types.
@kevwan kevwan requested review from Copilot and kesonan June 29, 2025 12:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that Swagger definitions are correctly referenced when UseDefinitions is enabled, fixes POST JSON parameter detection, and updates enum option parsing.

  • Add $ref support for array item types in itemsFromGoType when using definitions
  • Refactor propertiesFromType to delegate to a new buildSchemaWithDefinitions helper
  • Correct isPostJson logic for POST methods and overhaul enum parsing in enumsValueFromOptions

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tools/goctl/api/swagger/swagger.go Added handling for array types referencing definitions in itemsFromGoType
tools/goctl/api/swagger/properties.go Introduced buildSchemaWithDefinitions and updated propertiesFromType to use it
tools/goctl/api/swagger/parameter.go Fixed inverted check in isPostJson to correctly detect POST requests
tools/goctl/api/swagger/options.go Refactored enumsValueFromOptions to parse "options=" flag values
Comments suppressed due to low confidence (1)

tools/goctl/api/swagger/properties.go:53

  • This new UseDefinitions branch in propertiesFromType covers multiple composite types but lacks dedicated tests. Please add unit tests for struct, array, and map definitions scenarios to verify correct $ref generation.
			if ctx.UseDefinitions {

return nil
}

if ctx.UseDefinitions {
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

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

The logic for handling struct references in itemsFromGoType duplicates similar code in buildSchemaWithDefinitions. Consider extracting a shared helper to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
})
for _, field := range fields {
resp = append(resp, field)
if strings.HasPrefix(option, "options=") {
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

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

[nitpick] Hardcoding the prefix "options=" instead of using the existing enumFlag constant may cause inconsistency. Consider using enumFlag for matching the enum option.

Copilot uses AI. Check for mistakes.
@kesonan
Copy link
Collaborator

kesonan commented Jun 30, 2025

  1. please provide the generation changes before and after fixed
  2. please add some unit tests

enums = append(enums, true)
} else if enum == "false" {
enums = append(enums, false)
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

else if !stringx.IsWhiteSpace(enum)?


func isPostJson(ctx Context, method string, tp apiSpec.Type) (string, bool) {
if strings.EqualFold(method, http.MethodPost) {
if !strings.EqualFold(method, http.MethodPost) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate with #4997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants