-
Notifications
You must be signed in to change notification settings - Fork 59
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
Percent encoding #205
base: master
Are you sure you want to change the base?
Percent encoding #205
Conversation
There is a test finding |
It seems like the test is finding it in a URI, which should be escaped. Am I wrong? |
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.
You may be right about the test case, but I'm not sure any more what you're trying to accomplish. I've left some comments, but I'll also look into the code a bit more soon.
@@ -344,3 +349,55 @@ sopSwaggerGenericToEncoding'' (SwaggerAesonOptions prefix _ sub) = go | |||
where (x, y) = span isUpper s | |||
|
|||
#endif | |||
|
|||
percentEncodeS :: String -> 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 would use urlEncode.
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.
Looking through the source code, it doesn't escape all reserved characters: source.
It doesn't escape the sub-delims
set of characters from RFC 3986, which isn't strictly necessary and is scheme-specific.
I think the desired behaviour is for mainstream tools (like https://editor.swagger.io) to accept all output as valid.
@@ -1150,10 +1153,11 @@ instance ToJSON SecurityDefinitions where | |||
toJSON (SecurityDefinitions sd) = toJSON sd | |||
|
|||
instance ToJSON Reference where | |||
toJSON (Reference ref) = object [ "$ref" .= ref ] | |||
toJSON (Reference ref) = object [ "$ref" .= percentEncodeT ref ] |
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 seems to me the wrong place to do this. The text inside the Reference
should really be a type that can only be turned into a string by encoding it; the fact that the string is also encoded if it appears inside a json object is coincidental.
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 not sure I understand what you are trying to say.
Reference
references some other type, as you have alluded to.
IMO the Haskell data type should contain the literate string, which is the name of the referenced type.
So, if the type referenced is User'
, then the literal string contained in the Reference
should be "User'"
. However, swagger requires all URIs (references) to be a proper URI, which requires special characters (such as '
) to be escaped with percent-encoding. So, percent-encoding really is just the way the Reference
type is converted to swagger.
And, as far as I understand it, in the scope of this library, ToJSON
instances on swagger-related datatypes should produce a valid swagger description.
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 will fix the tests (if that will be necessary), once we come to a common understanding.
Thanks, btw! :) |
BTW, the way I found out about the need to percent-encode is by importing a generated swagger file, containing a type with a |
closes #204