question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate raw client

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

0reactions
orihomiecommented, Dec 6, 2019

Ok, that works fine, thx.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing a "raw" HTTP client in C# - Stack Overflow
I am trying to write a "raw" HTTP client in C#. You may ask why?? My aim is to implement an HTTP client...
Read more >
.NET Minimal API HTTP Client Generation - YouTube
This is a guide for how to generate an http client for your minimal api. ... Buy my Courses https://learning. raw -coding.dev Buy...
Read more >
Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >
Raw HTTP/S
Receive raw HTTP data. ... Click Generate to create a new secret. ... Validate client certs: Reject certificates that are not authorized by...
Read more >
How can I use command line telnet client to open a raw ...
Use netcat, it provides command line raw sockets, a very handy utility, I often use it to move data between servers when encryption...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found