File: helpers.go

package info (click to toggle)
golang-github-grpc-ecosystem-grpc-gateway.v2 2.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 6,148 kB
  • sloc: javascript: 352; makefile: 136; sh: 26
file content (35 lines) | stat: -rw-r--r-- 752 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//go:build go1.12
// +build go1.12

package genopenapi

import (
	"strings"

	"golang.org/x/text/cases"
	"golang.org/x/text/language"
)

func fieldName(k string) string {
	return strings.ReplaceAll(cases.Title(language.AmericanEnglish).String(k), "-", "_")
}

//this method will filter the same fields and return the unique one
func getUniqueFields(schemaFieldsRequired []string, fieldsRequired []string) []string {
	var unique []string
	var index *int

	for j, schemaFieldRequired := range schemaFieldsRequired {
		index = nil
		for i, fieldRequired := range fieldsRequired {
			if schemaFieldRequired == fieldRequired {
				index = &i
				break
			}
		}
		if index == nil {
			unique = append(unique, schemaFieldsRequired[j])
		}
	}
	return unique
}