Skip to content

Commit

Permalink
Ensure string-typed header results are unquoted
Browse files Browse the repository at this point in the history
Whereas body responses of type string are double quoted because we are designing for a Content-Type of application/json (which requires the quotes to be present), string-typed header values in earlier versions of Menes have always been unquoted. (This is consistent with input handling where untyped inputs such as headers, cookies, and query string parameters do not use quotes when we want to handle the input as a string.)
  • Loading branch information
idg10 committed Jan 12, 2023
1 parent b1a6244 commit 39a6e6d
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ private void BuildHeaders(HttpResponse httpResponse, OpenApiResponse response)
convertedValue = this.ConvertValue(header.Value.Schema, value);
}

if (header.Value.Schema.Type == "string")
{
// When IOpenApiConverter produce a JSON string, they always include the surround
// double quotes, because those are necessary for the result to be valid JSON.
// But when we put string values in headers, we do not include the double quotes.
convertedValue = convertedValue[1..^1];
}

httpResponse.Headers.Add(header.Key, new Microsoft.Extensions.Primitives.StringValues(convertedValue));

if (this.logger.IsEnabled(LogLevel.Debug))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ Feature: Boolean Output Parsing
I want to be able to specify boolean values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Body with valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'boolean', and format ''
When I try to build a response body from the value '<Value>' of type 'System.Boolean'
When I try to build a response from the value '<Value>' of type 'System.Boolean'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| true | true |
| false | false |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'boolean', and format ''
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Boolean | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| true | true |
| false | false |
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ Feature: Byte Array Output Parsing
I want to be able to specify byte-formatted string values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'byte'
When I try to build a response body from the value '<Value>' of type 'ByteArrayFromBase64String'
When I try to build a response from the value '<Value>' of type 'ByteArrayFromBase64String'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| U3dhZ2dlciByb2Nrcw== | "U3dhZ2dlciByb2Nrcw==" |
| | "" |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'byte'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | ByteArrayFromBase64String | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| U3dhZ2dlciByb2Nrcw== | U3dhZ2dlciByb2Nrcw== |
| | |
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ Feature: Date Output Parsing
I want to be able to specify date values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'date'
When I try to build a response body from the value '<Value>' of type 'System.DateTimeOffset'
When I try to build a response from the value '<Value>' of type 'System.DateTimeOffset'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 2017-07-21T00:00:00Z | "2017-07-21" |

Scenario: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'date'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.DateTimeOffset | 2017-07-21T00:00:00Z |
Then the response header called 'X-Test' should be '2017-07-21'
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ Feature: DateTime Output Parsing

Scenario Outline: Valid values for simple types
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'date-time'
When I try to build a response body from the value '<Value>' of type 'System.String'
When I try to build a response from the value '<Value>' of type 'System.String'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 2017-07-21T00:00:00Z | "2017-07-21T00:00:00Z" |
| Value | ExpectedResult |
| 2017-07-21T00:00:00Z | "2017-07-21T00:00:00Z" |

Scenario: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'date-time'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.String | 2017-07-21T00:00:00Z |
Then the response header called 'X-Test' should be '2017-07-21T00:00:00Z'
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: Double Output Parsing
I want to be able to specify double values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'number', and format 'double'
When I try to build a response body from the value '<Value>' of type 'System.Double'
When I try to build a response from the value '<Value>' of type 'System.Double'
Then the response body should be '<ExpectedResult>'

Examples:
Expand All @@ -19,4 +19,21 @@ Scenario Outline: Valid values for simple types
| -1234 | -1234 |
| 1234.5 | 1234.5 |
| -1234.567 | -1234.567 |
| -1234.5678987 | -1234.5678987 |
| -1234.5678987 | -1234.5678987 |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'double'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Double | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 0 | 0 |
| 0.1 | 0.1 |
| 1234 | 1234 |
| -1234 | -1234 |
| 1234.5 | 1234.5 |
| -1234.567 | -1234.567 |
| -1234.5678987 | -1234.5678987 |
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: Float Output Parsing
I want to be able to specify float values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'number', and format 'float'
When I try to build a response body from the value '<Value>' of type 'System.Single'
When I try to build a response from the value '<Value>' of type 'System.Single'
Then the response body should be '<ExpectedResult>'

Examples:
Expand All @@ -18,4 +18,20 @@ Scenario Outline: Valid values for simple types
| 1234 | 1234 |
| -1234 | -1234 |
| 1234.5 | 1234.5 |
| -1234.567 | -1234.567 |
| -1234.567 | -1234.567 |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'float'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Single | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 0 | 0 |
| 0.1 | 0.1 |
| 1234 | 1234 |
| -1234 | -1234 |
| 1234.5 | 1234.5 |
| -1234.567 | -1234.567 |
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: Integer32 Output Parsing
I want to be able to specify integer32 values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'integer', and format ''
When I try to build a response body from the value '<Value>' of type 'System.Int32'
When I try to build a response from the value '<Value>' of type 'System.Int32'
Then the response body should be '<ExpectedResult>'

Examples:
Expand All @@ -18,3 +18,18 @@ Scenario Outline: Valid values for simple types
| -1234 | -1234 |
| 2147483647 | 2147483647 |
| -2147483648 | -2147483648 |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'integer', and format ''
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Int32 | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 0 | 0 |
| 1234 | 1234 |
| -1234 | -1234 |
| 2147483647 | 2147483647 |
| -2147483648 | -2147483648 |
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: Integer64 Output Parsing
I want to be able to specify integer64 values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'integer', and format 'int64'
When I try to build a response body from the value '<Value>' of type 'System.Int64'
When I try to build a response from the value '<Value>' of type 'System.Int64'
Then the response body should be '<ExpectedResult>'

Examples:
Expand All @@ -20,3 +20,20 @@ Scenario Outline: Valid values for simple types
| -2147483648 | -2147483648 |
| 9223372036854775807 | 9223372036854775807 |
| -9223372036854775808 | -9223372036854775808 |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'integer', and format 'int64'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Int64 | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 0 | 0 |
| 1234 | 1234 |
| -1234 | -1234 |
| 2147483647 | 2147483647 |
| -2147483648 | -2147483648 |
| 9223372036854775807 | 9223372036854775807 |
| -9223372036854775808 | -9223372036854775808 |
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: Oubject Output Parsing

Scenario: Object with properties of simple types
Given I have constructed the OpenAPI specification with a response body of type object, containing properties in the structure '{ "id": { "type": "integer" }, "name": {"type": "string"} }'
When I try to build a response body from the value '{"id":123,"name":"Ed"}' of type 'ObjectWithIdAndName'
When I try to build a response from the value '{"id":123,"name":"Ed"}' of type 'ObjectWithIdAndName'
Then the response body should be '{"id":123,"name":"Ed"}'
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ Feature: Password Output Parsing
I want to be able to specify password-formatted string values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'password'
When I try to build a response body from the value '<Value>' of type 'System.String'
When I try to build a response from the value '<Value>' of type 'System.String'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| myVErySeCurePAsSworD123 | "myVErySeCurePAsSworD123" |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'password'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.String | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| Foo | Foo |
| myVErySeCurePAsSworD123 | myVErySeCurePAsSworD123 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@perScenarioContainer

Feature: String Output Parsing
In order to implement a web API
As a developer
I want to be able to specify string values as or in response bodies or headers within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format ''
When I try to build a response from the value '<Value>' of type 'System.String'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| Foo | "Foo" |
| /1234/abc | "/1234/abc" |
| | "" |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format ''
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.String | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| Foo | Foo |
| /1234/abc | /1234/abc |
| | |
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ Feature: Uri Output Parsing
I want to be able to specify uri-formatted string values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'uri'
When I try to build a response body from the value '<Value>' of type 'System.Uri'
When I try to build a response from the value '<Value>' of type 'System.Uri'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| https://myuri.com/ | "https://myuri.com/" |
# Note: although Menes has always supported relative URIs as inputs, it does not allow them
# as outputs. It seems likely that one of these facts is a bug, but it's not currently clear
# which. We will most likely resolve this when we move over to Corvus.JsonSchema.
#| relativeuri | "relativeuri" |
| relativeuri | "relativeuri" |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'uri'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Uri | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| https://myuri.com/ | https://myuri.com/ |
| relativeuri | relativeuri |
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ Feature: Uuid Output Parsing
I want to be able to specify uuid-formatted string values as or in response bodies within the OpenAPI specification and have corresponding response bodies deserialized and validated


Scenario Outline: Valid values for simple types
Scenario Outline: Body with valid values
Given I have constructed the OpenAPI specification with a response body of type 'string', and format 'uuid'
When I try to build a response body from the value '<Value>' of type 'System.Uri'
When I try to build a response from the value '<Value>' of type 'System.Guid'
Then the response body should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 9b7d63fb-1689-4697-9571-00d10b873d78 | "9b7d63fb-1689-4697-9571-00d10b873d78" |

Scenario Outline: Header with valid values
Given I have constructed the OpenAPI specification with a response header called 'X-Test' of type 'string', and format 'uuid'
When I try to build a response from an OpenAPI result with these values
| Name | Type | Value |
| X-Test | System.Guid | <Value> |
Then the response header called 'X-Test' should be '<ExpectedResult>'

Examples:
| Value | ExpectedResult |
| 9b7d63fb-1689-4697-9571-00d10b873d78 | 9b7d63fb-1689-4697-9571-00d10b873d78 |
Loading

0 comments on commit 39a6e6d

Please sign in to comment.