swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Swagger UI within docker and one (or multiple) referenced ($ref) YAML file(s)

Open CyrilleBenard opened this issue 8 years ago • 1 comments

Content & configuration

Swagger/OpenAPI definition:

Not the full YAML file but an extract to identify what's the purpose of this improvement I think that would be nice

paths:
 /{ueContextId}/provide:
   post:
     summary: Namf_Location ProvideLocation service Operation
     tags:
       - Provide Location
     operationId: ProvideLocation
     parameters:
       - name: ueContextId
         in: path
         description: UE Context Identifier
         required: true
         schema:
           type: string
     requestBody:
       content:
         application/json:
           schema:
             $ref: '#/components/schemas/RequestUELocation'
       required: true
     responses:
       '200':
         description: Expected response to a valid request
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/ProvideUELocation'
       '403':
         $ref: './TS29571_CommonData.yaml#/components/responses/403'

Is your feature request related to a problem?

The current docker image already downloadable allows the user to specify its own JSON / YAML file as soon as the container ran, thanks to the below CLI :

docker run -p 80:8080 -e SWAGGER_JSON=/foo/openapi.yaml -v /bar:/foo swaggerapi/swagger-ui

But in case the current YAML file (openapi.yaml) uses an external file reference (see $ref: './TS29571_CommonData.yaml#/components/responses/403' above), Swagger-UI will not be able to handle it.

Describe the solution you'd like

In the docker-run.sh file I would have replaced the link to the JSON file by a link on each file in its current directory :

if [[ -f $SWAGGER_JSON ]]; then
# OLD CODE 
  # cp -s $SWAGGER_JSON $NGINX_ROOT
# NEW CODE 
  cd $NGINX_ROOT ; ln -s $(dirname $SWAGGER_JSON)/* .

# The others lines stay as they are
  REL_PATH="./$(basename $SWAGGER_JSON)"
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
  sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE
else
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$API_URL|g" $INDEX_FILE
  sed -i "s|http://example.com/api|$API_URL|g" $INDEX_FILE
fi

CyrilleBenard avatar Nov 06 '18 14:11 CyrilleBenard

I have forked the project and implemented this. See my fork and the respecting docker image at docker hub

~~I still have a problem with references within component defintions. If such a reference is present the browser will load the referenced file over and over again.~~

hottehead avatar Jan 03 '19 12:01 hottehead