| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2897cdc commit 14fc88e
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -486,7 +486,21 @@ paths: | |||
| 486 | 486 | responses: | |
| 487 | 487 | default: | |
| 488 | 488 | $ref: "#/components/responses/SimpleResponse" | |
| 489 | - | ||
| 489 | + /enums: | ||
| 490 | + get: | ||
| 491 | + operationId: enumParams | ||
| 492 | + parameters: | ||
| 493 | + - name: enumPathParam | ||
| 494 | + description: Parameter with enum values | ||
| 495 | + in: query | ||
| 496 | + required: false | ||
| 497 | + schema: | ||
| 498 | + type: integer | ||
| 499 | + format: int32 | ||
| 500 | + enum: [100, 200] | ||
| 501 | + responses: | ||
| 502 | + 204: | ||
| 503 | + description: no content | ||
| 490 | 504 | components: | |
| 491 | 505 | schemas: | |
| 492 | 506 | Object: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -323,12 +323,21 @@ func GenerateTypeDefinitions(t *template.Template, swagger *openapi3.T, ops []Op | |||
| 323 | 323 | } | |
| 324 | 324 | allTypes = append(allTypes, bodyTypes...) | |
| 325 | 325 | ||
| 326 | - paramTypesOut, err := GenerateTypesForOperations(t, ops) | ||
| 326 | + // Go through all operations, and add their types to allTypes, so that we can | ||
| 327 | + // scan all of them for enums. Operation definitions are handled differently | ||
| 328 | + // from the rest, so let's keep track of enumTypes separately, which will contain | ||
| 329 | + // all types needed to be scanned for enums, which includes those within operations. | ||
| 330 | + enumTypes := allTypes | ||
| 331 | + for _, op := range ops { | ||
| 332 | + enumTypes = append(enumTypes, op.TypeDefinitions...) | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + operationsOut, err := GenerateTypesForOperations(t, ops) | ||
| 327 | 336 | if err != nil { | |
| 328 | 337 | return "", fmt.Errorf("error generating Go types for component request bodies: %w", err) | |
| 329 | 338 | } | |
| 330 | 339 | ||
| 331 | - enumsOut, err := GenerateEnums(t, allTypes) | ||
| 340 | + enumsOut, err := GenerateEnums(t, enumTypes) | ||
| 332 | 341 | if err != nil { | |
| 333 | 342 | return "", fmt.Errorf("error generating code for type enums: %w", err) | |
| 334 | 343 | } | |
@@ -348,7 +357,7 @@ func GenerateTypeDefinitions(t *template.Template, swagger *openapi3.T, ops []Op | |||
| 348 | 357 | return "", fmt.Errorf("error generating union boilerplate: %w", err) | |
| 349 | 358 | } | |
| 350 | 359 | ||
| 351 | - typeDefinitions := strings.Join([]string{enumsOut, typesOut, paramTypesOut, allOfBoilerplate, unionBoilerplate}, "") | ||
| 360 | + typeDefinitions := strings.Join([]string{enumsOut, typesOut, operationsOut, allOfBoilerplate, unionBoilerplate}, "") | ||
| 352 | 361 | return typeDefinitions, nil | |
| 353 | 362 | } | |
| 354 | 363 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -625,7 +625,7 @@ func GenerateParamsTypes(op OperationDefinition) []TypeDefinition { | |||
| 625 | 625 | return append(typeDefs, td) | |
| 626 | 626 | } | |
| 627 | 627 | ||
| 628 | - // Generates code for all types produced | ||
| 628 | + // GenerateTypesForOperations generates code for all types produced within operations | ||
| 629 | 629 | func GenerateTypesForOperations(t *template.Template, ops []OperationDefinition) (string, error) { | |
| 630 | 630 | var buf bytes.Buffer | |
| 631 | 631 | w := bufio.NewWriter(&buf) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments