Skip to content

Commit 3b56aae

Browse files
authored
chore(docs): change guidelines for snippet return values (#9562)
modify snippet method's return value guidelines to enable more robust testing. address markdown lint warning for the modified section of the document.
1 parent cd0b601 commit 3b56aae

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

SAMPLE_FORMAT.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,33 +348,39 @@ public static void exampleSnippet(String projectId, String filePath) {
348348
// Snippet content ...
349349
}
350350
```
351+
351352
### Method Structure
353+
352354
Method arguments should be limited to what is absolutely required for testing (ideally having at
353355
most 4 arguments). In most cases, this is project specific information or the path to an external
354356
file. For example, project specific information (such as `projectId`) or a `filePath` for an
355357
external file is acceptable, while an argument for the type of a file or a specific action is not.
356-
358+
357359
Any declared function arguments should include a no-arg, main method with examples for how
358360
the user can initialize the method arguments and call the entrypoint for the snippet. If the
359361
values for these variables need to be replaced by the user, be explicit that
360362
they are example values only.
361363

362-
Snippet methods should specify a return type of `void` and avoid returning any value wherever
363-
possible. Instead, show the user how to interact with a returned object programmatically by printing
364-
some example attributes to the console.
364+
Snippet methods should return data that can be used in the calling method to show the user how to
365+
interact with a returned object programmatically.
366+
365367
```java
366368
public static void main(String[] args) {
367369
// TODO(developer): Replace these variables before running the sample.
368370
String projectId = "my-project-id";
369371
String filePath = "path/to/image.png";
370-
inspectImageFile(projectId, filePath);
372+
List<String> results = inspectImageFile(projectId, filePath);
373+
for (String result : results) {
374+
// process result ...
375+
}
371376
}
372377

373378
// This is an example snippet for showing best practices.
374-
public static void exampleSnippet(String projectId, String filePath) {
379+
public static List<String> exampleSnippet(String projectId, String filePath) {
375380
// Snippet content ...
376381
}
377382
```
383+
378384
### Exception Handling
379385
Samples should include examples and details of how to catch and handle common `Exceptions` that are
380386
the result of improper interactions with the client or service. Lower level exceptions that are

0 commit comments

Comments
 (0)