googleapis / google-api-php-client-services

http://googleapis.github.io/google-api-php-client-services/
Apache License 2.0
1.23k stars 316 forks source link

TransitType enum not generated #4591

Open razvanphp opened 9 months ago

razvanphp commented 9 months ago

There ~might be~ are other missing enums, but this one stood out to me: https://developers.google.com/wallet/reference/rest/v1/transitclass#TransitClass.TransitType

Since I'm the maintainer of eymengunay/php-passbook project and we will have this repo as dependancy, I would love to contribute this here for the whole community.

<?php

namespace Google\Service\Walletobjects;

/**
 * Enum for Transit Types.
 */
enum TransitType: string
{
    case TRANSIT_TYPE_UNSPECIFIED = 'TRANSIT_TYPE_UNSPECIFIED';

    case BUS = 'BUS';

    /**
     * @deprecated Legacy alias for BUS. Deprecated.
     */
    case bus = 'BUS';

    case RAIL = 'RAIL';

    /**
     * @deprecated Legacy alias for RAIL. Deprecated.
     */
    case rail = 'RAIL';

    case TRAM = 'TRAM';

    /**
     * @deprecated Legacy alias for TRAM. Deprecated.
     */
    case tram = 'TRAM';

    case FERRY = 'FERRY';

    /**
     * @deprecated Legacy alias for FERRY. Deprecated.
     */
    case ferry = 'FERRY';

    case OTHER = 'OTHER';

    /**
     * @deprecated Legacy alias for OTHER. Deprecated.
     */
    case other = 'OTHER';
}

LE: enum data type was introduced in version 8.1, so we should probably stick with class constants for now to support 7.4

But... not sure how to do it through the generator.... can I get some guidance at least? Maybe I could try it.

Also, on a more general note, it would be awesome to include those types as return types and parameter types as many other issues suggested, now that PHP 7.4 is the minimum supported version.

Thank you!

CC @bshaffer

razvanphp commented 9 months ago

It can be seen here and here:

       "transitType": {
          "enum": [
            "TRANSIT_TYPE_UNSPECIFIED",
            "BUS",
            "bus",
            "RAIL",
            "rail",
            "TRAM",
            "tram",
            "FERRY",
            "ferry",
            "OTHER",
            "other"
          ],
          "description": "Required. The type of transit this class represents, such as \"bus\".",
          "enumDeprecated": [
            false,
            false,
            true,
            false,
            true,
            false,
            true,
            false,
            true,
            false,
            true
          ],
          "type": "string",
          "enumDescriptions": [
            "",
            "",
            "Legacy alias for `BUS`. Deprecated.",
            "",
            "Legacy alias for `RAIL`. Deprecated.",
            "",
            "Legacy alias for `TRAM`. Deprecated.",
            "",
            "Legacy alias for `FERRY`. Deprecated.",
            "",
            "Legacy alias for `OTHER`. Deprecated."
          ]
        },

... but none of the enums get generated.

We should also add the text descriptions as DocBlocks, would be immensely helpful for anybody using this SDK.

bshaffer commented 5 months ago

Hello @razvanphp

You're correct in identifying that this library does not generate enums.

This was a feature request in https://github.com/googleapis/google-api-php-client-services/pull/563, but since this library is essentially in maintenance mode, we made the decision to not merge it.

razvanphp commented 5 months ago

hey @bshaffer

While I understand this lib is pretty much outdated, the wallterobjects objects were added rather recently, but we cannot add those constants only for this because of the generators.

Isn't there a better way to do this without creating so many files, maybe using phpdoc types at least, so IDEs can alert? This can be done in the same files probably, but I'm not familiar with how the generator works to do it myself.

The use-case is obvious, makes no sense to define those in my lib, while depending on those classes anyway, everybody should use types in 2024, even in PHP 🙂

bshaffer commented 5 months ago

Hi @razvanphp , these are just strings, so extra classes or typing is not necessary. I do think adding these values to phpdoc is something we should look into.

Edit: it seems like there are a lot of options for this, and we should implement one of them.