Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions config/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4785,7 +4785,6 @@ api:
top_k: int
sample_rate: int
channel: int
files_before_body: true
response_type: SpeakerIdentifyResp
- path: /v1/audio/voiceprint_groups/{group_id}/features
method: post
Expand All @@ -4811,7 +4810,6 @@ api:
desc: str
sample_rate: int
channel: int
files_before_body: true
response_type: CreateVoicePrintGroupFeatureResp
- path: /v1/audio/voiceprint_groups/{group_id}/features/{feature_id}
method: put
Expand All @@ -4835,7 +4833,6 @@ api:
file: Optional[FileTypes]
sample_rate: int
channel: int
files_before_body: true
response_type: UpdateVoicePrintGroupFeatureResp
- path: /v1/audio/voiceprint_groups/{group_id}/features/{feature_id}
method: delete
Expand Down
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ type OperationMapping struct {
BodyFixedValues map[string]string `yaml:"body_fixed_values"`
BodyBuilder string `yaml:"body_builder"`
FilesFields []string `yaml:"files_fields"`
FilesBeforeBody bool `yaml:"files_before_body"`
PreDocstringCode []string `yaml:"pre_docstring_code"`
PreBodyCode []string `yaml:"pre_body_code"`
BodyRequiredFields []string `yaml:"body_required_fields"`
Expand Down
17 changes: 8 additions & 9 deletions internal/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGeneratePythonAudioTranscriptionsAsyncCreateFromMapping(t *testing.T) {
if got := strings.Count(module, "async def create("); got != 1 {
t.Fatalf("expected exactly one async create method, got %d", got)
}
if !strings.Contains(module, "files = {\"file\": _try_fix_file(file)}") {
if !strings.Contains(module, "files = {\"file\": _try_fix_file(file)} if file else {}") {
t.Fatalf("expected generated files payload from mapping/rendering, got:\n%s", module)
}
if !strings.Contains(module, "return await self._requester.arequest(") {
Expand Down Expand Up @@ -1306,7 +1306,7 @@ func TestRenderOperationMethodPageSizeDefaultAsyncOverride(t *testing.T) {
}
}

func TestRenderOperationMethodFilesBeforeBody(t *testing.T) {
func TestRenderOperationMethodFilesAfterBody(t *testing.T) {
doc := mustParseSwagger(t)
details := openapi.OperationDetails{
Path: "/v1/demo/{group_id}/features",
Expand All @@ -1328,10 +1328,9 @@ func TestRenderOperationMethodFilesBeforeBody(t *testing.T) {
MethodName: "create",
Details: details,
Mapping: &config.OperationMapping{
BodyBuilder: "remove_none_values",
BodyFields: []string{"name"},
FilesFields: []string{"file"},
FilesBeforeBody: true,
BodyBuilder: "remove_none_values",
BodyFields: []string{"name"},
FilesFields: []string{"file"},
ArgTypes: map[string]string{
"group_id": "str",
"name": "str",
Expand All @@ -1342,10 +1341,10 @@ func TestRenderOperationMethodFilesBeforeBody(t *testing.T) {

code := pygen.RenderOperationMethod(doc, binding, false)
headersIdx := strings.Index(code, "headers: Optional[dict] = kwargs.get(\"headers\")")
filesIdx := strings.Index(code, "files = {\"file\": _try_fix_file(file)}")
filesIdx := strings.Index(code, "files = {\"file\": _try_fix_file(file)} if file else {}")
bodyIdx := strings.Index(code, "body = remove_none_values(")
if headersIdx < 0 || filesIdx < 0 || bodyIdx < 0 || !(headersIdx < filesIdx && filesIdx < bodyIdx) {
t.Fatalf("expected files assignment before body assignment:\n%s", code)
if headersIdx < 0 || filesIdx < 0 || bodyIdx < 0 || !(headersIdx < bodyIdx && bodyIdx < filesIdx) {
t.Fatalf("expected files assignment after body assignment:\n%s", code)
}
}

Expand Down
18 changes: 2 additions & 16 deletions internal/generator/python/operation_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ func renderOperationMethodWithContext(
bodyFieldNames := make([]string, 0)
bodyFixedValues := map[string]string{}
filesFieldNames := make([]string, 0)
filesBeforeBody := false
if binding.Mapping != nil && len(binding.Mapping.BodyFields) > 0 {
bodyFieldNames = append(bodyFieldNames, binding.Mapping.BodyFields...)
}
Expand All @@ -581,9 +580,6 @@ func renderOperationMethodWithContext(
if binding.Mapping != nil && len(binding.Mapping.FilesFields) > 0 {
filesFieldNames = append(filesFieldNames, binding.Mapping.FilesFields...)
}
if binding.Mapping != nil {
filesBeforeBody = binding.Mapping.FilesBeforeBody
}
if !shouldGenerateImplicitRequestBody(details.Method, binding.Mapping, details.RequestBodySchema) {
requestBodyType = ""
bodyRequired = false
Expand Down Expand Up @@ -1110,11 +1106,7 @@ func renderOperationMethodWithContext(
fieldName := filesFieldNames[0]
argName := OperationArgName(fieldName, paramAliases)
valueExpr := fmt.Sprintf("_try_fix_file(%s)", argName)
if !bodyRequiredSet[fieldName] {
buf.WriteString(fmt.Sprintf(" files = {%q: %s} if %s else {}\n", fieldName, valueExpr, argName))
return true
}
buf.WriteString(fmt.Sprintf(" files = {%q: %s}\n", fieldName, valueExpr))
buf.WriteString(fmt.Sprintf(" files = {%q: %s} if %s else {}\n", fieldName, valueExpr, argName))
return true
}

Expand All @@ -1128,10 +1120,6 @@ func renderOperationMethodWithContext(
return true
}

if filesBeforeBody {
renderFilesAssignment()
}

if len(bodyFieldNames) > 0 {
if bodyBuilder == "raw" {
buf.WriteString(fmt.Sprintf(" %s = {\n", bodyVarAssign))
Expand Down Expand Up @@ -1213,9 +1201,7 @@ func renderOperationMethodWithContext(
buf.WriteString(" request_body = body.model_dump(exclude_none=True) if hasattr(body, \"model_dump\") else body\n")
}
}
if !filesBeforeBody {
renderFilesAssignment()
}
renderFilesAssignment()
if headersExpr == "" && !headersAssigned && includeKwargsHeaders && !isTokenPagination(paginationMode) && !isNumberPagination(paginationMode) && len(details.HeaderParameters) == 0 {
needsBlankLine := len(queryFields) > 0 ||
len(bodyFieldNames) > 0 ||
Expand Down