Allow swagger.extra to be a string literal (#121)

* Allow swagger.extra to be a string literal

This makes complex scenarios possible where the extra data
needs to contain handlebars template markup which is incompatible
with a yaml file section

* Adding unit test for extra literal string
This commit is contained in:
Louis DeJardin 2019-03-26 16:35:23 -07:00 коммит произвёл GitHub
Родитель 15ceb581f1
Коммит 73effb59aa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 72 добавлений и 1 удалений

Просмотреть файл

@ -82,7 +82,14 @@ namespace Microsoft.Atlas.CommandLine.Swagger
if (context.SwaggerReference.extra != null)
{
writer.WriteLine(_yamlSerializers.YamlSerializer.Serialize(context.SwaggerReference.extra));
if (context.SwaggerReference.extra is string extraString)
{
writer.WriteLine(extraString);
}
else
{
writer.WriteLine(_yamlSerializers.YamlSerializer.Serialize(context.SwaggerReference.extra));
}
}
var bodyParameter = parameters.SingleOrDefault(parameter => parameter.@in == "body");

Просмотреть файл

@ -388,6 +388,70 @@ Responses:
stubHttpClients.AssertRequest("GET", "https://example.com/path");
}
[TestMethod]
public async Task ExtraCanBeStringLiteral()
{
var stubHttpClients = Yaml<StubHttpClientHandlerFactory>(@"
Responses:
https://example.net/the-test/readme.md:
GET:
status: 200
body: |
``` yaml
info:
title: TheTest
swagger:
foo:
target: apis/tests
source: https://example.org/specs/
inputs:
- testing/swagger.json
extra: |
headers:
x-sum: {{{ query ""sum([`2`, `5`])"" }}}
```
https://example.net/the-test/workflow.yaml:
GET:
status: 200
body:
operations:
- request: apis/tests/TestingClient/One/Two.yaml
https://example.org/specs/testing/swagger.json:
GET:
status: 200
body:
swagger: 2.0
info:
title: Testing Client
version: 5.0-preview.2
host: example.com
paths:
/path:
get:
tags:
- One
operationId: One_Two
https://example.com/path:
GET:
status: 200
body:
- request has arrived
");
InitializeServices(stubHttpClients);
var result = Services.App.Execute("deploy", "https://example.net/the-test");
System.Console.Error.WriteLine(Console.ErrorStringWriter.ToString());
System.Console.Out.WriteLine(Console.OutStringWriter.ToString());
Assert.AreEqual(0, result);
var request = stubHttpClients.AssertRequest("GET", "https://example.com/path");
var xSumValue = request.Headers.GetValues("x-sum").Single();
Assert.AreEqual("7", xSumValue);
}
public class ServiceContext : ServiceContextBase
{
public CommandLineApplicationServices App { get; set; }