Jhipster Swagger configuration - swagger

How to override Jhipster swagger configuration in a microservice project to change the /api path in the backend and update gateway Swagger UI accordingly ?

Have you tried setting default-include-pattern in swagger section of your config file (probably application.yml)?
Default setting is /api/.*. For my project I changed it to /(api|io)/.* (its a regex) to include api and io paths.

As of JHipster 7.0, the following changes were made to the backend:
swagger maven profile becomes api-docs
jhipster.swagger property becomes jhipster.api-docs
In order to enable swagger api and to change the default uri pattern I had to:
1 - Enable the maven api-docs profile
2 - Add the following property under to application.yml (replace with your api path):
jhipster:
api-docs:
default-include-pattern: /api-new-path/.*

Related

How to stop Swagger UI from loading Petstore

I've been updating my company's projects to the latest versions of all the packages. When I try to run swagger (http://localhost:4000/swagger/?url=/swagger/swagger.json), it now redirects me to the Petstore.
After searching Google for an answer, it seems like I need to set the following parameter:
queryConfigEnabled=true
According to the Swagger documentation, I can set the parameter in the following ways:
Swagger UI accepts configuration parameters in four locations.
From lowest to highest precedence:
The swagger-config.yaml in the project root directory, if it exists, is baked into the application
configuration object passed as an argument to Swagger UI (SwaggerUI({ ... }))
configuration document fetched from a specified configUrl
configuration items passed as key/value pairs in the URL query string
I tried the following URL
http://localhost:4000/swagger/?queryConfigEnabled=true&url=http://localhost:4000/swagger/swagger.json
but that still redirected me to the Petstore.
I then tried to create a swagger-config.yaml file in the project root directory with the following contents:
queryConfigEnabled: "true"
url: "/swagger/swagger.json"
dom_id: "#swagger-ui"
validatorUrl: "https://validator.swagger.io/validator"
That didn't work either. I even tried to copy the config file to the project /src folder to see if that made a difference.
I tried other things like using a swagger-config.json file instead, copying the config file to the app root in the docker image, setting the configURL to point to the config file, setting the docker environment CONFIG_URL to point to the swagger config file. None of these solutions worked. I'm still being redirected to the Petstore.
As a last resort, I modified the dist/swagger-initializer.js file and added the queryConfigEnabled parameter.
That worked.
Obviously, if I delete the /node_modules folder and re-run npm install, that change will go away.
What am I doing wrong? How do I fix this?

SpringFox Boot starter: How to disable swagger-ui for production profile?

I am using the io.springfox springfox-boot-starter v 3.0.0,
According to the documentation, this Spring Boot setup would disable the swagger endpoint for prod:
#Configuration
#Profile({"!prod && swagger"})
public class SwaggerConfig implements WebMvcConfigurer {
#Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.any())
.build()
.apiInfo(apiInfo());
}
...
When on prod, the customisations of swagger defined here are indeed missing, but the Swagger UI endpoint is still there. How can I suppress the /swagger-ui/ endpoint altogether? Is there nothing like a springfox.swagger-ui.enabled=false property I can set somewhere in the spring boot application configuration?
You can disable using below property
springfox.documentation.enabled=false
Springfox Boot Starter API enable by default the 'auto-startup' configuration, means Swagger UI html page (ex. /swagger-ui/index.html) and Api-Docs (/v2/api-docs) JSON page containing a swagger with All API definitions.
For production environment is a good choise disable all the API documentation.
To disable all the swagger auto-configurations you can add on your application-prod.properties file the property below:
springfox.documentation.auto-startup=false
In this case with Your config on prod you have nothing about swagger.
If you want to remove the swagger-related resources completely, consider do it in the compile-time.
If you are using Apache Maven, it is easy to control dependencies and runtime configuration in a Maven profile, eg swagger.
When building for production, run the following command.
mvn package -Pprod
// for dev stage.
mvn clean spring-boot:run -Pdev,swagger
My example is a little old which used Maven to control different configuration in different stage.

Django rest framework swagger missing port when run in docker

I am using rest framework swagger for the first time in my Django application. When I run it locally from PyCharm it works just fine. My app runs on port 1337 and when I Try Out my restful API endpoint and click Execute, the curl command works and the URL includes the port.
The issue is when I run my Django app in a Docker. In this case, the URL in the curl command does not include the port. Do I have to add any swagger specific configuration to my docker compose file? I have not changed my Dockerfile nor my docker-compose file at all.
What do I need to do to get this to work properly?
It seems like you have set the url parameter for the get_schema_view(...)--(DRF Doc) function. The url is used to set the canonical base URL for the schema.
If you didn't set the value, DRF will use the "requested host" as the default URL.
Ref
url = self.url
if not url and request is not None:
url = request.build_absolute_uri()
SO, you can set the url to any value or you can exclude the parameter to get the default behavior.
from rest_framework.schemas import get_schema_view
urlpatterns = [
path('openapi', get_schema_view(
title="Your Project",
description="API for all things …",
version="1.0.0"
), name='openapi-schema'),
]
Please check the file urls.py which is the place you are setting URL for SWAGGER.
Don't set url in get_schema_view function.
Also, when you are running the app by using docker, the URL in the curl command does not include the port -> That's right!
I think that your file is using multiple settings for swagger by checking like this:
if getattr(settings, "SETTINGS_ENV", None) in ["local", "dev", "draft", "production"]:

Grails 3 plugins configuration

New to Grails 3- starting to port.
Have tried placing config values in application.groovy and application.yml within plugin conf dir to no avail - trying to read values from within plugin service fails. Adding values to the main application's application.groovy works.
What is the secret here? Previously I could load specific conf files via config.locations simply by naming them which was nice and simple. I've seen some resolutions that include needing to setup env vars with paths to config files which I'd like to avoid. Then they set up file URIs for dev and classpath URIs for other envs that will be war packaged - don't really want to do any of this.
Do we no longer have the ability to place config within a plugin and have that automatically merged with the applications config?
The plugin may provide config settings in grails-app/conf/plugin.yml.

Keycloak Unknown authentication mechanism

I need help with using keycloak in an Errai app. I am getting an error about "unknown authentication method" for "KEYCLOAK" ? I have the keycloak-appliance running (on a different port though), and the Errai app has a with KEYCLOAK in the web.xml file inside WEB-INF
When I run the Errai app with mvn gwt:run, I get : RuntimeException caused by "Unknown authentication mechanism KEYCLOAK". I have no idea how to go around this issue .
Just wanted to add a little more detail to #cfsnyder's answer. In order for your application server to recognize a definition in the web.xml that looks like this:
<login-config>
<auth-method>KEYCLOAK</auth-method>
<realm-name>internal</realm-name>
</login-config>
you'll need to tell jboss (in this instance) how to interpret that particular auth method. At the time of my answer, this is in section 8.2 of the Keycloak docs.
First, download the keycloak adapter (remember, this is not the same as the Keycloak Server). Next, unzip the download in the wildfly home directory. With your application server running, just use the following command to install the Keycloak configuration into the appropriate files:
jboss-cli.sh -c --file=adapter-install.cli
When this script completes, your configuration file will have the new entry added to accommodate the KEYCLOAK entry in your web.xml. The script will add something like this to either a domain.xml or standalone.xml:
<security-domain name="keycloak">
<authentication>
<login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"/>
</authentication>
</security-domain>
Once you have the Keycloak module files provided by the adapter + the security domain configuration to link the KEYCLOAK method to the appropriate LoginModule, you should be all set.
You will need to install and configure the Wildfly adapter in order for your Errai app to recognize the "KEYCLOAK" authentication method. See section 7.2 of the Keycloak documentation.
To add to #josh-cain's answer, you might also need following additions in your domain.xml or standalone.xml:
To <extensions></extensions>, add:
<extension module="org.keycloak.keycloak-adapter-subsystem"/>
To <profile></profile>, add:
<subsystem xmlns="urn:jboss:domain:keycloak:1.1"/>
The adapter installation cli scripts can fail for various reasons so you might need to add these entries manually.

Resources