-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix array of enums #335
Fix array of enums #335
Conversation
992fef4
to
61b9645
Compare
A property that is an array of enum values was being generated as only that enum. This change corrects that.
61b9645
to
45e9966
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments/questions
csharp/sdk/3.1/models.cs
Outdated
@@ -1735,20 +1735,15 @@ public class Integration : SdkModel | |||
/// <summary>Array of params for the integration.</summary> | |||
public IntegrationParam[]? @params { get; set; } = null; | |||
/// <summary>A list of data formats the integration supports. If unspecified, the default is all data formats. Valid values are: "txt", "csv", "inline_json", "json", "json_label", "json_detail", "json_detail_lite_stream", "xlsx", "html", "wysiwyg_pdf", "assembled_pdf", "wysiwyg_png", "csv_zip". (read-only)</summary> | |||
[JsonConverter(typeof(StringEnumConverter))] | |||
public SupportedFormats? supported_formats { get; set; } | |||
public SupportedFormats[]? supported_formats { get; set; } = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so
@@ -146,26 +146,9 @@ describe('c# generator', () => { | |||
.user_attribute_filter_types.type | |||
const actual = gen.declareType('', type) | |||
const expected = `/// An array of user attribute types that are allowed to be used in filters on this field. Valid values are: "advanced_filter_string", "advanced_filter_number", "advanced_filter_datetime", "string", "number", "datetime", "relative_url", "yesno", "zipcode". | |||
public enum UserAttributeFilterTypes | |||
public class UserAttributeFilterTypes[] : SdkModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea if this is correct - it's just what the actual
output is right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct
.toUpperCase() | ||
.replace('-', '') | ||
.replace('_', '') | ||
group.toUpperCase().replace('-', '').replace('_', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier did this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -450,7 +458,7 @@ describe('sdkModels', () => { | |||
}) | |||
|
|||
describe('enum naming', () => { | |||
const rf1: OAS.SchemaObject = { | |||
const rf: OAS.SchemaObject = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renumbered so that expect(actual1.name).toEqual('ResultFormat1')
below is easier on the brain
if (propType.instanceOf('EnumType')) { | ||
api.registerEnum(propType, propName) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? resolveType
does a registerEnum
any time it finds one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure if you take that line out enum resolution will break
constructor( | ||
public elementType: IType, | ||
schema: OAS.SchemaObject, | ||
types: TypeList, | ||
typeName?: string, | ||
methodName?: string | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lost some time because I didn't immediately see where the enum name was being switched from result_format
to ResultFormat
. I don't think this solution is totally ideal but I also don't think that setting the enum name in a function called registerEnum
is right either. If knowledge of how to set the name should not be contained inside the EnumType
class (because we need to know types
, typeName
, and methodName
which are external to the object) then perhaps a separate method named makeEnum()
that instantiates the object and then sets its name. But I still think registerEnum()
isn't the right place for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to discuss the enum naming logic. I put it in the place where the enum was added to the model because that's where it was needed. I don't know how registerEnum()
would be different than makeEnum()
, but again, let's talk about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's just how my brain works but I was reading the new EnumType(...)
as "here's the enum in all it's entirety" and my brain glanced over the registerEnum
call because I didn't think that would have a side effect on the enum object itself. So it took me a little while to figure out that it was changing the name. I didn't think I'd need to read the contents of the registerEnum
method to learn about how properties of the enum instance itself were set. I'd expect that to be found more in either the constructor or a method with a more aggressively mutating sounding name :-)
let name = titleCase(this.name || typeName || 'Enum') | ||
if (name in types) { | ||
// Enum values don't match existing enum of this name. Pick a new name | ||
const baseName = methodName ? titleCase(`${methodName}_${name}`) : name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to also scope to parentType name to try as hard as possible to avoid the ++i
appending. maybe something like
const baseName = methodName ? titleCase(`${methodName}_${name}`) : name | |
const baseName = methodName ? titleCase(`${methodName}_${name}`) : name | |
baseName = (baseName in types) ? titleCase(`${parentTypeName}_${baseName}) : baseName |
and we'd have to optionally pass parentTypeName
through the constructor into this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need time to get my head back into this space to have significant feedback :)
@@ -842,6 +842,29 @@ export enum ResultFormat { | |||
export enum Align { | |||
left = 'left', | |||
right = 'right' | |||
}`) | |||
}) | |||
it('array of enums', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for this in typescript (as well as augmenting a test in python) but I haven't touched the other language gen tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The C# enum array syntax is not correct. Need to try building this in Rider or VS Code. Would be nice to have a Look# smoke test, of course.
csharp/sdk/3.1/models.cs
Outdated
@@ -1735,20 +1735,15 @@ public class Integration : SdkModel | |||
/// <summary>Array of params for the integration.</summary> | |||
public IntegrationParam[]? @params { get; set; } = null; | |||
/// <summary>A list of data formats the integration supports. If unspecified, the default is all data formats. Valid values are: "txt", "csv", "inline_json", "json", "json_label", "json_detail", "json_detail_lite_stream", "xlsx", "html", "wysiwyg_pdf", "assembled_pdf", "wysiwyg_png", "csv_zip". (read-only)</summary> | |||
[JsonConverter(typeof(StringEnumConverter))] | |||
public SupportedFormats? supported_formats { get; set; } | |||
public SupportedFormats[]? supported_formats { get; set; } = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so
@@ -146,26 +146,9 @@ describe('c# generator', () => { | |||
.user_attribute_filter_types.type | |||
const actual = gen.declareType('', type) | |||
const expected = `/// An array of user attribute types that are allowed to be used in filters on this field. Valid values are: "advanced_filter_string", "advanced_filter_number", "advanced_filter_datetime", "string", "number", "datetime", "relative_url", "yesno", "zipcode". | |||
public enum UserAttributeFilterTypes | |||
public class UserAttributeFilterTypes[] : SdkModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct
.toUpperCase() | ||
.replace('-', '') | ||
.replace('_', '') | ||
group.toUpperCase().replace('-', '').replace('_', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
if (propType.instanceOf('EnumType')) { | ||
api.registerEnum(propType, propName) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure if you take that line out enum resolution will break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for this fix and the thorough review of enum logic.
Description *string `json:"description,omitempty"` // Description of the integration. | ||
Enabled *bool `json:"enabled,omitempty"` // Whether the integration is available to users. | ||
Params *[]IntegrationParam `json:"params,omitempty"` // Array of params for the integration. | ||
SupportedFormats *[]SupportedFormats `json:"supported_formats,omitempty"` // A list of data formats the integration supports. If unspecified, the default is all data formats. Valid values are: "txt", "csv", "inline_json", "json", "json_label", "json_detail", "json_detail_lite_stream", "xlsx", "html", "wysiwyg_pdf", "assembled_pdf", "wysiwyg_png", "csv_zip". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kppk should this be []SupportedFormatType
instead of []SupportedFormats
? if so, then there's some misconfiguration between packages/sdk-codegen/src/sdkModels.ts and packages/sdk-codegen/src/go.gen.ts
A property that is an array of enum values was being generated as only
that enum. This change corrects that.
fixes #334