create method

Future<GoogleCloudApihubV1Spec> create(
  1. GoogleCloudApihubV1Spec request,
  2. String parent, {
  3. String? specId,
  4. String? $fields,
})

Add a spec to an API version in the API hub.

Multiple specs can be added to an API version. Note, while adding a spec, at least one of contents or source_uri must be provided. If contents is provided, then spec_type must also be provided. On adding a spec with contents to the version, the operations present in it will be added to the version.Note that the file contents in the spec should be of the same type as defined in the projects/{project}/locations/{location}/attributes/system-spec-type attribute associated with spec resource. Note that specs of various types can be uploaded, however parsing of details is supported for OpenAPI spec currently. In order to access the information parsed from the spec, use the GetSpec method. In order to access the raw contents for a particular spec, use the GetSpecContents method. In order to access the operations parsed from the spec, use the ListAPIOperations method.

request - The metadata request object.

Request parameters:

parent - Required. The parent resource for Spec. Format: projects/{project}/locations/{location}/apis/{api}/versions/{version} Value must have pattern ^projects/\[^/\]+/locations/\[^/\]+/apis/\[^/\]+/versions/\[^/\]+$.

specId - Optional. The ID to use for the spec, which will become the final component of the spec's resource name. This field is optional. * If provided, the same will be used. The service will throw an error if the specified id is already used by another spec in the API resource. * If not provided, a system generated id will be used. This value should be 4-500 characters, overall resource name which will be of format projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}, its length is limited to 1000 characters and valid characters are /a-z[0-9]-_/.

$fields - Selector specifying which fields to include in a partial response.

Completes with a GoogleCloudApihubV1Spec.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<GoogleCloudApihubV1Spec> create(
  GoogleCloudApihubV1Spec request,
  core.String parent, {
  core.String? specId,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (specId != null) 'specId': [specId],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = 'v1/' + core.Uri.encodeFull('$parent') + '/specs';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return GoogleCloudApihubV1Spec.fromJson(
    response_ as core.Map<core.String, core.dynamic>,
  );
}