-
Notifications
You must be signed in to change notification settings - Fork 134
/
http_uri_parent.go
54 lines (49 loc) · 1.88 KB
/
http_uri_parent.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aip0133
import (
"github.com/googleapis/api-linter/lint"
"github.com/googleapis/api-linter/rules/internal/utils"
"github.com/jhump/protoreflect/desc"
)
// Create methods should have a parent variable if the resource isn't top-level.
// This should be the only variable in the URI path.
var httpURIParent = &lint.MethodRule{
Name: lint.NewRuleName(133, "http-uri-parent"),
OnlyIf: func(m *desc.MethodDescriptor) bool {
// The response type of a Standard Create method must be the resource
// itself, unless it is an LRO, in which case, the operation_info field
// response_type must be the resource.
res := m.GetOutputType()
if info := utils.GetOperationInfo(m); info != nil {
res = utils.FindMessage(m.GetFile(), info.GetResponseType())
// If we cannot resolve the response_type, then skip this check.
// There is nothing we can do, and must let the check specific to
// unresolvable operation_info types do its thing.
if res == nil {
return false
}
}
return utils.IsCreateMethod(m) && !hasNoParent(res)
},
LintMethod: func(m *desc.MethodDescriptor) []lint.Problem {
if problems := utils.LintHTTPURIHasParentVariable(m); problems != nil {
return problems
}
if problems := utils.LintHTTPURIVariableCount(m, 1); problems != nil {
return problems
}
return nil
},
}