Skip to content
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

snippetgen: turn resource path strings into f-strings #965

Closed
busunkim96 opened this issue Aug 3, 2021 · 0 comments · Fixed by #1012
Closed

snippetgen: turn resource path strings into f-strings #965

busunkim96 opened this issue Aug 3, 2021 · 0 comments · Fixed by #1012
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@busunkim96
Copy link
Contributor

Mock values generated for resource paths currently look like this: (see #941):

async def sample_delete_feed():
    """Snippet for delete_feed"""
    # Create a client
    client = asset_v1.AssetServiceAsyncClient()

    # Initialize request argument(s)
    request = asset_v1.DeleteFeedRequest(
        name="projects/{project}/feeds/{feed}",

To make it easier to understand how the string should be filled, it should be turned into a f-string with separate variables in the "initialize request argument(s) section".

async def sample_delete_feed():
    """Snippet for delete_feed"""
    # Create a client
    client = asset_v1.AssetServiceAsyncClient()

    # Initialize request argument(s)
    project = "my-project"
    feed = "my-feed"

    request = asset_v1.DeleteFeedRequest(
        name=f"projects/{project}/feeds/{feed}",
@busunkim96 busunkim96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Aug 3, 2021
@busunkim96 busunkim96 self-assigned this Aug 3, 2021
gcf-merge-on-green bot pushed a commit that referenced this issue Nov 5, 2021
Fixes #965.

Uses the already-existing resource path logic for autogen snippets.

Previous:
```py
    # Initialize request argument(s)
    request = asset_v1.DeleteFeedRequest(
        name="projects/{project}/feeds/{feed}",
    )
```

Now:
```py
    # Initialize request argument(s)
    project = "my-project-id"
    feed = "feed_value"
    name = f"projects/{project}/feeds/{feed}"

    request = asset_v1.DeleteFeedRequest(
        name=name,
    )
```

Note: The logic may result in multiple variables with the same name (it doesn't happen for any of the golden APIs, but might for an API with more required fields).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant