I’m trying to change the URL of my swagger UI from 0.0.0.0
to localhost
(see image below)
I’m using a docker compose with a swagger image.
version: '3'
services:
api-postgrest:
image: another-url.com/postgrest:1.0.0
ports:
- 3000:3000
depends_on:
- database-postgres
environment:
- PGRST_DB_URI=postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@database-postgres:5432/${DATABASE_NAME}
- PGRST_DB_SCHEMA=${PGRST_DB_SCHEMA} # public
- PGRST_DB_ANON_ROLE=${PGRST_DB_ANON_ROLE} # web_anon
database-postgres:
image: postgres:16
ports:
- '5432:5432'
environment:
- POSTGRES_USER=${DATABASE_USER} # postgres
- POSTGRES_PASSWORD=${DATABASE_PASSWORD} # postgres
- POSTGRES_DB=${DATABASE_NAME} # postgres
volumes:
- pg_data:/var/lib/postgresql/data
swagger:
image: swaggerapi/swagger-ui
ports:
- "8080:8080"
expose:
- "8080"
environment:
API_URL: http://localhost:3000/
volumes:
pg_data:
My current solution after some researching was to add a json configuration file as you can see below, with the SWAGGER_JSON
.
swagger:
image: swaggerapi/swagger-ui
ports:
- "8080:8080"
expose:
- "8080"
environment:
API_URL: http://localhost:3000/
SWAGGER_JSON: swagger.json
The json file looks like this
{
"swagger": "2.0",
"info": {
"title": "The YOLO Json",
"description": "I'm losing my stuff",
"version": "0.0.1"
},
"host": "127.0.0.1:3000",
"schemes": [
"https"
]
}
Yet it is not working. My question would be the following, is the path for SWAGGER_JSON
correct and also the json correct in its content?
2
Answers
If you specify
SWAGGER_JSON
, you don’t need to specifyAPI_URL
as that seems to be the URL from which to load the swagger.json. Also from theswagger
service definition in the question, it doesn’t look like theswagger.json
file has been mounted into the container. And as theswagger.json
in the question didn’t have any operations, I used the petstore swagger json instead, changing the URL to127.0.0.1:3000
like in the question. With those things I ended up with adocker-compose.yml
file like the below:With the above compose file, the outbound requests do show the expected host:
You can find all the changes including the swagger.json used on github.
You need to use either one of them:-
I would prefer swagger JSON, as below
The entries in your
swagger.json
looks good