Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

vertex-spec.test.ts

75 lines2.5 KB

1import { describe, expect, it } from 'vitest'
2​
3import type { DiscoveryDoc } from './gemini.ts'
4import { publisherModelDiscovery, vertexOpenApi } from './vertex-spec.ts'
5​
6const DOC = {
7 title: 'Agent Platform API',
8 version: 'v1',
9 rootUrl: 'https://aiplatform.googleapis.com/',
10 schemas: {
11 Request: {
12 type: 'object',
13 properties: { contents: { $ref: 'Content' } },
14 },
15 Content: { type: 'object' },
16 Unused: { type: 'object' },
17 },
18 resources: {
19 projects: {
20 resources: {
21 locations: {
22 resources: {
23 publishers: {
24 resources: {
25 models: {
26 methods: {
27 generateContent: {
28 id: 'aiplatform.projects.locations.publishers.models.generateContent',
29 flatPath:
30 'v1/projects/{projectsId}/locations/{locationsId}/publishers/{publishersId}/models/{modelsId}:generateContent',
31 httpMethod: 'POST',
32 request: { $ref: 'Request' },
33 response: { $ref: 'Content' },
34 },
35 generateContentAlias: {
36 id: 'aiplatform.publishers.models.generateContent',
37 flatPath:
38 'v1/publishers/{publishersId}/models/{modelsId}:generateContent',
39 httpMethod: 'POST',
40 request: { $ref: 'Request' },
41 },
42 },
43 },
44 },
45 },
46 endpoints: {
47 methods: {
48 generateContent: {
49 id: 'aiplatform.projects.locations.endpoints.generateContent',
50 flatPath:
51 'v1/projects/{projectsId}/locations/{locationsId}/endpoints/{endpointsId}:generateContent',
52 httpMethod: 'POST',
53 },
54 },
55 },
56 },
57 },
58 },
59 },
60 },
61} as DiscoveryDoc
62​
63describe('publisherModelDiscovery', () => {
64 it('keeps publisher generateContent and the schemas it references', () => {
65 const spec = vertexOpenApi(DOC)
66 const paths = Object.keys(spec.paths ?? {})
67 expect(paths).toEqual([
68 '/v1/projects/{projectsId}/locations/{locationsId}/publishers/{publishersId}/models/{modelsId}:generateContent',
69 ])
70 const schemas = spec.components?.schemas ?? {}
71 expect(Object.keys(schemas).sort()).toEqual(['Content', 'Request'])
72 const pruned = publisherModelDiscovery(DOC)
73 expect(pruned.schemas?.Unused).toBeUndefined()
74 })
75})