googleapis / googleapis/nodejs-agentplatform
Schema type in Vertex AI Node.js SDK does not match the REST API specification
- Dominant language
- TypeScript
- Stars
- 182
- Forks
- 69
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 10
Description
#### 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!
Contributor guide
Assessment
This issue has not been assessed yet.