diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2d959463 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +end_of_line = lf +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..de8159ce --- /dev/null +++ b/.eslintrc @@ -0,0 +1,37 @@ +{ + "parser": "babel-eslint", + + "env": { + "browser": true, + "node": true, + "es6": true + }, + + "parserOptions": { + "ecmaFeatures": { + "jsx": true + } + }, + + "extends": ["eslint:recommended", "plugin:react/recommended"], + + "plugins": [ + "react" + ], + + "rules": { + "semi": [2, "never"], + "strict": 0, + "quotes": 2, + "no-unused-vars": 2, + "no-multi-spaces": 1, + "camelcase": 1, + "no-use-before-define": [2,"nofunc"], + "no-underscore-dangle": 0, + "no-unused-expressions": 1, + "comma-dangle": 0, + "no-console": ["error", { allow: ["warn", "error"] }], + "react/jsx-no-bind": 1, + "react/display-name": 0 + } +} diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 00000000..1b519695 --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,3 @@ +When reporting an issue, please provide the following details: +- swagger-ui version +- a swagger file reproducing the issue diff --git a/.gitignore b/.gitignore index e5ab13fd..3930fdf4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .deps_check .DS_Store npm-debug.log +.eslintcache diff --git a/.travis.yml b/.travis.yml index 99f40f28..c9d09c8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,50 @@ language: node_js node_js: - '6.9' +services: + - docker branches: only: - master - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ -before_deploy: "npm run build-core" +before_deploy: + - npm run build +env: + - DOCKER_IMAGE_NAME=swaggerapi/swagger-ui deploy: - provider: npm - email: apiteam@swagger.io - skip_cleanup: true - api_key: - secure: "IJkLaACa+rfERf1O5nwlqOyuo9sbul3FBhBt4Un9P+DvEet3AoDPV9NQVLd8SkmQYKGbGQWF4BIdjrO5nqFD6Te+JTeUX5Uo/DFS/fu9qw1xv0dQpvbJFuoYnnFlbzGTEs4CFa8lbu3ZromFHQGOQxRobjsG1Kf0dWFSSzmND3g=" - on: - tags: true - repo: swagger-api/swagger-ui - node: '6.9' + - provider: npm + email: apiteam@swagger.io + skip_cleanup: true + api_key: + secure: "IJkLaACa+rfERf1O5nwlqOyuo9sbul3FBhBt4Un9P+DvEet3AoDPV9NQVLd8SkmQYKGbGQWF4BIdjrO5nqFD6Te+JTeUX5Uo/DFS/fu9qw1xv0dQpvbJFuoYnnFlbzGTEs4CFa8lbu3ZromFHQGOQxRobjsG1Kf0dWFSSzmND3g=" + on: + tags: true + repo: swagger-api/swagger-ui + node: '6.9' + - provider: script + skip_cleanup: true + script: swagger-ui-dist-package/deploy.sh + on: + tags: true + repo: swagger-api/swagger-ui + node: '6.9' +after_success: + - if [ $DOCKER_HUB_USERNAME ]; then + docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD; + + if [ ! -z "$TRAVIS_TAG" ]; then + DOCKER_IMAGE_TAG=$TRAVIS_TAG; + else + DOCKER_IMAGE_TAG=unstable; + fi; + docker build -t $DOCKER_IMAGE_NAME .; + if [ ! -z "$TRAVIS_TAG" ]; then + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; + docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest; + docker push $DOCKER_IMAGE_NAME:latest; + else + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; + docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; + fi; + fi; diff --git a/Dockerfile b/Dockerfile index 18c6d443..a3ef6c28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,18 +2,27 @@ FROM alpine:3.4 MAINTAINER fehguy +ENV VERSION "v2.2.10" +ENV FOLDER "swagger-ui-2.2.10" +ENV API_URL "http://petstore.swagger.io/v2/swagger.json" +ENV API_KEY "**None**" +ENV OAUTH_CLIENT_ID "**None**" +ENV OAUTH_CLIENT_SECRET "**None**" +ENV OAUTH_REALM "**None**" +ENV OAUTH_APP_NAME "**None**" +ENV OAUTH_ADDITIONAL_PARAMS "**None**" +ENV SWAGGER_JSON "/app/swagger.json" +ENV PORT 80 + RUN apk add --update nginx RUN mkdir -p /run/nginx COPY nginx.conf /etc/nginx/ # copy swagger files to the `/js` folder -ADD ./dist/ /usr/share/nginx/html/js -ADD ./public/index.html /usr/share/nginx/html - -# change the folder structure -RUN sed -i 's/\.\.\/dist/js/g' /usr/share/nginx/html/index.html +ADD ./dist/* /usr/share/nginx/html/ +ADD ./docker-run.sh /usr/share/nginx/ EXPOSE 8080 -CMD exec nginx -g 'daemon off;' +CMD ["sh", "/usr/share/nginx/docker-run.sh"] diff --git a/README.md b/README.md index 23a9d531..f17deced 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ ## New! -This is the new version of swagger-ui, 3.x. +**This is the new version of swagger-ui, 3.x. Want to learn more? Check out our [FAQ](http://swagger.io/new-ui-faq/).** + +As a brand new version, written from the ground up, there are some known issues and unimplemented features. Check out the [Known Issues](#known-issues) section for more details. For the older version of swagger-ui, refer to the [*2.x branch*](https://github.com/swagger-api/swagger-ui/tree/2.x). @@ -13,7 +15,7 @@ The OpenAPI Specification has undergone 4 revisions since initial creation in 20 Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes | Status ------------------ | ------------ | -------------------------- | ----- | ------ -3.0.1 | 2017-03-18 | 2.0 | [tag v3.0.1](https://github.com/swagger-api/swagger-ui/tree/v3.0.1) | +3.0.8 | 2017-03-19 | 2.0 | [tag v3.0.8](https://github.com/swagger-api/swagger-ui/tree/v3.0.8) | 2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10) | 2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5) | 2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) | @@ -37,14 +39,57 @@ Will start nginx with swagger-ui on port 80. - Node 6.x - NPM 3.x -If you just want to see your specs, open `public/index.html` in your browser directly from your filesystem. +If you just want to see your specs, open `dist/index.html` in your browser directly from your filesystem. If you'd like to make modifications to the codebase, run the dev server with: `npm run dev`. - ##### Browser support Swagger UI works in the latest versions of Chrome, Safari, Firefox, Edge and IE11. +### Known Issues + +To help with the migration, here are the currently known issues with 3.X. This list will update regularly, and will not include features that were not implemented in previous versions. + +- Only part of the [parameters](#parameters) previously supported are available. +- The JSON Form Editor is not implemented. +- Shebang URL support for operations is missing. +- Support for `collectionFormat` is partial. +- l10n (translations) is not implemented. +- Relative path support for external files is not implemented. + +### SwaggerUIBundle +To use swagger-ui's bundles, you should take a look at the [source of swagger-ui html page](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html) and customize it. This basically requires you to instantiate a SwaggerUi object as below: + +```javascript + const ui = SwaggerUIBundle({ + url: "http://petstore.swagger.io/v2/swagger.json", + dom_id: '#swagger-ui', + presets: [ + SwaggerUIBundle.presets.apis, + SwaggerUIStandalonePreset + ], + plugins: [ + SwaggerUIBundle.plugins.DownloadUrl + ], + layout: "StandaloneLayout" + }) +``` + +If you'd like to use the bundle files via npm, check out the [`swagger-ui-dist` package](https://www.npmjs.com/package/swagger-ui-dist). + +#### Parameters + +Parameter Name | Description +--- | --- +url | The url pointing to API definition (normally `swagger.json` or `swagger.yaml`). +spec | A JSON object describing the OpenAPI Specification. When used, the `url` parameter will not be parsed. This is useful for testing manually-generated specifications without hosting them. +validatorUrl | By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators ([Validator Badge](https://github.com/swagger-api/validator-badge)). Setting it to `null` will disable validation. +dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger. +oauth2RedirectUrl | OAuth redirect URL +operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged. + + + ## CORS Support CORS is a technique to prevent websites from doing bad things with your personal data. Most browsers + JavaScript toolkits not only support CORS but enforce it, which has implications for your API server which supports Swagger. diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..76288f67 --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name": "swagger-api/swagger-ui", + "description": " Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.", + "keywords": [ + "Swagger", + "OpenAPI", + "specification", + "documentation", + "API", + "UI" + ], + "homepage": "http://swagger.io", + "license": "Apache-2.0", + "authors": [ + { + "name": "Anna Bodnia", + "email": "anna.bodnia@gmail.com" + }, + { + "name": "Buu Nguyen", + "email": "buunguyen@gmail.com" + }, + { + "name": "Josh Ponelat", + "email": "jponelat@gmail.com" + }, + { + "name": "Kyle Shockey", + "email": "kyleshockey1@gmail.com" + }, + { + "name": "Robert Barnwell", + "email": "robert@robertismy.name" + }, + { + "name": "Sahar Jafari", + "email": "shr.jafari@gmail.com" + } + ] +} diff --git a/public/index.html b/dev-helpers/index.html similarity index 85% rename from public/index.html rename to dev-helpers/index.html index 831ecb81..83a671ca 100644 --- a/public/index.html +++ b/dev-helpers/index.html @@ -1,12 +1,13 @@ +