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

feat: support snippet generation for services that only support REST transport #1656

Merged
merged 2 commits into from
May 8, 2023

Conversation

dizcology
Copy link
Collaborator

@dizcology dizcology commented May 1, 2023

Fixes #1465

This adds support for services that support only the REST transport (Compute). For such services we now generate a sync snippet for every method, for example:

# -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated code. DO NOT EDIT!
#
# Snippet for Get
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.

# To install the latest published package dependency, execute the following:
#   python3 -m pip install google-cloud-compute


# [START compute_v1_generated_AcceleratorTypes_Get_sync]
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import compute_v1


def sample_get():
    # Create a client
    client = compute_v1.AcceleratorTypesClient()

    # Initialize request argument(s)
    request = compute_v1.GetAcceleratorTypeRequest(
        accelerator_type="accelerator_type_value",
        project="project_value",
        zone="zone_value",
    )

    # Make the request
    response = client.get(request=request)

    # Handle the response
    print(response)

# [END compute_v1_generated_AcceleratorTypes_Get_sync]

No changes for services that support gRPC transport, we still generate both sync and async snippets for each method.

Additional changes:

  • Ran code formatter on test_samplegen.py. The only updated test is test_generate_sample_spec_basic.

@dizcology dizcology requested review from a team as code owners May 1, 2023 18:08
@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label May 1, 2023
@dizcology dizcology added the owlbot:run Add this label to trigger the Owlbot post processor. label May 1, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 1, 2023
@dizcology dizcology requested review from parthea and atulep May 1, 2023 18:19
return "async"
else: # api.TRANSPORT_REST
return "rest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now method will return "sync" whereas before it was "rest". Will this break anything?

Copy link
Collaborator Author

@dizcology dizcology May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMing from the side of SnippetGen.

Thanks @dizcology !

@parthea parthea merged commit bb60a3d into googleapis:main May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR(snippetgen): Add support for REST snippets
4 participants