Generate raw client
See original GitHub issueIs that possible to generate raw client which just sends requests on URI taken from swagger spec and returns HttpResponseMessages (base HttpClient objects) without any additional logic?
UPD
I’ll try to explain. I’ve got some service which has swagger, there are some endpoints and each one must give you response in a it’s own formats, and I need to write some tests checking whenever format was changed or not, this can help in a way:
- developer can spot his broken changes early, before something starts to crash, and can even find error faster if error is about scheme (not BL)
- set up to cross-command chat this can be as a notification what some command changed their response, so others can faster fix their integrations,
I was tryin to make this in such a way as I was just manually writing each endpoint, like
internal void ValidateJsonSchema(HttpResponseMessage message, string schemaFileName, bool resaveSchema = false)
{
var result = message.Content.ReadAsStringAsync().Result;
var schemaPath = Path.Combine(schemaFileName);
if (resaveSchema)
{
File.WriteAllText(schemaFileName, NJsonSchema.JsonSchema.FromSampleJson(result).ToJson());
}
var schema = NJsonSchema.JsonSchema.FromFileAsync(schemaPath).Result;
new JsonSchemaValidator().Validate(result, schema).Count.ShouldBe(0);
}
...
[Fact]
public async Task GetQueryCheckSchema()
{
var response = await myClient.clientSegment1.GetQuery(1);
response.StatusCode.ShouldBe(HttpStatusCode.OK);
var jsonSchemaFileName = "../../../Schemes/queries_id.json";
ValidateJsonSchema(response, jsonSchemaFileName, false);
}
This how it works: first time you dont have serialized shema, so you call ValidateJsonSchema(…, …, true) - it will generate it, and then you set it to false and you’re able to check if schema changed.
And now I can come back to this topic: that’s why if this tool generates Dto’s for responses and even checking where response’s StatusCode - how I can configure this in a way it would check JsonSchema? Dto’s themselves is not bad, but this statuscode check makes me feel uncomfortable.
** UPD 2 ** Ok, I’ve digged a bit into code and found that template for C# client, changed (hardcoded) a bit Client.Class.liquid and that didnt worked, can someone please help with that? p.s. my change: https://github.com/orihomie/NSwag/commit/f83c79aac2b71520c6923c3a352415b8ba587518
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
https://github.com/RicoSuter/NSwag/wiki/Templates
Ok, that works fine, thx.