Skip to content

Commit b20e778

Browse files
author
Luke Sneeringer
committed
feat: AIP-163 – Change validation
1 parent fd72558 commit b20e778

3 files changed

Lines changed: 127 additions & 0 deletions

File tree

aip/general/0163/aip.md.j2

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Change validation
2+
3+
Occasionally, a user wants to validate an intended change to see what the
4+
result will be before actually making the change. For example, a request to
5+
provision new servers in a fleet will have an impact on the overall fleet size
6+
and cost, and could potentially have unexpected downstream effects.
7+
8+
## Guidance
9+
10+
APIs **may** provide an option to validate, but not actually execute, a
11+
request, and provide the same response (status code, headers, and response
12+
body) that it would have provided if the request was actually executed.
13+
14+
To provide this option, the method **should** include a `validate_only` boolean
15+
field:
16+
17+
```http
18+
POST /v1/publishers/{publisher}/books?validate_only=true HTTP/2
19+
Host: library.googleapis.com
20+
Accept: application/json
21+
```
22+
23+
- Standard operations **must** expose the `validate_only` field on the query
24+
string.
25+
- Custom operations **may** expose the `validate_only` field in the request
26+
body, on the query string, or accept either one.
27+
28+
The API **must** perform permission checks and any other validation that would
29+
be performed on a "live" request; a request using `validate_only` **must** fail
30+
if it determines that the actual request would fail.
31+
32+
**Note:** It may occasionally be infeasible to provide the full output. For
33+
example, if creating a resource would create an auto-generated ID, it does not
34+
make sense to do this on validation. APIs **should** omit such fields on
35+
validation requests in this situation.
36+
37+
## Interface Definitions
38+
39+
{% tab proto %}
40+
41+
{% sample 'standard_operation.proto', 'message CreateBookRequest' %}
42+
43+
- The `validate_only` field **must** use the `bool` type.
44+
- The `validate_only` field **must not** be annotated as `REQUIRED`.
45+
46+
{% endtabs %}

aip/general/0163/aip.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: 163
3+
state: approved
4+
created: 2019-12-16
5+
placement:
6+
category: design-patterns
7+
order: 90
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
import "google/api/annotations.proto";
18+
import "google/api/client.proto";
19+
import "google/api/field_behavior.proto";
20+
import "google/api/resource.proto";
21+
22+
service Library {
23+
// Create a single book.
24+
rpc CreateBook(CreateBookRequest) returns (Book) {
25+
option (google.api.http) = {
26+
post: "/v1/{parent=publishers/*}/books"
27+
body: "book"
28+
};
29+
option (google.api.method_signature) = "parent,book";
30+
}
31+
}
32+
33+
34+
// The request message for creating a book.
35+
message CreateBookRequest {
36+
// The parent collection where this book will be created.
37+
// Format: publishers/{publisher}
38+
string parent = 1 [
39+
(google.api.field_behavior) = REQUIRED,
40+
(google.api.resource_reference) = {
41+
child_type: "library.googleapis.com/Book"
42+
}];
43+
44+
// The book to create.
45+
Book book = 2 [(google.api.field_behavior) = REQUIRED];
46+
47+
// If set, validate the request and preview the review, but do not actually
48+
// post it.
49+
bool validate_only = 3;
50+
}
51+
52+
// A representation of a single book.
53+
message Book {
54+
option (google.api.resource) = {
55+
type: "library.googleapis.com/Book"
56+
pattern: "publishers/{publisher}/books/{book}"
57+
};
58+
59+
// The name of the book.
60+
// Format: publishers/{publisher}/books/{book}
61+
string name = 1;
62+
63+
// The ISBN (International Standard Book Number) for this book.
64+
string isbn = 2;
65+
66+
// The title of the book.
67+
string title = 3;
68+
69+
// The author or authors of the book.
70+
repeated string authors = 4;
71+
72+
// The rating assigned to the book.
73+
float rating = 5;
74+
}

0 commit comments

Comments
 (0)