GenerateConstants generates operation ids, context keys, paths, etc. to be exported as constants
(t *template.Template, ops []OperationDefinition)
| 644 | |
| 645 | // GenerateConstants generates operation ids, context keys, paths, etc. to be exported as constants |
| 646 | func GenerateConstants(t *template.Template, ops []OperationDefinition) (string, error) { |
| 647 | constants := Constants{ |
| 648 | SecuritySchemeProviderNames: []string{}, |
| 649 | } |
| 650 | |
| 651 | providerNameMap := map[string]struct{}{} |
| 652 | for _, op := range ops { |
| 653 | for _, def := range op.SecurityDefinitions { |
| 654 | providerName := SanitizeGoIdentity(def.ProviderName) |
| 655 | providerNameMap[providerName] = struct{}{} |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | providerNames := slices.Collect(maps.Keys(providerNameMap)) |
| 660 | sort.Strings(providerNames) |
| 661 | |
| 662 | constants.SecuritySchemeProviderNames = append(constants.SecuritySchemeProviderNames, providerNames...) |
| 663 | |
| 664 | return GenerateTemplates([]string{"constants.tmpl"}, t, constants) |
| 665 | } |
| 666 | |
| 667 | // GenerateTypesForSchemas generates type definitions for any custom types defined in the |
| 668 | // components/schemas section of the Swagger spec. |
no test coverage detected