-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support x-enum-varnames extension
#692
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
Changes from all commits
7e08bd0
96cf8b0
a8f8e44
c136a96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -401,8 +401,21 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) { | |
| for i, enumValue := range schema.Enum { | ||
| enumValues[i] = fmt.Sprintf("%v", enumValue) | ||
| } | ||
| if 0 < len(schema.ExtensionProps.Extensions) { | ||
| //fmt.Fprintf(os.Stderr, "%#v\n\n", schema) | ||
| } | ||
|
|
||
| enumNames := enumValues | ||
| for _, key := range []string{extEnumVarNames, extEnumNames} { | ||
| if _, ok := schema.ExtensionProps.Extensions[key]; ok { | ||
| if extEnumNames, err := extParseEnumVarNames(schema.ExtensionProps.Extensions[key]); err == nil { | ||
| enumNames = extEnumNames | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, your extension completely replaces the enum names that are autogenerated. What happens when the provided names array has a different length than possible enum values? I think we'll end up creating invalid enums. Can you, at a minimum, error out on cardinality mismatch? |
||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| sanitizedValues := SanitizeEnumNames(enumValues) | ||
| sanitizedValues := SanitizeEnumNames(enumNames, enumValues) | ||
| outSchema.EnumValues = make(map[string]string, len(sanitizedValues)) | ||
|
|
||
| for k, v := range sanitizedValues { | ||
|
|
||
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.
Remove old debugging?