import {z} from 'zod' export type GoogleCloudApihubV1AllowedValue = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined, immutable?: boolean | undefined}; export type GoogleCloudApihubV1EnumAttributeValues = {values?: Array | undefined}; export type GoogleCloudApihubV1StringAttributeValues = {values?: Array | undefined}; export type GoogleCloudApihubV1AttributeValues = {attribute?: string | undefined, enumValues?: GoogleCloudApihubV1EnumAttributeValues | undefined, jsonValues?: GoogleCloudApihubV1StringAttributeValues | undefined, stringValues?: GoogleCloudApihubV1StringAttributeValues | undefined, uriValues?: GoogleCloudApihubV1StringAttributeValues | undefined}; export type GoogleCloudApihubV1Documentation = {externalUri?: string | undefined}; export type GoogleCloudApihubV1ExternalApi = {attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, createTime?: unknown | undefined, description?: string | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, endpoints?: Array | undefined, name?: string | undefined, paths?: Array | undefined, updateTime?: unknown | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdExternalApisArgs = {projectsId: string, locationsId: string, externalApiId?: string | undefined, body: GoogleCloudApihubV1ExternalApi}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdExternalApisOptions = {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 googleCloudApihubV1EnumAttributeValues = z.object({values: z.array(googleCloudApihubV1AllowedValue).optional()}); export const googleCloudApihubV1StringAttributeValues = z.object({values: z.array(z.string()).optional()}); export const googleCloudApihubV1AttributeValues = z.object({attribute: z.string().optional(), enumValues: googleCloudApihubV1EnumAttributeValues.optional(), jsonValues: googleCloudApihubV1StringAttributeValues.optional(), stringValues: googleCloudApihubV1StringAttributeValues.optional(), uriValues: googleCloudApihubV1StringAttributeValues.optional()}); export const googleCloudApihubV1Documentation = z.object({externalUri: z.string().optional()}); export const googleCloudApihubV1ExternalApi = z.object({attributes: z.record(z.string(), googleCloudApihubV1AttributeValues).optional(), createTime: z.string().optional(), description: z.string().optional(), displayName: z.string().optional(), documentation: googleCloudApihubV1Documentation.optional(), endpoints: z.array(z.string()).optional(), name: z.string().optional(), paths: z.array(z.string()).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 an External API resource in the API hub. * * POST /v1/projects/{projectsId}/locations/{locationsId}/externalApis * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdExternalApis = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdExternalApisArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdExternalApisOptions) => { 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.externalApiId != null) query.append("externalApiId", String(args.externalApiId)) 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))}/externalApis${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(googleCloudApihubV1ExternalApi, await res.json()) };