How to use Swagger in non-trivial Wildfly Swarm project? - swagger

In a very simple Wildfly Swarm project Swagger works fine and produces the expected swagger.json output. But as soon as a second java package is added to the project, it doesn't work anymore.
Example (see https://github.com/pe-st/swagger42 example project):
the first commit consists of the project as generated by http://wildfly-swarm.io/ (containing one class HelloWorldEndpoint in the package ch.schlau.pesche.swagger42.rest)
the second commits adds minimal Swagger annotations and generates the following swagger.json :
{
"swagger": "2.0",
"info": {},
"basePath": "/",
"paths": {
"/hello": {
"get": {
"summary": "Get the response",
"description": "",
"operationId": "doGet",
"produces": [
"text/plain"
],
"parameters": [],
"responses": {
"default": {
"description": "successful operation"
}
}
}
}
}
}
the third commit adds an empty class in a second java package ch.schlau.pesche.swagger42.core. Now the generated swagger.json looks like this:
{"swagger":"2.0","info":{},"basePath":"/"}
What has to be done to make Swagger work in projects like these?

https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/advanced/swagger.html
Create a file META-INF/swarm.swagger.conf
and add following entry:
packages:ch.schlau.pesche.swagger42.rest
There is a info in the startup:
[org.wildfly.swarm.swagger] (main) WFSSWGR0004: Configure Swagger for deployment
demo.war with package ch.schlau.pesche.swagger42.core
or similar, which packages is scanned.

Related

How do you configure Destructurama.Attributes .Destructure.UsingAttribues() in JSON from appsettings?

We use appsettings to configure Serilog via JSON, a fairly standard enterprise practice.
But I'm having trouble enabling the UsingAttributes. How does one enable .Destructure.UsingAttributes via JSON config?
I started with a pure Serliog approach, but they indicate that Serilog.Extras.Attributed is deprecated in favor of using Destructurama.Attributed. And in looking at the Destructurama.Attributed github example, I don't understand how to convert that into a JSON configuration. Their example:
var log = new LoggerConfiguration().Destructure.UsingAttributes()
The Serilog documentation for the "Destructure" option is straightforward:
"Destructure": [
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
},
],
However, I don't know what I would use for the "Sample.CustomPolicy, Sample" to get Destructurama to be enabled.
"Destructure": [
{
"Name": "With",
"Args": { "UsingAttributes": WHAT_GOES_HERE}
},
],
I feel like I'm missing something obvious.
I just encountered the same problem and after a few experiments I figured how to have it working using Destructurama.Attributed version 2.0.0 :
You must specify the following using in JSON configuration to make Serilog able to see the library :
"Serilog":
{
"Using":
[
"Destructurama.Attributed"
],
....
}
Inside Serilog configuration, you have to specify this to Destructure to enable the attributes :
"Destructure":
[
{
"Name": "UsingAttributes"
},
....
]

Ocelot swagger redirection issue

I am trying to implement Ocelot/Swagger/MMLib and .net microservices on my Windows 2019 server.
Everything is working fine, I can call each of the microservices correctly through the API gateway using postman, but I would like to display the swagger documentation as the API is going to be used by a third party.
If I use the ip address/port number I get the correct page displayed, with my microservice definitions. However if I reroute this to a physical url (eg https://siteaddress.com/path/swagger.index.html) I get the main swagger document but a 'Failed to load API definition' error, followed by 'Fetch error undefined /swagger/docs/v1/test.
The network page of my browser inspection gives a 'Http Error 404.0 Not Found'. The requested url is 'https://siteaddress.com:443/swagger/docs/v1/test'.
My ocelot.json is:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/v1/TestSvc/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "test.api",
"Port": "80"
}
],
"UpstreamPathTemplate": "/api/v1/TestSvc/{everything}",
"UpstreamHttpMethod": [ "POST" ],
"SwaggerKey": "test"
}
...
],
"SwaggerEndPoints": [
{
"Key": "test",
"Config": [
{
"Name": "Test API",
"Version": "v1",
"Url": "http://test.api:80/swagger/v1/swagger.json"
}
]
}
...
]
}
I have tried changing paths in ocelot.json and startup.cs. I can see nothing in the MMLib documentation regarding this scenario, which is surely common in deploying these sites.
Suggestion on where to go next appreciated.
Page with ipaddress and port number
Page with physical address and error message

JsonPatchDocument Not getting displayed properly in Asp.Net Core 3.1 Web API Swagger

I have my API documented and versioned previously using Swashbuckle.AspNetCore, Microsoft.AspNetCore.Mvc.Api.Analyzers, Microsoft.AspNetCore.Mvc.Versioning and Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer.
Everything was fine but all of a sudden today I noticed that JsonPatchDocument Not getting displayed properly in my swagger. I couldn't figure out what's the root cause. But I suspect some Nuget Package Upgrade?
Previously I remember the JsonPatchDocument in my swagger as something similar below:
{
"Operations": [
{
"value": {},
"path": "string",
"op": "string",
"from": "string"
}
]
}
But now it shows something else,
{
"ContractResolver": {}
}
Please assist on what I'm missing
Make sure you are added the AddNewtonsoftJson in program.cs after install the Microsoft.AspNetCore.Mvc.NewtonsofJson
should be like this :
builder.Services.AddControllers().AddNewtonsoftJson();

Simple swagger specification, to retrieve an html web page

I'm new to swagger, and I'm trying to make a very simple specification, with only a get method in order to retrieve a web page, this is the code:
{
"swagger": "2.0",
"info": {
"title": "example",
"description": "Sample api to retrieve a web page.",
"version": "0.1"
},
"host":"example.org", #"localhost:8080",
"schemes": [
"https"
],
"paths": {
"/":{
"get":{
"summary":"Return the web page.",
"description":"",
"produces":["text/html"],
"responses":{
"200":{
"description":"OK",
},
"400":{
"description":"Bad request"
},
"404":{
"description":"Not Found"
}
}
}
}
}
}
I'm using the swagger online editor.
Unfortunately when I execute the request, it did not return the web page and no one of the status code that I have implemented in the specification, it return me in the detail section the error:
TypeError: Failed to fetch
Someone can tell me where I'm wrong?
Thank you.
For the "Try it out" button to work in the Swagger online editor, your API endpoints must be CORS-enabled. That is, your server (example.org or localhost:8080) must be configured to return certain response headers that would allow editor.swagger.io to make cross-domain requests to your server. This is explained in more details here:
https://github.com/swagger-api/swagger-ui#cors-support
The way to configure CORS depends on the server/framework used to host the app. This page has instructions for some common web servers:
https://enable-cors.org/server.html

Google Cloud Endpoints REST Discovery Document missing format

I've upgraded to Cloud Endpoints 2.0 which no longer supports RPC. Therefore, I generated a new discovery document and used the service generator with the REST discovery doc as input in order to generate the client library for my iOS app.
Using the new REST discovery doc I am getting the following error when trying to generate the library:
~/workspace/google-api-objectivec-client-for-rest/Source/Tools/ServiceGenerator/build/Release/ServiceGenerator discovery/servUsApi-v1-rest.discovery --outputDir GTLAPI --gtlrFrameworkName GoogleAPIClientForREST
ERROR: Failure, exception: Looking at parameter 'creditKickbackKash:creditAmount', found a type/format pair of 'number/(null)', and don't how to map that to Objective-C
I was able to manually fix this by adding (in numerous places) in the discovery doc, the "format": "double" key and value for all double parameters. Notice creditAmount below is missing a format, like all other doubles.
The generated discovery doc looks like this:
"creditKickbackKash": {
"httpMethod": "PUT",
"id": "servUsApi.admin.creditKickbackKash",
"parameterOrder": [
"userId",
"creditAmount"
],
"parameters": {
"userId": {
"format": "int64",
"location": "path",
"required": true,
"type": "string"
},
"creditAmount": {
"location": "path",
"required": true,
"type": "number"
}
},
"path": "creditKickbackKash/{userId}/{creditAmount}",
"response": {
"$ref": "ResultDTO"
},
"scopes": [
"https://www.googleapis.com/auth/userinfo.email"
]
}
Is anyone else having this issue? How can I get the discovery document generation to properly format the document including double number types?
I had the same problem. I rolled back from 1.9.50 to 1.9.48 and the problem is gone.

Resources