HubSpot / hubspot-api-nodejs

HubSpot API NodeJS Client Libraries for V3 version of the API
Apache License 2.0
298 stars 97 forks source link

FilterOperatorEnum is required, but looks like it's not exported #172

Closed ptaberg closed 4 months ago

ptaberg commented 2 years ago
Screenshot 2022-03-15 at 12 02 07

Example of code:

const filter = { propertyName: 'enriched', operator: "EQ", value: 'true' }
const filterGroup = { filters: [filter] }

const detailFromHubspot = await hubspotClient.crm.companies.searchApi.doSearch({
      filterGroups: [filterGroup]
});

I could do such thing:

import { FilterOperatorEnum } from '@hubspot/api-client/lib/codegen/crm/companies/models/Filter';

But then I see 'FilterOperatorEnum' only refers to a type, but is being used as a value here.ts(2693)

That's because of export declare type FilterOperatorEnum = "EQ" | "NEQ" | "LT" | "LTE" | "GT" | "GTE" | "BETWEEN" | "IN" | "NOT_IN" | "HAS_PROPERTY" | "NOT_HAS_PROPERTY" | "CONTAINS_TOKEN" | "NOT_CONTAINS_TOKEN";

PhakornKiong commented 2 years ago

Just ran into this today as well

mlahp7 commented 2 years ago

We ran into this problem as well, but in the contacts section of the CRM class. As suggested above, asserting the EQ (or any supported operator string) as FilterOperatorEnum is a quick workaround.

Edit: We're on the latest version, 6.0.1-beta5

quick-assert-fix-hubspot

ghost commented 2 years ago

This works using 5.0 (not tried in latest release):

import * as hubspot from '@hubspot/api-client'

operator: hubspot.contactsModels.Filter.OperatorEnum.EQ
deiga commented 2 years ago

It seems that the Filter type was changed between 5.0 and 6.0

Current version:

/**
 * Companies
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * OpenAPI spec version: v3
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech/).
 * https://openapi-generator.tech/
 * Do not edit the class manually.
 */

import { HttpFile } from '../http/http';

export class Filter {
    'value'?: string;
    'values'?: Array<string>;
    'propertyName': string;
    /**
    * null
    */
    'operator': FilterOperatorEnum;

    static readonly discriminator: string | undefined = undefined;

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "value",
            "baseName": "value",
            "type": "string",
            "format": ""
        },
        {
            "name": "values",
            "baseName": "values",
            "type": "Array<string>",
            "format": ""
        },
        {
            "name": "propertyName",
            "baseName": "propertyName",
            "type": "string",
            "format": ""
        },
        {
            "name": "operator",
            "baseName": "operator",
            "type": "FilterOperatorEnum",
            "format": ""
        }    ];

    static getAttributeTypeMap() {
        return Filter.attributeTypeMap;
    }

    public constructor() {
    }
}

export type FilterOperatorEnum = "EQ" | "NEQ" | "LT" | "LTE" | "GT" | "GTE" | "BETWEEN" | "IN" | "NOT_IN" | "HAS_PROPERTY" | "NOT_HAS_PROPERTY" | "CONTAINS_TOKEN" | "NOT_CONTAINS_TOKEN" ;

and previously we had:

/**
 * Companies
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: v3
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech/).
 * https://openapi-generator.tech/
 * Do not edit the class manually.
 */

import { RequestFile } from './models';

export class Filter {
    'value'?: string;
    'propertyName': string;
    /**
    * null
    */
    'operator': Filter.OperatorEnum;

    static discriminator: string | undefined = undefined;

    static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
        {
            "name": "value",
            "baseName": "value",
            "type": "string"
        },
        {
            "name": "propertyName",
            "baseName": "propertyName",
            "type": "string"
        },
        {
            "name": "operator",
            "baseName": "operator",
            "type": "Filter.OperatorEnum"
        }    ];

    static getAttributeTypeMap() {
        return Filter.attributeTypeMap;
    }
}

export namespace Filter {
    export enum OperatorEnum {
        Eq = <any> 'EQ',
        Neq = <any> 'NEQ',
        Lt = <any> 'LT',
        Lte = <any> 'LTE',
        Gt = <any> 'GT',
        Gte = <any> 'GTE',
        Between = <any> 'BETWEEN',
        In = <any> 'IN',
        NotIn = <any> 'NOT_IN',
        HasProperty = <any> 'HAS_PROPERTY',
        NotHasProperty = <any> 'NOT_HAS_PROPERTY',
        ContainsToken = <any> 'CONTAINS_TOKEN',
        NotContainsToken = <any> 'NOT_CONTAINS_TOKEN'
    }
}

Was the change intentional? It was a lot easier to use operators, when one could reference them (like Filter.OperatorEnum.HasProperty)

ksvirkou-hubspot commented 1 year ago

Was the change intentional? It was a lot easier to use operators, when one could reference them (like Filter.OperatorEnum.HasProperty)

Hi @deiga . We changed code generator that is why this code was changed.

deiga commented 1 year ago

Was the change intentional? It was a lot easier to use operators, when one could reference them (like Filter.OperatorEnum.HasProperty)

Hi @deiga . We changed code generator that is why this code was changed.

Thanks for sharing context! Are there plans to allow access to Filters easily?

ksvirkou-hubspot commented 1 year ago

https://github.com/OpenAPITools/openapi-generator/pull/14579 https://github.com/OpenAPITools/openapi-generator/pull/14663

ksvirkou-hubspot commented 1 year ago

Hi everyone. I've created PR to OpenAPIGenerator and It has been merged already. When OpenAPIGenerator publish new major version and I have possibility to regenerate the SDK, I'll do it.

ksvirkou-hubspot commented 5 months ago

Hi everyone. I've published it in the latest version(11.0.0-beta.0).

ksvirkou-hubspot commented 4 months ago

I've published it in the latest stable version(11.0.0).