Skip to content

Commit

Permalink
Merge pull request #50 from MakingSense/DSL-612_quoted_profile
Browse files Browse the repository at this point in the history
DSL-612 - Quoted Profile
  • Loading branch information
gabi-cg authored Feb 1, 2022
2 parents 9b670cb + ff9ce71 commit 86e46ab
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,23 @@ public void OnResultExecuting([NotNull]ResultExecutingContext context)

if (schemaAttribute != null)
{
var keepUnquoted = context.HttpContext.Request.Query.ContainsKey("keep-unquoted-profile");

context.HttpContext.Response.OnStarting((o) =>
{
context.HttpContext.Response.ContentType += $"; profile={schemaAttribute.SchemaFilePath}";
AddProfileToContentType(context, schemaAttribute, keepUnquoted);
return Task.FromResult(0);
}, null);
}
}

private static void AddProfileToContentType(ResultExecutingContext context, SchemaAttribute schemaAttribute, bool keepUnquoted = false)
{
var profile = keepUnquoted ? schemaAttribute.SchemaFilePath
: $"\"{schemaAttribute.SchemaFilePath?.Replace("\"", "\\\"")}\"";
context.HttpContext.Response.ContentType += $"; profile={profile}";
}

private SchemaAttribute GetSchemaAttributeFromOutputModel()
{
var attr = OutputModel?.GetSchemaAttribute();
Expand Down

0 comments on commit 86e46ab

Please sign in to comment.