-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update generated samples to executable format #874
Conversation
Codecov Report
@@ Coverage Diff @@
## main #874 +/- ##
==========================================
+ Coverage 87.84% 87.93% +0.08%
==========================================
Files 153 156 +3
Lines 15966 16068 +102
Branches 1155 1155
==========================================
+ Hits 14025 14129 +104
Misses 1601 1601
+ Partials 340 338 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM on how the resulting samples are looking, this is great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amanda-tarafa @eaball35
I see that this only updates inline samples, and the single-file samples as described in the design are not part of this PR.
I'm a little surprised to see essentially the whole executable sample file with imports and a wrapping application class inline. Was that the intent of the original design all along? Do you feel like this might be adding too much boilerplate repetitive code to the javadoc samples?
@meltsufin I'm starting a thread internally to discuss more in-depth, but basically, these aspects are up for decision for each language, as they know their community better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just went over the top part of the PR. Will take another look later.
.../java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java
Show resolved
Hide resolved
this.sampleVariableAssignments = sampleVariableAssignments; | ||
this.sampleBody = sampleBody; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm: is there any chance that the input List
instances may be modified?
return sampleName; | ||
} | ||
|
||
public List<AssignmentExpr> getSampleVariableAssignments() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, any chance that the output List
object may be modified?
src/main/java/com/google/api/generator/gapic/composer/samplecode/ExecutableSampleComposer.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/gapic/composer/samplecode/ExecutableSampleComposer.java
Outdated
Show resolved
Hide resolved
JavaWriterVisitor visitor = new JavaWriterVisitor(); | ||
classDefinition.accept(visitor); | ||
// Escape character "@" in the markdown code block <pre>{@code...} tags. | ||
return visitor.write().replaceAll("@", "{@literal @}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since write(List<Statement>)
does this too, will this end up double-escaping @
? If not, I actually think this is unnecessary? And should we format code here instead of write(List<Statement>)
?
src/main/java/com/google/api/generator/gapic/composer/samplecode/SampleUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/gapic/composer/samplecode/SampleUtil.java
Outdated
Show resolved
Hide resolved
public static MethodInvocationExpr systemOutPrint(String content) { | ||
return composeSystemOutPrint(ValueExpr.withValue(StringObjectValue.withValue(content))); | ||
} | ||
|
||
public static MethodInvocationExpr systemOutPrint(VariableExpr variableExpr) { | ||
return composeSystemOutPrint(variableExpr.toBuilder().setIsDecl(false).build()); | ||
} | ||
|
||
static MethodInvocationExpr composeSystemOutPrint(Expr content) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These method are not called by non-test code. Let's remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, however I created them because eventually I will definitely want to use them in the samples to handle the responses. I was just getting a little ahead of myself implementing these now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually what I suspected. Let's add them in the future when they are needed.
...java/com/google/api/generator/gapic/composer/samplecode/ServiceClientSampleCodeComposer.java
Show resolved
Hide resolved
Forking as new branch as we decided to not make inline snippets "executable" format but instead link to full example if users wants it - #882 |
chore: pin versions of certifi and google-resumable-media Source-Link: googleapis/synthtool@09c4fcd Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:264c6d5da60ff1684fbdd2b268d6a3ffca2038246e0948a06f15ca0c3cf28ce8 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
…874) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.protobuf:protobuf-bom](https://developers.google.com/protocol-buffers/) ([source](https://togithub.com/protocolbuffers/protobuf)) | `3.21.2` -> `3.21.3` | [![age](https://badges.renovateapi.com/packages/maven/com.google.protobuf:protobuf-bom/3.21.3/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.protobuf:protobuf-bom/3.21.3/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.protobuf:protobuf-bom/3.21.3/compatibility-slim/3.21.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.protobuf:protobuf-bom/3.21.3/confidence-slim/3.21.2)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>protocolbuffers/protobuf</summary> ### [`v3.21.3`](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.2...v3.21.3) [Compare Source](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.2...v3.21.3) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMjIuMSIsInVwZGF0ZWRJblZlciI6IjMyLjEyMi4xIn0=-->
🤖 I have created a release *beep* *boop* --- ## [2.8.3](googleapis/java-core@v2.8.2...v2.8.3) (2022-07-26) ### Dependencies * update dependency com.google.api-client:google-api-client-bom to v2 ([#868](googleapis/java-core#868)) ([fe7991d](googleapis/java-core@fe7991d)) * update dependency com.google.api:gax-bom to v2.18.4 ([#864](googleapis/java-core#864)) ([d4a8501](googleapis/java-core@d4a8501)) * update dependency com.google.api:gax-bom to v2.18.5 ([#876](googleapis/java-core#876)) ([e2c0c13](googleapis/java-core@e2c0c13)) * update dependency com.google.api.grpc:proto-google-common-protos to v2.9.2 ([#870](googleapis/java-core#870)) ([adf5af4](googleapis/java-core@adf5af4)) * update dependency com.google.api.grpc:proto-google-iam-v1 to v1.5.2 ([#865](googleapis/java-core#865)) ([5dad1ea](googleapis/java-core@5dad1ea)) * update dependency com.google.auth:google-auth-library-bom to v1.8.1 ([#856](googleapis/java-core#856)) ([bb58609](googleapis/java-core@bb58609)) * update dependency com.google.http-client:google-http-client-bom to v1.42.2 ([#871](googleapis/java-core#871)) ([341b04e](googleapis/java-core@341b04e)) * update dependency com.google.protobuf:protobuf-bom to v3.21.3 ([#874](googleapis/java-core#874)) ([efe8c28](googleapis/java-core@efe8c28)) * update dependency com.google.protobuf:protobuf-bom to v3.21.4 ([#877](googleapis/java-core#877)) ([25bea6c](googleapis/java-core@25bea6c)) * update dependency io.grpc:grpc-bom to v1.48.0 ([#873](googleapis/java-core#873)) ([8bfee63](googleapis/java-core@8bfee63)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
b/207550139, b/207550144
go/java-sample-gen
go/java-sample-gen-bugs