How to expose yaml endpoint in NSwag? - yaml

I need to expose the schema definition of API (.net core 2.2) in Yaml not JSON. I'm using NSwag. I found package NSwag.Core.Yaml https://www.nuget.org/packages/NSwag.Core.Yaml/
But I have no idea how I should use it. In Shwasbuckle things are pretty straightforward. Everything you have to do is change the extension to yaml, like this:
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.yaml", "My API V1");
});
What should I do using NSwag?

Will be supported in next NSwag version:
https://github.com/RicoSuter/NSwag/issues/2331

Related

How to register a UsePublishFilter while using Bus.Factory.CreateUsingRabbitMq on a .net 4.7.2 project

I am trying to add a custom filter to the publish-action on the publishing side. However, to register a custom filter, I need to pass an instance of IConfigurationServiceProvider.
When using asp.net core, this would not be a problem as there are many examples around. That is unfortionately not the case for an application using the "full" .net 4.7.2
Here is some samplecode to further illustrate what I am trying to do:
var busControl = Bus.Factory.CreateUsingRabbitMq(config =>
{
config.Host(RabbitMqHostUrl, h =>
{
h.Username(RabbitMqUsername);
h.Password(RabbitMqPassword);
});
config.UsePublishFilter(typeof(MyCustomFilter<>), Instance_of_IConfigurationServiceProvider);
});
Scoped Filters only work with Microsoft.Extensions.DependencyInjection or Autofac, and require the use of the currently supported container-based configuration syntax.

How to upload with ExpediaGroup's graphql-kotlin?

There's nothing related to file upload in the examples under https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/server/spring-server/src/main/kotlin/com/expediagroup/graphql/examples/server/spring.
I'd like to upload 5 files at once and although I think it should be a mutation I'm not sure whether it should go like this:
class UploadMutation: Mutation {
fun upload(files: FilePart) {
print("$files")
}
}
The context is obviously Spring Boot with Kotlin and WebFlux.
According to the developers they don't support Apollo-like file uploads at all.
File uploads can be built using our library and spring boot, but they are not included out of the box. You will have to configure the response parser yourself
https://github.com/ExpediaGroup/graphql-kotlin/discussions/1037

How to specify mapping templates in AWS SAM

I have an AWS lambda that acts on an events of the form:
{"id": "some-id", "stuff": "bla-bla-stuff-here" }
Now I want to attach an API Gateway endpoint with POSTs to an url of the form /stuff/{id} where the actual stuff would go in the body. So, on the integration request of the method there is a mapping template section which seems to allow for something like:
{
"id": $input.params('id'),
"stuff": $input.body
}
Now, how do I specify this template in the SAM file?
SAM uses the Proxy integration to Lambda which I don't think works with request/response mapping. If it does, you would need to specify this in Swagger as the DefinitionBody property of the Serverless::Api as SAM doesn't currently have a property for adding Request/Response mapping and generating the Swagger for you. The easiest way to use Swagger is to inspect the generated CloudFormation template of your stack; copy-paste it into your SAM template under DefinitionBody; and then apply the necessary Swagger additions.

Swagger 2.0 offline validation

I know that there's a tool that is able to do an online validation:
http://online.swagger.io/validator?url=http://petstore.swagger.io/v2/swagger.json
I'm writing a JUnit test that validates the project's swagger.json file. It's important that this validation can be done offline, because the test runs as localhost, and that validation tool can't reach a localhost server.
So, is it possible to validate a Swagger 2.0 JSON file, offline?
I'm very satisfied with this Validator from Atlassian: https://bitbucket.org/atlassian/swagger-request-validator
There is still active development, so I guess they will also provide something for OpenAPI 3.
I have created a Maven project that validates swagger JSON documents if you ever decide to use Maven for running your tests.
You can clone the project here: https://github.com/navidsh/maven.swagger.validator
Well, I finished a Swagger validator using fge/json-schema-validator and Jackson. It uses the Swagger 2.0 schema to validate.
https://gist.github.com/mariosotil/e1219d4e946c643fe0e5
#Singleton
public class SwaggerValidator {
public ArrayNode validate(JsonNode jsonNode) {
return Optional.of(jsonNode)
.map(this::validateWithinSwaggerSchema)
.map(this::getMessagesAsJsonArray)
.get();
}
// [...]
}

How to use protobuf interface in C#

I write a .proto file, and it include a service:
service ServerService {
rpc HelloServer (Word) returns (Void);
}
Then, I use protobuf-net generate .cs file:
public interface IServerService
{
gt.Void HelloServer(gt.example.Word request);
}
But I do not know how to use it. Is there any doc?
A new standard, gRPC, is picking up steam and has support in .net core.
Check out this tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.1&tabs=visual-studio
The tutorial also links out to other information on gRPC in .NET. The docs are pretty good.

Resources