您也可以直接呼叫 Service Management API,提交來源檔案。舉例來說,如果您有以下 OpenAPI 定義 (hello.json):
{"swagger":"2.0","info":{"title":"Hello Endpoints API.","description":"Hello Endpoints API.","version":"v1"},"host":"endpointsapis.appspot.com","schemes":["https"],"paths":{"/v1/hello":{"get":{"tags":["endpointsapis"],"operationId":"GetHello","description":"Returns \"Hello\" with given name in the response.","parameters":[{"name":"name","description":"Name to be greeted.","in":"query","type":"string"}],"responses":{"default":{"description":"Successful operation","schema":{"$ref":"#/definitions/GetHelloResponse"}}}}}},"definitions":{"GetHelloResponse":{"description":"Response message for GetHello method.","type":"object","properties":{"response":{"description":"String of \"Hello \" + `name` provided in the request.","type":"string"}}}}}
# List the service configuration history for a managed service.
$ gcurl https://servicemanagement.googleapis.com/v1/services/endpointsapis.appspot.com/configs
{
"serviceConfigs": [
{
"name": "endpointsapis.appspot.com",
"title": "Hello Endpoints API",
"id": "2016-07-16r1",
...
},
{
"name": "endpointsapis.appspot.com",
"title": "Hello Endpoints API",
"id": "2016-07-16r0",
...
}
]
}
# Get a specific version of the service configuration for a managed service.
$ gcurl https://servicemanagement.googleapis.com/v1/services/endpointsapis.appspot.com/configs/2016-07-16r0
{
"name": "endpointsapis.appspot.com",
"title": "Hello Endpoints API",
"id": "2016-07-16r0",
...
}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Managing Service Configurations\n\nThis page describes how to manage service configurations using Service Infrastructure.\n\nA [service configuration](/service-infrastructure/docs/glossary#config) is a specification that describes\ndifferent aspects of a [managed service](/service-infrastructure/docs/glossary#managed).\n\nThe Service Management API methods typically involved in managing service\nconfigurations are:\n\n- Using [`services.configs.create`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/create) or [`services.configs.submit`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/submit) to submit service configurations.\n- Using [`services.configs.list`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/list) and [`services.configs.get`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/get) to retrieve service configurations.\n- Using [`services.generateConfigReport`](/service-infrastructure/docs/service-management/reference/rest/v1/services/generateConfigReport) to get a change report between two service configurations.\n\nBefore you begin\n----------------\n\nTo run the examples in this guide, make sure you first follow the\ninstructions to complete the initial setup in\n[Getting Started with the Service Management API](/service-infrastructure/docs/service-management/getting-started).\n\n### Submitting service configuration source files\n\nTo update your service configuration, you need to submit a list of\nservice configuration source files to the Service Management API,\nand the server will compile them into a validated service configuration.\n\nThe source files can have the following formats:\n\n- [OpenAPI](https://github.com/OAI/OpenAPI-Specification) v2\n- Protocol Buffers descriptor\n- [`google.api.Service`](https://github.com/googleapis/googleapis/blob/master/google/api/service.proto) in JSON or YAML format\n\nThe Service Management API does not take `.proto` files, you need to\ngenerate protobuf descriptors from your `.proto` files before submitting them.\nYou can use use the following command to generate the descriptor files: \n\n $ protoc hello.proto --include_source_info --include_imports --descriptor_set_out=service.descriptors *.proto\n\nThe recommended way to submit service configuration source files is to use\nthe gcloud CLI. \n\n $ gcloud auth login\n $ gcloud endpoints services deploy [a list of service configuration source files]\n\nYou can also call the Service Management API directly to submit source\nfiles. For example, if you have this OpenAPI definition (`hello.json`): \n\n {\n \"swagger\": \"2.0\",\n \"info\": {\n \"title\": \"Hello Endpoints API.\",\n \"description\": \"Hello Endpoints API.\",\n \"version\": \"v1\"\n },\n \"host\": \"endpointsapis.appspot.com\",\n \"schemes\": [\"https\"],\n \"paths\": {\n \"/v1/hello\": {\n \"get\": {\n \"tags\": [\"endpointsapis\"],\n \"operationId\": \"GetHello\",\n \"description\": \"Returns \\\"Hello\\\" with given name in the response.\",\n \"parameters\": [\n {\n \"name\": \"name\",\n \"description\": \"Name to be greeted.\",\n \"in\": \"query\",\n \"type\": \"string\"\n }\n ],\n \"responses\": {\n \"default\": {\n \"description\": \"Successful operation\",\n \"schema\": {\n \"$ref\": \"#/definitions/GetHelloResponse\"\n }\n }\n }\n }\n }\n },\n \"definitions\": {\n \"GetHelloResponse\": {\n \"description\": \"Response message for GetHello method.\",\n \"type\": \"object\",\n \"properties\": {\n \"response\": {\n \"description\": \"String of \\\"Hello \\\" + `name` provided in the request.\",\n \"type\": \"string\"\n }\n }\n }\n }\n }\n\nYou can make the following API call to submit the OpenAPI spec: \n\n $ gcurl -d \"\n {\n 'serviceName': 'endpointsapis.appspot.com',\n 'configSource':\n {\n 'files': [\n {\n 'fileContents': '$(base64 hello.json | sed ':a;N;$!ba;s/\\n//g')',\n 'fileType': 'OPEN_API_JSON',\n 'filePath': 'hello.json',\n }\n ]\n }\n }\" https://servicemanagement.googleapis.com/v1/services/endpointsapis.appspot.com/configs:submit\n {\n \"name\": \"operations/serviceConfigs.endpointsapis.appspot.com:a7651c15-9017-4274-b065-d644cc337847\",\n \"metadata\": {\n \"@type\": \"type.googleapis.com/google.api.servicemanagement.v1.OperationMetadata\",\n \"resourceNames\": [\n \"services/endpointsapis.appspot.com/configs/2016-07-29r10\"\n ],\n \"startTime\": \"2016-07-29r10T23:59:21.081Z\",\n \"persisted\": true\n },\n \"done\": true,\n \"response\": {\n \"@type\": \"type.googleapis.com/google.api.servicemanagement.v1.SubmitConfigSourceResponse\",\n \"serviceConfig\": {\n \"name\": \"endpointsapis.appspot.com\",\n \"title\": \"Hello Endpoints API.\",\n ...\n }\n\nGenerating service configuration reports\n----------------------------------------\n\nBefore submitting a new service configuration version, you might want to\ncall the [`services.generateConfigReport`](/service-infrastructure/docs/service-management/reference/rest/v1/services/generateConfigReport)\nmethod to get a report of changes relative to an existing service\nconfiguration version. You can specify the version to be compared against using\nthe `old_config` field in the request, or you can simply skip this field to\ngenerate a report against the latest service configuration version.\n\nAssuming the new OpenAPI configuration file is called `hello.json`, you can\nrun the following command: \n\n $ gcurl -d \"\n {\n 'newConfig':\n {\n '@type': 'type.googleapis.com/google.api.servicemanagement.v1.ConfigSource',\n 'files': [\n {\n 'fileContents': '$(base64 hello.json | sed ':a;N;$!ba;s/\\n//g')',\n 'fileType': 'OPEN_API_JSON',\n 'filePath': 'hello.json',\n }\n ],\n }\n }\" https://servicemanagement.googleapis.com/v1/services:generateConfigReport\n\nIf you want to generate report for a specific configuration version, you can\nrun: \n\n # Generate config report for the local configration from `/tmp/hello.json`\n # and the configration version `2016-07-29r10`.\n $ gcurl -d \"\n {\n 'newConfig':\n {\n '@type': 'type.googleapis.com/google.api.servicemanagement.v1.ConfigSource',\n 'files': [\n {\n 'fileContents': '$(base64 hello.json | sed ':a;N;$!ba;s/\\n//g')',\n 'fileType': 'OPEN_API_JSON',\n 'filePath': 'hello.json',\n }\n ],\n },\n 'oldConfig':\n {\n '@type': 'type.googleapis.com/google.api.servicemanagement.v1.ConfigRef',\n 'name': 'services/endpointsapis.appspot.com/configs/2016-07-29r10'\n }\n }\" https://servicemanagement.googleapis.com/v1/services:generateConfigReport\n\nGetting prior service configuration versions\n--------------------------------------------\n\nThe Service Management API keeps a version history of submitted\nservice configurations. You can list them or retrieve a specific version using\nthe\n[`services.configs.list`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/list)\nor\n[`services.configs.get`](/service-infrastructure/docs/service-management/reference/rest/v1/services.configs/get)\nmethods, as illustrated by the following commands: \n\n # List the service configuration history for a managed service.\n $ gcurl https://servicemanagement.googleapis.com/v1/services/endpointsapis.appspot.com/configs\n {\n \"serviceConfigs\": [\n {\n \"name\": \"endpointsapis.appspot.com\",\n \"title\": \"Hello Endpoints API\",\n \"id\": \"2016-07-16r1\",\n ...\n },\n {\n \"name\": \"endpointsapis.appspot.com\",\n \"title\": \"Hello Endpoints API\",\n \"id\": \"2016-07-16r0\",\n ...\n }\n ]\n }\n\n # Get a specific version of the service configuration for a managed service.\n $ gcurl https://servicemanagement.googleapis.com/v1/services/endpointsapis.appspot.com/configs/2016-07-16r0\n {\n \"name\": \"endpointsapis.appspot.com\",\n \"title\": \"Hello Endpoints API\",\n \"id\": \"2016-07-16r0\",\n ...\n }"]]