This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: upgrade openapi-generator to v7.1.0 #172
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctreatma
commented
Nov 13, 2023
Comment on lines
+290
to
+312
// This validates that all required properties are included in the JSON object | ||
// by unmarshalling the object into a generic map with string keys and checking | ||
// that every required field exists as a key in the generic map. | ||
requiredProperties := []string{ | ||
"address", | ||
"country", | ||
"zip_code", | ||
} | ||
|
||
allProperties := make(map[string]interface{}) | ||
|
||
err = json.Unmarshal(bytes, &allProperties) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, requiredProperty := range requiredProperties { | ||
if _, exists := allProperties[requiredProperty]; !exists { | ||
return fmt.Errorf("no value given for required property %v", requiredProperty) | ||
} | ||
} | ||
|
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 an example of the required property validation that is added in v7.1.0. Models with required properties are updated to check that the required property names appear in the JSON object that is being unmarshalled.
ctreatma
commented
Nov 13, 2023
@@ -207,14 +207,14 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class | |||
if reflect.TypeOf(t).Kind() == reflect.Slice { | |||
s := reflect.ValueOf(t) | |||
for i := 0; i < s.Len(); i++ { | |||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i).Interface(), "{{collectionFormat}}") | |||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{{baseName}}}", s.Index(i).Interface(), "{{collectionFormat}}") |
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 an upstream change to use the unescaped value of baseName
(see https://mustache.github.io/mustache.5.html#Variables for the difference between {{
and {{{
).
displague
approved these changes
Nov 14, 2023
This PR is included in version 0.27.0 🎉 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Upgrading the generator to v7.1.0 brings in required field validation, which will enable the SDK to determine the schema of an object in an API response based on the presence or absence of required fields. In addition, v7.1.0 has enum validation built in, so we no longer need a custom template to implement that.
In order to generate valid code I had to remove some new
defaultValue
code fromapi.mustache
, since that template code does not correctly handle array properties.