MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / GenerateConstants

Function GenerateConstants

pkg/codegen/codegen.go:646–665  ·  view source on GitHub ↗

GenerateConstants generates operation ids, context keys, paths, etc. to be exported as constants

(t *template.Template, ops []OperationDefinition)

Source from the content-addressed store, hash-verified

644
645// GenerateConstants generates operation ids, context keys, paths, etc. to be exported as constants
646func 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.

Callers 1

GenerateFunction · 0.85

Calls 2

SanitizeGoIdentityFunction · 0.85
GenerateTemplatesFunction · 0.85

Tested by

no test coverage detected