Skip to content

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

@CyrilleBenard

Description

@CyrilleBenard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions