UsedVariables returns the subset of OAPISchema.Variables whose `{name}` placeholder actually appears in OAPISchema.URL. Variables declared but unused are skipped — they would otherwise produce a type, constant, function parameter, and a no-op `strings.ReplaceAll` (https://github.com/oapi-codegen/oap
()
| 53 | // both server-urls.tmpl and BuildServerURLTypeDefinitions so that |
| 54 | // emitted types and the generated function signature stay in sync. |
| 55 | func (s ServerObjectDefinition) UsedVariables() map[string]*openapi3.ServerVariable { |
| 56 | if s.OAPISchema == nil || len(s.OAPISchema.Variables) == 0 { |
| 57 | return nil |
| 58 | } |
| 59 | placeholders := urlPlaceholders(s.OAPISchema.URL) |
| 60 | used := make(map[string]*openapi3.ServerVariable, len(s.OAPISchema.Variables)) |
| 61 | for name, v := range s.OAPISchema.Variables { |
| 62 | if _, ok := placeholders[name]; ok { |
| 63 | used[name] = v |
| 64 | } |
| 65 | } |
| 66 | return used |
| 67 | } |
| 68 | |
| 69 | // UndeclaredPlaceholders returns the sorted list of `{name}` |
| 70 | // placeholder names that appear in OAPISchema.URL but have no |