-
-
Notifications
You must be signed in to change notification settings - Fork 559
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
Add ability to set JSON encoded Swagger extension values #788
Conversation
@tchssk fyi, you can now encode values in JSON in the Metadata field for Swagger extensions. |
Great! Thank you for telling me. @raphael |
I read the document of Swagger Extensions again.
If it means
maybe we should have picked up only valid values as JSON and simply stored them as func extensionsFromDefinition(mdata dslengine.MetadataDefinition) map[string]string {
extensions := make(map[string]string)
for key, value := range mdata {
chunks := strings.Split(key, ":")
if len(chunks) != 3 {
continue
}
if chunks[0] != "swagger" || chunks[1] != "extension" {
continue
}
if strings.HasPrefix(chunks[2], "x-") != true {
continue
}
// Validate value.
var unmarshaled interface{}
if err := json.Unmarshal(value[0], &unmarshaled); err != nil {
// Skip if invalid.
continue
}
// Set if valid.
extensions[chunks[2]] = value[0]
}
if len(extensions) == 0 {
return nil
}
return extensions
} How do you think? @raphael |
Hmm yes that's a good point. It's going to be less practical for strings though as you'd have to double escape them. I could see people getting bitten by this. Maybe we could keep doing what the algorithm does today and if json unmarshal fails then fall back to using the value directly. It's not great from a performance point of view but this is code generation so it's fine :) |
I almost understood. |
Yeah my response wasn't super clear now that I re-read it :) What I mean to say is that like you suggest we should remove the
I don't have to do:
But that would work too. |
Oh I understand. And I was planned to undo each |
cool! yeah I think the |
OK. I'll send a new pull request. |
No description provided.