I have a SpringBoot application that uses Swagger for the API doc and Swagger-UI for rendering it.
Before using the any of the endpoints from swagger-ui I need to retrieve a bearer token and for this a clientID and an authorize endpoint are used
I have 2 different environment where both the clientID and the authorize endpoint are different.
I'm using chef to handle the deployment of my app (which is a JAR started as java -jar myapi.jar) which builds a different application.properties for each environment but because the clientID and auth url are in the swagger-ui's index.html and that thee files are INSIDE the jar I don't know how to use chef to replace these values at deploy time.
Is there a way I can passed these values somehow? Or the only solution is to not have a JAR but an exploded jar ?
TLDR: I want to be able replace values in the index.html depending on the environement
I;m not aware of anything in springboot/swagger that let you pass values to the static files (aka ${clientId} from your index.html)
What you could do though is having chef template (a simple json file can be enough) containing
{
"clientID":..
"authUrl: ..
}
That you make chef write in the same directory where your index.html is. And in your index.html write some javascript to load that file.
Related
I have my API documented with Swagger. For developer convenience I would like to provide the swagger GUI on my website as well. However, my provider has not installed the php yaml extension. It implies that I can't use the GUI on my own website.
So, I would like to use a third party GUI. I know that I can use https://petstore.swagger.io/ and enter the link to my yaml file in the text box. This is also not really user friendly. I prefer to open the GUI and specify the yaml when calling the url. For the user the GUI opens with my API definition.
Any thoughts?
If for some reason you cannot host Swagger UI youself, here are some alternatives you can try:
Use SwaggerHub to host your API definition and docs.
Disclosure: I work for the company that makes SwaggerHub.
Use GitLab to host your OpenAPI YAML/JSON file. GitLab uses Swagger UI to render OpenAPI files. Example:
https://gitlab.com/gofus/gofus-api/blob/dev/swagger.yaml
Use https://petstore.swagger.io with the url query parameter to automatically load your API definition:
https://petstore.swagger.io?url=https://yoursite.com/api.yaml
For this to work, the server where your OpenAPI file is hosted must use HTTPS and support CORS.
I am currently building a SPA app using Vue.js and webpack to do our bundling. The backend API is built with .Net Core. When running locally, the Vue app is hitting localhost on the backend. I need to be able to change the route of the API dynamically based on the environment. Is there a way to do this without having to do a big switch statement that considers the current url? A requirement is that we are not allowed to change the webpack bundle for different environments, in other words, once it is bundled, it has to stay bundled. I have tried to pass static config files through to the bundle and dynamically change them based on the environment, but unfortunately that does not work, as it hits the values that were originally in them.
webpack dev server has a proxy capability. You could use this to proxy to your locally running backend when developing.
https://webpack.js.org/configuration/dev-server/#devserver-proxy
e.g. you can point anything from '/api' to 'localhost:8888/api' with the config.
Is your app the backend running on the same url when deployed? If not, you'll likely need a reverse proxy to pass along the requests to the backend.
You can use an axios interceptor so you only have that switch in one place:
axios.interceptors.request.use(config => {
// check location.host name and append the backend url you want
});
see https://github.com/axios/axios#interceptors
However, this is a little dangerous as the URLs in your switch statement will be strings, and therefore all of your environment URLs can be pulled out of your code even if minified/concatenated.
Another option is to add some sort of endpoint to the server your client side code is hosted, and when you start your app, query for that configuration.
I am getting the following response when requesting for Swagger doc in a Web API project,even the same response getting from Azure.
Can any one help me to get the Swagger UI.
Perhaps try to request the Swagger-UI through a different url, eg.../swagger/index.html.
I am not working with .NET here and I have no Idea about your setup, but did you (for example) copied swagger-ui resources to your webdir?
It looks like you are calling swagger interface directly and not swagger-ui (which is something different).
https://swagger.io/swagger-ui/
from Swagger-Ui Documentation:
Step 1: Go to the GitHub repository of the Swagger UI project
Step 2: Clone or download the zip file of the repository
https://github.com/swagger-api/swagger-ui
Usage
Step 1: Go to the folder containing the Swagger UI project in your local machine
Step 2: Open the dist folder
Step 3: Run the dist/index.html file on a browser or place the dist folder inside your server.
Step 4: The Swagger UI will now be live in the browser, with the default rendering of the Swagger Petstore. The JSON specification of the Swagger Petstore can be found here - http://petstore.swagger.io/v2/swagger.json
Note: Please remember that to load a specification and execute the UI’s try out requests, you would need to have enabled CORS (read below)
Step 5: You can mention the YAML or JSON path of any existing specification hosted on a server in the field on the top navigation bar.
The correct URL for the UI would be https://localhost:44390/swagger/ui/index
Check if swagger is configured to use any custom route or prefix. In this case the UI URL would be url:port/route-prefix/index.html. Route prefix empty = url:port/index.html.
I am new to Yii. I have a jquery file manager working with plain PHP script. Now i want to integrate it with Yii Application. The flow is like, from index it will initiate jquery function, which will search for PHP connector script. My problem is, how can i include connector script in Yii so that the Jquery can access it
If you've got the rest of the extension working, then you can create a controller within this extension's directory to handle any actions for it. Then you can use the URL rules in the configuration to send specific URLs to it.
as of now i did not create any extensions, I put the connector script under assets directory and it just worked fine. I am sure this cannot be the best practice. I would like to get help on creating custom extensions for Yii
I know that within Symfony2's configuration, there is no reference to the base url, as there is no request; the application could either run in cli or within a web server, and therefore we cannot rely on request. But still, I have configuration that asks for stylesheets or javascript base url (such as the JQueryHelperBundle, where you can set your jquery local path - being the local url). The thing is, is there a way to dynamically set a base url for the configuration, without having to change it so that:
The application can move from any directory under development, whether www/myproject or www/foo/myproject without having to change the settings
Production would work the same, except that rewriting the base url with apache would be detected (virtualhosting is common, where the baseurl is mapped to the web directory as '/').
Is there a way to get that base url information? Would using the difference between $_SERVER['DOCUMENT_ROOT'] minus the kernel root dir be a way to detect such base url? But what about virtualhost rebasing the url to / on the web directory? Hardcoding the base url completely couples the project to where it stands in development, and moving project around would require to change the base url everytime, which is annoying.
So, is there a way to dynamically detect the base url within Symfony2's configuration, according to the environment, without depending on the request?
I had to do that in a service, so I injected the router service in my own service and then:
$baseUrl = $router->getContext()->getHost();
But I considered it more as an hack that a real fixture of Symfony2 framework. For instance, in Controller you can generate absolute url easily (example from the symfony book):
$router->generate('blog_show', array('slug' => 'my-blog-post'), true);
And in the twig template, you have the {{ url }} function
I hope this help