Skip to content

swagger vendor tags, host, path tags#163

Closed
kmalyar-tic wants to merge 2 commits into
noirbizarre:masterfrom
kmalyar-tic:master
Closed

swagger vendor tags, host, path tags#163
kmalyar-tic wants to merge 2 commits into
noirbizarre:masterfrom
kmalyar-tic:master

Conversation

@kmalyar-tic
Copy link
Copy Markdown

Hi!

I just got approval for this internally. I've taken the latest pull and run with that:

........................................................................
.............................................................................

....

851 tests run in 2.8 seconds (851 tests passed)

3 changes that I made was to allow for

custom tags to be added at the path level
3rd party vendor fields
having an explicit hostname added to the document (Example is if the doc or swagger ui should be communicating with a host and not running the service local to the doc)

I ran nosetests and they all executed

This is my first attempt at a pull request, so please, be gentle.

Regards,
Kelvin

@kmalyar-tic
Copy link
Copy Markdown
Author

I don't have a python 3 environment. I"m trying to get one to get it to build again. I have no idea why parts that I didn't have anything to do with are breaking.

@noirbizarre noirbizarre added this to the 0.10 milestone Apr 22, 2016
@noirbizarre
Copy link
Copy Markdown
Owner

Thanks !
Don't worry, let's iterate together on this PR, I'm really glad you had approval for it.

I'll start reviewing today (after I released the 0.9.1).

From what I see, you'll be needing:

  • some tests.
  • some documentation about it.

About Python 3, what OS are you using ?

Once they are installed, use tox to run tests on the different version: https://github.com/noirbizarre/flask-restplus/blob/master/CONTRIBUTING.rst

Comment thread flask_restplus/api.py
:param str contact: A contact email for the API (used in Swagger documentation)
:param str license: The license associated to the API (used in Swagger documentation)
:param str license_url: The license page URL (used in Swagger documentation)
:param str host: The host that the api is running on. Not always the localhost, thought it is the default.
Copy link
Copy Markdown
Owner

@noirbizarre noirbizarre Apr 22, 2016

Choose a reason for hiding this comment

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

There is many closed issue on the host subject (ex: #132, #155, #128, #54).
You should have to enter it manually as Flask already handle this properly. If you have to specify the host elsewhere from the SERVER_NAME setting, it's propably that you're lacking the ProxyFix

I should had a dedicated section in the documentation in addition to the examples (https://github.com/noirbizarre/flask-restplus/blob/master/examples/complex.py)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am still a bit confused by this. I have added:

from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)

to my code and it does not return a host in the swagger doc.
{
basePath: "/v1",
consumes: [
"application/json"
],
info: {
description: "API Interface",
title: "Tudor Instrument API",
version: "1.0.0"
},
paths: {},
produces: [],
responses: {},
swagger: "2.0",
tags: []
}

When setting SERVER_NAME explicitly it causes errors. (404)

Could you elaborate on how that should work.

Also, I want to re-confirm the use case.

We are generating a swagger document. Storing in a mongo db. Calling it from another location for dynamic function generation.

It looks to me like if I am setting SERVER_NAME it impacts the routing. I was hoping for a solution where the app behavior isn't driven by the doc.

That said, I don't have a huge amount of experience in this area. Could you provide a bit more clarification on:

  1. how the proxy fix should behave
  2. whether I can have a completely arbitrary host name

@kmalyar-tic
Copy link
Copy Markdown
Author

In response to the higher level question.

I am using Rhel 6.5 (can be 7)

I got most of the above working. I have one issue unfortunately with the tests.

Nosetests pass while the tox tests fail. I'm not sure of why/where that is.

__________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR:   py26: InterpreterNotFound: python2.6
  py27: commands succeeded
ERROR:   py33: InterpreterNotFound: python3.3
ERROR:   py34: commands failed
ERROR:   py35: InterpreterNotFound: python3.5
ERROR:   pypy: InterpreterNotFound: pypy
ERROR:   pypy3: InterpreterNotFound: pypy3
  doc: commands succeeded
(restplus)  ~/git/flask-restplus [master] $ nosetests
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
.............................................................................
...................................................

-----------------------------------------------------------------------------
898 tests run in 1.797 seconds (898 tests passed)
(restplus)  ~/git/flask-restplus [master] $ python
Python 3.4.3 (default, Jan 26 2016, 02:25:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux

I'm still trying to figureout how to identify the bug. with the python 3 code.

@bedge
Copy link
Copy Markdown

bedge commented Jul 22, 2016

This may be a religious issue here, but is it possible to disable a feature for python 3 if it's only functional in 2?
Seems like this effort died a few months ago and if there's no integration soon the work will have been for naught.

@kmalyar-tic
Copy link
Copy Markdown
Author

@bedge
If that is all it is, I would be happy to just provide documentation and unit testing . I am just not sure what to do with py3 at the moment. I not really able to give it the dedicated attention I need to.

@bedge
Copy link
Copy Markdown

bedge commented Aug 16, 2016

@kmalyar-tic I rebased your work to master with python 3 disabled, just to see if everything else still passed.
#191, from git@github.com:bedge/flask-restplus.git
If you have some docs & unit tests to commit, I may have some time to poke at the python 3 tests. I have a local config where I can at least verify the same failures.

@bedge
Copy link
Copy Markdown

bedge commented Aug 16, 2016

@kmalyar-tic I took a pass at the python3 stuff and just merged in some 2to3 recommendations and it fixed the failing pythin3 unit tests.
Now the only holdup is the unit test coverage drop.
If you have anything you can add on the coverage side, this should be good. feel free to pyll sown my PR and re-submit with your work if you want, #192

@noirbizarre
Copy link
Copy Markdown
Owner

Sorry for the late response.

I think you should rebase on latest master to make it pass.

Great for the tag part, but for the host part, I think it should be in because Flask already provide all necessary to proprely specify host. Losts of Flask internals relies on it and I don't want to monkeypatch or bypass this part as it leads to lots of inconsistency.

@kmalyar-tic
Copy link
Copy Markdown
Author

Will do my best to get this working this weekend :) Thanks!

I understand a desire not to monkey patch. With our use case, we are generating the swagger docs, but they they are being collected elsewhere. Not only that, but they are also aliased due to load balancers. I know that Flask provides some information on how to properly specify host, but trying that, it did not then work running the service.

Can you help me out with an example of how that should happen? I'm relatively new.

The approach I took was to just add that one tag to make it config driven more than fiddling with either nginx configs or some environment variables.

@kmalyar-tic
Copy link
Copy Markdown
Author

@bedge Thanks again! Thats awesome, I appreciate it

@kmalyar-tic
Copy link
Copy Markdown
Author

Hi @noirbizarre ,

I think I've finally wrapped my head around our disconnect. I can appreciate the proxy fix solution you've provided. I've gotten it sorta working on my side, but it doesn't actually fit my needs.

Here's the difference:

We are using the library to generate swagger docs and then publish to an api hub. The host itself doesn't know what its CNAME is. We gather these these docs and use them for code generation in other places to make web requests through the load balancer.

I don't have any control over the load balancer, we can't touch it.

Proxying the request is fine, but I need to have a config driven url for the host. Any change to the flask configs breaks the service functionality.

Maybe I can persuade you? :)

Either that, or maybe you can help with a better example, the simple ProxyFix doesn't do it. It doesn't generate the doc correctly.

Either way, if no, no harm done. I'll withdraw this peice of functionality and recreate a pull request with just vendor and path tags.

Thanks!
Kelvin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants