Blog: 2017 November

Advanced Newtonsoft.Json: Dynamically rename or ignore properties without changing the serialized class

November 2, 2017, Software Development

This article describes how to implement a custom contract resolver, so that you can ignore or rename serialized JSON properties where the serialization happens and without changing the serialized classes. I use this resolver in my project NSwag, a Swagger/Open API toolchain: A Swagger specification uses JSON Schemas to describe types, but it is not exactly the same model – some properties of a schema are not allowed and some must be renamed. Because I cannot change the JSON Schema implementation, I had to ignore or rename properties in the Swagger serializer. Another use case of this contract resolver is, […] Read more...

Tags: , , ,

NSwag Tutorial: Implement a custom operation processor to define ReDoc code samples

November 1, 2017, (updated on November 2, 2017), Software Development

With NSwag you can implement custom operation processors and apply them to ASP.NET Core MVC or Web API controller operations. These processors then get picked up by NSwag and are applied to the given operation in the Swagger specification. This article shows how to implement a custom operation processor using the example of adding code samples to the ReDoc UI. The ReDoc UI processes the x-code-samples property on operations. Here is a sample Swagger specification: { ... "paths": { "/person": { "post": { "summary": "Adds a new person.", "operationId": "addPerson", "x-code-samples": { "lang": "CSharp", "source": "console.log('Hello World');" } ... } […] Read more...

Tags: , , , ,


  Page 1 of 1