googleapis / googleapis/nodejs-agentplatform

Schema type in Vertex AI Node.js SDK does not match the REST API specification

Aperta
#533 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
api: aiplatform priority: p2 type: bug
Lingua principale
TypeScript
Stelle
182
Fork
69
Merge medio
1g 8h
PR unite (30g)
10

Descrizione

#### Environment details

- Programming language: TypeScript
- OS: Any
- Language runtime version: Node.js 18+
- Package version: ^1.10.0

---

#### Steps to reproduce

1. Import and use the `Schema` interface from `@google-cloud/vertexai`.
2. Attempt to define schema fields like `additionalProperties`, `minProperties`, `maxProperties`, `anyOf`, etc., which are supported by the [Vertex AI REST API schema specification](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.cachedContents#Schema) but are not present in the TypeScript interface provided by the SDK.
3. Observe that TypeScript raises type errors even though the API accepts those fields at runtime.

---

#### Suggested Fix

Please update the `Schema` type definition in the SDK to match the actual REST API capabilities. Below is a more accurate version of the `types/common.ts` interface:

```ts
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** This file contains interfaces that are usable in the types folder. */
/**
* The list of OpenAPI data types
* as defined by https://swagger.io/docs/specification/data-models/data-types/
*/
export enum SchemaType {
/** String type. */
STRING = "STRING",
/** Number type. */
NUMBER = "NUMBER",
/** Integer type. */
INTEGER = "INTEGER",
/** Boolean type. */
BOOLEAN = "BOOLEAN",
/** Array type. */
ARRAY = "ARRAY",
/** Object type. */
OBJECT = "OBJECT"
}

// Helper type to map SchemaType to its corresponding value type
type SchemaValueByType =
T extends SchemaType.STRING ? string :
T extends SchemaType.NUMBER ? number :
T extends SchemaType.INTEGER ? number :
T extends SchemaType.BOOLEAN ? boolean :
T extends SchemaType.ARRAY ? unknown[] :
T extends SchemaType.OBJECT ? Record :
unknown;

/**
* Schema is used to define the format of input/output data.
* Represents a select subset of an OpenAPI 3.0 schema object.
* More fields may be added in the future as needed.
*/
export type Schema = {
type?: T;
format?: string;
title?: string;
description?: string;
nullable?: boolean;
default?: SchemaValueByType; // ahora depende del tipo
example?: SchemaValueByType; // también depende del tipo
items?: Schema;
minItems?: string;
maxItems?: string;
enum?: string[];
properties?: {
[key: string]: Schema;
};
propertyOrdering?: string[];
required?: string[];
minProperties?: string;
maxProperties?: string;
minimum?: number;
maximum?: number;
minLength?: string;
maxLength?: string;
pattern?: string;
anyOf?: Schema[];
additionalProperties?: boolean | Schema;
ref?: string;
defs?: {
[key: string]: Schema;
};
};
```

This change would allow developers to use the client library in type-safe ways that are aligned with the official Vertex AI schema documentation and API behavior.

Thanks!

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in types/common.ts, where the Vertex AI Node.js SDK's Schema interface is defined, and compare it with the linked Vertex AI REST API Schema specification. Check the reported fields, including additionalProperties, minProperties, maxProperties, and anyOf, then verify that TypeScript accepts supported schema definitions without errors.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.