Swagger Configuration for base url - spring-boot

I have my Spring boot application deployed using the Kubernetes cluster. I have swagger configured using
springfox.documentation.*
Now on the swagger page when I use "Try it out" button, and submit an API request the Request Url is formed like https://java:9080/api/customer/order Which should be https://application.domain.com/api/customer/order
The swagger page opens at https://application.domain.com/swagger-ui.html#
Any idea how could it be fixed?

You need to configure the swagger ui to use your server. Look at this document.
Looks like setting the URL environment variable for the swagger UI should work. For better control, you can get a copy of the dist/index.html page, edit it with your configuration options, and mount it into the swagger container.

My answer is straight forward WRT Kubernetes + SpringBoot.
If it's on kubernetes, Then please try to append your application name in the URL.
Refer application name from deployment.yml
---
apiVersion: v1
kind: deployment
metadata:
name: {app-name}
Example:-
https://application.domain.com/{application-name}/swagger-ui.html

Related

How to route to my UI application using root url / using spring cloud gateway

I have react based UI application running on kubernetes with root contextPath (/). When I do kubectl port-forward svc/my-ui-app 8080:8080 and then launch the application on http://localhost:8080, everything works fine.
Now I want to use spring cloud gateway to route to my application. I configured the root url (/) and /apppath like below
spec:
routes:
- filters:
- RewritePath=/apppath(?<segment>/?.*), $\{segment}
predicates:
- Path=/apppath/**
- predicates:
- Path=/
service:
name: my-ui-app
So my expection is to have http://my-domain and http://my-domain/apppath both to route to my ui application.
Whats happening is when I use http://my-domain/apppath, when the ui app internally refers to the index.js (and other image files), the url used for that evaluates to http://my-domain/apppath/index.js automatically and spring cloud gateway is able to load these files as it matches the route /apppath/** and is able to route to my application.
The problem is with the root url http://my-domain. When I hit this, the url to fetch the index.js (and images etc) evaluates to http://my-domain/index.js and spring cloud gateway does not know where to route it to as there is no route mapped for /index.js.
What do I need to do to make http://my-domain work without having to change the application code to have a contextPath explicitly set?

Swagger incorrect API path

I'm using swagger and swagger UI to document my APIs. This is in a spring boot microservice set up. I am consolidating all swagger docs into my zuul gateway. This all works fine for displaying the documentation.
However when you try and execute the APIs using the Try It Out button, this fails as the path being used to hit the endpoint is incorrect. Specifically swagger seems to expect the downstream service to have no context root. Is there anyway i can configure this to accept a context root?
I've reproduced the issue on this repo https://github.com/craigmgordon/swagger
If i run the services and hit the gateway on http://localhost:20000/swagger-ui.html i can see the docs for my two services are displayed correctly.
You can see the url is correct at the top of the page http://localhost:20000/prod/product/v2/api-docs
where 'prod' is the zuul route to the product-service
and 'product' is the product-service context route
If I try and use Try ITOut on the /products endpoint though, on execution i get a 404 as its tried to hit the url http://localhost:20000/prod/products
i.e. has ommitted the context route.
Correct url should be http://localhost:20000/prod/product/products
Has anyone had the same issue and found a resolution??

what is service url in spring starter project? Alternatives for default service url https://start.spring.io

I am new to Spring boot.
While creating a New Spring Starter project in STS there is a Service URL dropdown defaults to https://start.spring.io as given below.
I searched in stack overflow but didn't find any information about it.
What is the use of specifying this? Why it has been given as editable? Is there any alternative available instead of https://start.spring.io?
I noticed that tried with any other URL, it tries to parse as json and gives exception given below.
JSONException: A JSONObject text must begin with '{' at character 3
Need clarification, what is happening in background?
It is a simple client server architecture which various UI clients such as Spring Boot CLI , IDE or official web UI talk to the same backend HTTP API that actually generates the spring starter project.
The service URL is the URL of this HTTP API. Spring Team already deploy an official one at https://start.spring.io which you can simply use it.
But in case if you want to build your own customised version , you can checkout its source codes , modify according to your needs and deployed to your own server. Then change the service URL to your API server 's URL in order to use it.

spring cloud data flow custom app config to pass enviromental variables

i am working on Spring cloud data flow Custom source application which gets data from an rest endpoint . I use Spring cloud data flow and Skipper server to push this custom jar to PCF (Pivotal Cloud Foundry) .This works fine but now i want to pass some custom environmental properties to the application .Below is the yaml config i used to deploy the jar to the repo . tried passing below it under the env bucket but seems its not getting picked by the application at runtime..Please suggest
DB_HOST:host_url
DB_PORT:3306
DB_SCHEMA:test
DB_USER: user
DB_PASS:pwd
application.yml for pusing the CUSTOM SOURCE to SCDF App Repo
---
applications:
- name: pocclient
memory: 2G
instances: 1
path: ../target/custom-sink-client-0.0.17-SNAPSHOT.jar
buildpacks:
- java_buildpack
env:
JAVA_VERSION: 1.8.0_+
SPRING_PROFILES_ACTIVE: cloud
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
DB_HOST:host_url
DB_PORT:port
DB_SCHEMA:test
DB_USER:
DB_PASS:
Based on the limited details in the description, it is unclear what you're trying to do with SCDF and a custom-sink, and likewise, in which platform are you provisioning all the components. You may want to edit the post with more details.
In Cloud Foundry, if you want SCDF to deploy apps with config-server binding automatically, you would want to review the ref. guide for more information. The service-instance must exist in the same Org/Space, and the service-instance name is expected to be configured in SCDF, so when SCDF deploys apps on your behalf, it will also bind the app with the service-instance automatically.
In Kubernetes, it'd be a similar mechanism; however, you're expected to provide the config-server URI configuration as an environment variable when deploying the desired apps as bare-pods.

'preview' ingress service configuration

I'd like to know how to add annotations on all preview ingress services definition generated for each jx preview to configure it.
I'm having issues with either header forward or header stripping by nginx. The server behind the preview ingress service is not receiving some headers requests.
Thank you for your help!
Jenkins X uses a controller called exposecontroller to generate ingress rules when applications are deployed. We can add annotations to Kubernetes services which exposecontroller then uses to in turn add to the ingress rule it creates.
You can add a list of annotations to your applications service helm chart which can be found in the repo of your project. Here's an example from a Jenkins X nodejs quickstart and to see an example of where we list multiple annotations that exposecontroller adds to generated ingress rules you can look at some of Jenkins X own charts

Resources