import {z} from 'zod' export type GoogleCloudApihubV1AllowedValue = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined, immutable?: boolean | undefined}; export type GoogleCloudApihubV1Attribute = {allowedValues?: Array | undefined, cardinality?: number | undefined, createTime?: unknown | undefined, dataType?: ('DATA_TYPE_UNSPECIFIED' | 'ENUM' | 'JSON' | 'STRING' | 'URI') | undefined, definitionType?: ('DEFINITION_TYPE_UNSPECIFIED' | 'SYSTEM_DEFINED' | 'USER_DEFINED') | undefined, description?: string | undefined, displayName?: string | undefined, mandatory?: boolean | undefined, name?: string | undefined, scope?: ('SCOPE_UNSPECIFIED' | 'API' | 'VERSION' | 'SPEC' | 'API_OPERATION' | 'DEPLOYMENT' | 'DEPENDENCY' | 'DEFINITION' | 'EXTERNAL_API' | 'PLUGIN') | undefined, updateTime?: unknown | undefined}; export type PatchApiV1ProjectsProjectsIdLocationsLocationsIdAttributesAttributesIdArgs = {projectsId: string, locationsId: string, attributesId: string, updateMask?: unknown | undefined, body: GoogleCloudApihubV1Attribute}; export type PatchApiV1ProjectsProjectsIdLocationsLocationsIdAttributesAttributesIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudApihubV1AllowedValue = z.object({description: z.string().optional(), displayName: z.string().optional(), id: z.string().optional(), immutable: z.boolean().optional()}); export const googleCloudApihubV1Attribute = z.object({allowedValues: z.array(googleCloudApihubV1AllowedValue).optional(), cardinality: z.number().int().optional(), createTime: z.string().optional(), dataType: z.enum(["DATA_TYPE_UNSPECIFIED", "ENUM", "JSON", "STRING", "URI"]).optional(), definitionType: z.enum(["DEFINITION_TYPE_UNSPECIFIED", "SYSTEM_DEFINED", "USER_DEFINED"]).optional(), description: z.string().optional(), displayName: z.string().optional(), mandatory: z.boolean().optional(), name: z.string().optional(), scope: z.enum(["SCOPE_UNSPECIFIED", "API", "VERSION", "SPEC", "API_OPERATION", "DEPLOYMENT", "DEPENDENCY", "DEFINITION", "EXTERNAL_API", "PLUGIN"]).optional(), updateTime: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update the attribute. The following fields in the Attribute resource can be updated: * display_name The display name can be updated for user defined attributes only. * description The description can be updated for user defined attributes only. * allowed_values To update the list of allowed values, clients need to use the fetched list of allowed values and add or remove values to or from the same list. The mutable allowed values can be updated for both user defined and System defined attributes. The immutable allowed values cannot be updated or deleted. The updated list of allowed values cannot be empty. If an allowed value that is already used by some resource's attribute is deleted, then the association between the resource and the attribute value will also be deleted. * cardinality The cardinality can be updated for user defined attributes only. Cardinality can only be increased during an update. The update_mask should be used to specify the fields being updated. * * PATCH /v1/projects/{projectsId}/locations/{locationsId}/attributes/{attributesId} * * Also accepts auth: Oauth2 + Oauth2c */ export const patchApiV1ProjectsProjectsIdLocationsLocationsIdAttributesAttributesId = async (args: PatchApiV1ProjectsProjectsIdLocationsLocationsIdAttributesAttributesIdArgs, options?: PatchApiV1ProjectsProjectsIdLocationsLocationsIdAttributesAttributesIdOptions) => { const {baseUrl = "https://apihub.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/attributes/${encodeURIComponent(String(args.attributesId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(googleCloudApihubV1Attribute, await res.json()) };