abujehad139 / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Support Enum fields on the scheme types #290

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There are few resources\requests that support enum on discovery.
"type" is set to string while the resource also has "enum" property which 
mentioned the right enum values (see an example below).

The dotnet client library should consider to create an enum property in those 
cases. 
The java library doesn't support enum, because changing enums will break the 
code and also java implementation of enums is complicated. 
in that case, the java library prefer to have a runtime error and not a compile 
time error.

- The dotnet client library should consider to change the string property to 
enum, and create a new enum.
- another option is to create a another property, which directs to the same 
field. in that case there will be two options to set the field

an exmple of enum in the discoery doc:

https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest

"minAccessRole": {
       "type": "string",
       "description": "The minimum access role for the user in the returned entires. Optional. The default is no restriction.",
       "enum": [
        "freeBusyReader",
        "owner",
        "reader",
        "writer"
       ],
       "enumDescriptions": [
        "The user can read free/busy information.",
        "The user can read and modify events and access control lists.",
        "The user can read events that are not private.",
        "The user can read and modify events."
       ],
       "location": "query"
      },

Original issue reported on code.google.com by pele...@google.com on 11 Feb 2013 at 5:59

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 11 Feb 2013 at 5:59

GoogleCodeExporter commented 9 years ago
Two issues to consider:

1. It may be a good idea to also provide a string input option in case a 
developer wants to specify a string for convenience, or because they are using 
an older-built version of the library that doesn't list a new enum value even 
though the server already supports it.

2. There is an issue that the generated enum value constants might look bad.  
For example FREEBUSYREADER is hard to read.  For that case, you may want to 
insert "_" along the capitalization border, i.e. FREE_BUSY_READER.  
Occasionally though the enum value may not be a legal name (e.g. numeric value 
of "1") or may produce a really ugly name (e.g. URI value of 
"http://somedomain.com/some/long/path").  So there are edge cases to worry 
about here.

Original comment by yan...@google.com on 11 Feb 2013 at 6:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
1. that's what I meant. So to be more clear, here is a sample code (based on 
the discovery above:

- Keep the old way (to suppport older built versions). 
As you can see the field reminds string.

private string _minAccessRole;
public string MinAccessRole
{
  get { return _minAccessRole; }
  set { this._minAccessRole = value; }
}

IN ADDITION:

// generate enum:

///<summary>The minimum access role for the user in the returned entires. 
Optional. The default is no restriction.</summary>
public enum MinAccessRole
{
  ///<summary>The user can read free/busy information</summary>
  FreeBusyReader,
  ///<summary>The user can read and modify events and access control lists</summary>
  Owner,
  ///<summary>The user can read events that are not private</summary>
  Reader,
  ///<summary>The user can read and modify events</summary>
  Writer,
}

And add another property similar to this:

public MinAccessRole MinAccessRoleEnum
{
  get { return (MinAccessRole) Enum.Parse(typeof(MinAccessRole), _minAccessRole); }
  set { this._minAccessRole = value.ToString(); }
}

NOTICE: we should also consider to add None value to the enum, so in case of 
the Enum getter above we will return MinAccessRole.None in case _minAccessRole 
is null

2. C# standards of enums is Pascal case as you can see above. 
And of course we should check that the generated enum and its values are valid 
(as we do to all properties, classes, etc.)

Original comment by pele...@google.com on 11 Feb 2013 at 7:36

GoogleCodeExporter commented 9 years ago
Issue 384 has been merged into this issue.

Original comment by pele...@google.com on 6 Sep 2013 at 7:24

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 28 Nov 2013 at 6:01

GoogleCodeExporter commented 9 years ago
Issue 384 has been merged into this issue.

Original comment by pele...@google.com on 4 Dec 2013 at 9:53