How to open local files in Swagger-UI

前端 未结 13 1714
粉色の甜心
粉色の甜心 2020-12-23 09:10

I\'m trying to open my self generated swagger specification file my.json with swagger-ui on my local computer.

So I downloaded the latest tag v2.1.8-M1

13条回答
  •  没有蜡笔的小新
    2020-12-23 09:45

    Yet another option is to run swagger using docker, you can use this docker image:

    https://hub.docker.com/r/madscientist/swagger-ui/

    I made this ghetto little BASH script to kill running containers and rebuild, so basically each time you make a change to your spec and want to see it, just run the script. Make sure to put the name of your application in the APP_NAME variable

    #!/bin/bash
    
    # Replace my_app with your application name
    APP_NAME="my_app"
    
    # Clean up old containers and images
    old_containers=$(docker ps -a | grep $APP_NAME | awk '{ print $1 }')
    old_images=$(docker images | grep $APP_NAME | awk '{ print $3 }')
    
    if [[ $old_containers ]];
        then
            echo "Stopping old containers: $old_containers"
            docker stop $old_containers
            echo "Removing old containers: $old_containers"
            docker rm $old_containers
    fi
    
    if [[ $old_images ]];
        then
            echo "Removing stale images"
            docker rmi $old_images
    fi
    
    # Create new image
    echo "Creating new image for $APP_NAME"
    docker build . -t $APP_NAME
    
    # Run container
    echo "Running container with image $APP_NAME"
    docker run -d --name $APP_NAME -p 8888:8888 $APP_NAME
    echo "Check out your swaggery goodness here:
    
    http://localhost:8888/swagger-ui/?url=http://localhost:8888/swagger-ui/swagger.yaml"
    

提交回复
热议问题