GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(snippetgen): generate mock input for required fields by busunkim96 · Pull Request #941 · googleapis/gapic-generator-python

This repository was archived by the owner on Aug 25, 2026. It is now read-only.

Conversation

@busunkim96

@busunkim96 busunkim96 commented Jun 29, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Generate mock field inputs for all required fields.

  • For oneofs, the first option is selected.
  • For enums, the last option is selected (as 0 is often unspecified).
  • Mock input for string fields that reference resources (resource_pb2.resource_reference) is the pattern provided in the protos.

TODOs:

  • When a resource's pattern is * this results in unhelpful strings

    message Asset {
      option (google.api.resource) = {
        type: "cloudasset.googleapis.com/Asset"
        pattern: "*"
      };
    request = asset_v1.BatchGetAssetsHistoryRequest(
       parent="*",
    )
  • Map fields are not yet handled.

Other changes:

  • Fields are set like foo.bar rather than through dict access foo["bar"]. This is because the former allows you to set fields nested more than one field deep foo.bar.baz.

    Before:

    output_config = {}
    output_config["gcs_destination"]["uri"] = "uri_value" # fails as there is no nested dict

    After:

    output_config = asset_v1.IamPolicyAnalysisOutputConfig()
    output_config.gcs_destination.uri = "uri_value"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
busunkim96 added 4 commits June 29, 2021 20:02
@busunkim96
feat: add async samples
236ffeb
@busunkim96
chore: fix style
d7befe4
@busunkim96
feat(snippetgen): set mock input for required fields
c8ddc50
@busunkim96
fix: handle enums
d397120
@snippet-bot

snippet-bot Bot commented Jun 29, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 2 region tags.
  • tests/snippetgen/goldens/mollusca_generated_mollusca_v1_snippets_one_of_method_async.py:26, tag mollusca_generated_mollusca_v1_Snippets_OneOfMethod_async
  • tests/snippetgen/goldens/mollusca_generated_mollusca_v1_snippets_one_of_method_sync.py:26, tag mollusca_generated_mollusca_v1_Snippets_OneOfMethod_sync

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 29, 2021
busunkim96 added 3 commits June 29, 2021 20:21
@busunkim96
chore: format
66cd70e
@busunkim96
fix: generate request in preprocess_sample
bcef9ab
@busunkim96
fix: use child_type as well
cc3de56
@busunkim96
busunkim96 marked this pull request as ready for review June 29, 2021 21:38
@busunkim96
busunkim96 requested review from a team, dizcology, parthea and software-dov June 29, 2021 21:38
leahecole
leahecole reviewed Jul 19, 2021
View reviewed changes

@leahecole leahecole left a comment

Copy link
Copy Markdown

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.

Okay @busunkim96 - I looked at some - didn't make it through all, but a lot of my comments will apply to multiple samples, I think. Hope it was at least a little helpful!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...nerated_samples/cloudasset_generated_asset_v1_asset_service_batch_get_assets_history_sync.py

# Initialize request argument(s)
request = asset_v1.BatchGetAssetsHistoryRequest(
parent="*",

@leahecole leahecole Jul 19, 2021

Copy link
Copy Markdown

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.

I'm not familiar with this syntax - is this asterisk something that's typical for this service?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@busunkim96 busunkim96 Jul 27, 2021

Copy link
Copy Markdown
Contributor Author

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.

The * wouldn't actually work if passed to the service. The snippetgen logic pulls the first resource pattern out of the protos, and in some uncommon cases it is just a * rather than some more specific pattern like projects/{project}. The * pattern creates problems for generating resource helper methods and tests too - see #701

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...et/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_create_feed_sync.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...t/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_delete_feed_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...et/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_delete_feed_sync.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...mples/iamcredentials_generated_credentials_v1_iam_credentials_generate_access_token_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...edis/samples/generated_samples/redis_generated_redis_v1_cloud_redis_update_instance_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/snippetgen/goldens/mollusca_generated_mollusca_v1_snippets_method_bidi_streaming_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

parthea
parthea approved these changes Jul 22, 2021
View reviewed changes
This was referenced Jul 23, 2021
snippetgen: add 2+ placeholder values for list field values #961
Closed
snippetgen: Use f-strings #960
Closed
@busunkim96
chore: rename a_string -> my_string
95282b5
software-dov
software-dov reviewed Aug 2, 2021
View reviewed changes
Comment thread gapic/samplegen/samplegen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/samplegen/samplegen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/schema/wrappers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...et/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_create_feed_sync.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...t/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_delete_feed_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JustinBeckwith
Merge branch 'master' into mock_fields
6f68c30
@busunkim96 busunkim96 mentioned this pull request Aug 3, 2021
snippetgen: turn resource path strings into f-strings #965
Closed
@busunkim96
fix: address review comments
70e1cea
@busunkim96

busunkim96 commented Aug 3, 2021

Copy link
Copy Markdown
Contributor Author

@software-dov Thank you for the review! PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@parthea parthea assigned software-dov Aug 4, 2021
software-dov
software-dov reviewed Aug 9, 2021
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

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.

Mostly nitpicking and one minor concern, looks great! Thanks for doing this, and I hope the existing samplegen code wasn't too unpleasant to work with.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/samplegen/samplegen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/schema/wrappers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/schema/wrappers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

busunkim96 and others added 4 commits August 11, 2021 00:08
@busunkim96
fix: consolidate duplicated logic for inner_mock
b5c8e24
@busunkim96
refactor: address review comments
77b1b88
@busunkim96
fix: fix typing errors
a8384e6
@busunkim96
Merge branch 'master' into mock_fields
39627a7
busunkim96 added 3 commits August 13, 2021 23:39
@busunkim96
fix: fix unit tests
3f3e73a
@busunkim96
chore: fix formatting
ef387f1
@busunkim96
chore: fix style
78251e0
software-dov
software-dov approved these changes Aug 18, 2021
View reviewed changes
@busunkim96
busunkim96 merged commit b2149da into master Aug 18, 2021
@busunkim96
busunkim96 deleted the mock_fields branch August 18, 2021 21:36
This was referenced Jan 18, 2022
chore(master): release reverted #1133
Merged
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@dizcology dizcology Awaiting requested review from dizcology
4 more reviewers
@leahecole leahecole leahecole left review comments
@amanda-tarafa amanda-tarafa amanda-tarafa left review comments
@software-dov software-dov software-dov approved these changes
@parthea parthea parthea approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@software-dov software-dov

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@busunkim96 @software-dov @parthea @leahecole @amanda-tarafa @JustinBeckwith
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.