Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SWAGGER_FILE env var #2072

Merged
merged 6 commits into from
Jun 2, 2020
Merged

Added SWAGGER_FILE env var #2072

merged 6 commits into from
Jun 2, 2020

Conversation

codeasashu
Copy link
Contributor

@codeasashu codeasashu commented Nov 12, 2019

Added support for SWAGGER_FILE in docker images of swagger-editor.

Description

Earlier it wasn't possible to use a local json or yaml swagger schema file to be used inside docker via env vars. Issue #1695 describes this in details. This is the PR that fixes it.

Motivation and Context

Fixes #1695

How Has This Been Tested?

  1. Pulled the repo and created a local docker image
git pull https://github.com/swagger-api/swagger-editor
## After making my changes
docker build -t swaggerapi/swagger-editor .
docker run -d -p 80:8080 -v $PWD:/tmp -e SWAGGER_FILE=/tmp/swagger.yaml swaggerapi/swagger-editor

seems to load correct yaml definition that only exists on my local machine in current dir.

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

Copy link

@z3niths z3niths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change request.

The rest are LGTM

docker-run.sh Outdated
## Adding env var support for swagger json
if [[ -f $SWAGGER_JSON ]]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use SWAGGER_FILE or DEFAULT_FILE instead since it's working with both json and yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 675812c

@codeasashu codeasashu changed the title Added SWAGGER_JSON env var Added SWAGGER_FILE env var Nov 13, 2019
index.html Outdated
@@ -51,6 +51,7 @@
window.onload = function() {
// Build a system
const editor = SwaggerEditorBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary? I'd like to avoid loading a url by default, since we have our own methods of providing a default value in the Editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

petstore example is what I see by default whenever I start the swagger editor. I have seen the default json included with the source code, to be petstore. If url is not a required attrib, you can kindly skip it. I am outside rn, and wont be able to change the source code. Feel free to edit them for me pls

@shockey
Copy link
Contributor

shockey commented Jan 26, 2020

(LGTM besides my review question!)

@jm3
Copy link

jm3 commented Jan 30, 2020

Any chance we can merge this?

@abirhoss
Copy link

Can we get this merged please

@cjuif
Copy link

cjuif commented Apr 23, 2020

Hi,
Would be great if these changes could be merged.
Thanks,

@tim-lai tim-lai merged commit f93e1ea into swagger-api:master Jun 2, 2020
@codeasashu codeasashu deleted the envvars branch June 3, 2020 07:31
@eugene-khyst
Copy link
Contributor

@tim-lai, it looks like the merge commit f93e1ea into master contains an error.
In the commit update index.html per reviewer comment you removed the line

url: "https://petstore.swagger.io/v2/swagger.json",

So, the following block in the docker-run.sh is useless:

if [[ -f $SWAGGER_FILE ]]; then
  cp -s $SWAGGER_FILE $NGINX_ROOT
  REL_PATH="/$(basename $SWAGGER_FILE)"
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
fi

sed will not replace anything and Pet Store will remain the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment variable to import json or yaml
8 participants