Skip to content
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

Various fixes, enhancements to csharp-refactor client #1711

Merged
merged 1 commit into from
Dec 20, 2018
Merged

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Dec 19, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • update dependencies to the latest version
  • bug fixes to content-type, accept header selection
  • add test cases

NOTE: file upload is still broken and will be addressed in another PR instead.

cc @mandrean (2017/08) @jimschubert (2017/09)

ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to create an issue to support naming strategy here.

public static bool IsJsonMime(String mime)
{
var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be optimized by returning earlier using String.IsNullOrWhitespace(mime) before unnecessarily constructing the regex object… could also cache the regex object as a static variable to reduce its effect on heap:

public static Regex jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

public static bool IsJsonMime(String mime)
{
    if (String.IsNullOrWhiteSpace(mime)) return false;
    return jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
}


foreach (var contentType in contentTypes)
{
if (IsJsonMime(contentType.ToLower()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be incorrect… this would return true for APPLICATION/JSON; CHARSET=UTF-8, then apply that as a header when it's not going to be a useful or relevant header. Although HTTP spec defines header names (e.g. 'Content-Type') as case insensitive, the values are case sensitive.

@wing328
Copy link
Member Author

wing328 commented Dec 20, 2018

@jimschubert thanks for the feedback. As discussed we'll address that in follow-up PRs

@wing328 wing328 merged commit 93c1307 into master Dec 20, 2018
@wing328 wing328 deleted the fix_csharp branch December 20, 2018 08:06
@jimschubert
Copy link
Member

@wing328 I opened #1723. I didn't see a clean solution to the serialization strategy, so I'll revisit that one later.

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants