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 CreateApiV1ProjectsProjectsIdLocationsLocationsIdAttributesArgs = {projectsId: string, locationsId: string, attributeId?: string | undefined, body: GoogleCloudApihubV1Attribute}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdAttributesOptions = {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 }; /** * Create a user defined attribute. Certain pre defined attributes are already created by the API hub. These attributes will have type as `SYSTEM_DEFINED` and can be listed via ListAttributes method. Allowed values for the same can be updated via UpdateAttribute method. * * POST /v1/projects/{projectsId}/locations/{locationsId}/attributes * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdAttributes = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdAttributesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdAttributesOptions) => { 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.attributeId != null) query.append("attributeId", String(args.attributeId)) 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${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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()) };