Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Swagger rebased updated #145

Merged
merged 31 commits into from
Mar 6, 2017
Merged

Swagger rebased updated #145

merged 31 commits into from
Mar 6, 2017

Conversation

NotSpecial
Copy link
Contributor

Fancy new swagger interface for /docs added by hermann

@hermannsblum
Copy link
Contributor

Seems like there are still some rebase problems, travis fails...

@coveralls
Copy link

coveralls commented Dec 10, 2016

Coverage Status

Coverage increased (+0.04%) to 87.077% when pulling be4c594 on swagger_rebased_updated into dffbf98 on master.

Copy link
Member

@cburchert cburchert left a comment

Choose a reason for hiding this comment

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

Are we sure we have to include the whole swagger code in the API?

The design looks weird as well. Can we make the resource description smaller, in a new line or bold the resource name? Currently the resource name and the description are in one block, I don't like that.

We loose a lot of documentation like max and min values and additional validators. Can we at least give something like the resource definition or a link to it?

Otherwise see the comments I left. I think some things should be changed.

# 'POST': "Login and aquire a login token. Post the fields "
# "'username' and 'password', the response will contain the "
# "token. 'username' can be either nethz, mail, or user_id",
# 'GET': "Check token(s)."}
Copy link
Member

Choose a reason for hiding this comment

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

Is this documentation lost now? If yes, can we add it somewhere else?
If no, can we remove this comment?

amivapi/docs.py Outdated
add_documentation({'definitions': {'User': {'properties': {
'password': {'default': ''},
'nethz': {'default': ''}
}}}})
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this? We generate empty documentation fields?

Copy link
Contributor

Choose a reason for hiding this comment

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

Swagger in the currrent version does not support

Default: null

And crashes. They decided to fix this only in later versions, so for now we have to replace all null fields with something else

amivapi/docs.py Outdated
'name': 'Authorization',
'in': 'header',
'description': 'enter a token you got with POST to /sessions'
}
Copy link
Member

Choose a reason for hiding this comment

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

This is badly worded, as it suggests API keys and tokens are the same. Looking at the created website, I propose:

name: Authorization header
remove in
description: 'enter either a session token, you retrived using POST to /sessions, or an API key defined in the server config.'

Copy link
Contributor

Choose a reason for hiding this comment

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

This is swagger code. Swagger supports 3 types of authorization schemes, and they call token-based authorization 'apiKey'

'name' is the key of the header field, this cant be changes therefore.

But if course we can adapt the description field

'2014-12-20T11:50:06Z',
# 'methods': {
# 'GET': 'You are always allowed, even without session, '
# 'to view AMIV-Events'
Copy link
Member

Choose a reason for hiding this comment

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

Again: do we loose this? remove comment?

'events.',
# 'methods': {
# 'PATCH': 'Only additional_fields can be changed'
# }
Copy link
Member

Choose a reason for hiding this comment

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

Same thing again

'termsOfService': 'todo',
'contact': {
'name': 'AMIV an der ETH',
'url': 'http://amiv.ch/'
Copy link
Member

Choose a reason for hiding this comment

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

https please

'title': 'AMIVAPI',
'version': '0.1-dev',
'description': "The REST API behind most of AMIV's web services.",
'termsOfService': 'todo',
Copy link
Member

Choose a reason for hiding this comment

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

Add a # TODO comment, so this shows up in grep

'url': 'http://amiv.ch/'
},
'license': {
'name': 'GNU',
Copy link
Member

Choose a reason for hiding this comment

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

This just puts "GNU" without context to the website. We need to write what it is.
Change to "GNU Affero General Public License"?

'add_permitted_methods_after_fetch_item',
'add_permitted_methods_after_fetch_resource',
'add_permitted_methods_for_home',
'add_permitted_methods_after_update']
Copy link
Member

Choose a reason for hiding this comment

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

This does not seem to work. add_permitted_methods_after_insert is shown under POST to joboffers.
Any ideas?

'add_permitted_methods_after_fetch_resource',
'add_permitted_methods_for_home',
'add_permitted_methods_after_update']
X_DOMAINS = ['http://127.0.0.1:5000', # The domain where Swagger UI is running
Copy link
Member

Choose a reason for hiding this comment

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

This IP should not be hardcoded, this breaks the documentation in many setups. The address should be available via flask. (maybe SERVER_NAME config value?)

@cburchert
Copy link
Member

I fixed all the comments I made apart from the one about the code in docs.py line 50. It is not clear to me, what that code is for.

Still design does not look good and we are missing the validator information.

@cburchert
Copy link
Member

Looking at other swagger based documentation, I think we should move the description of resources to implementation_notes and just have a short string for the description.

@hermannsblum
Copy link
Contributor

I fixed the authorization again following my comments above

@hermannsblum
Copy link
Contributor

I think the documentation with realtion to special HTTP methods is OK now, even though it should in the end only be displayed for the actual method you look at right now.

Also related to the more detailed description and "summary": How do you suggest to structure the json? We could think of something like this:

    'events': {
        'summary': 'Anything happening in the AMIV'.
        'description': 'An Event is basically everything happening in the '
        'AMIV. All time fields have the format YYYY-MM-DDThh:mmZ, e.g. '
        '2014-12-20T11:50:06Z\n\n'
        'method_documentation' {
            'GET': 'This is public even without a session'
        }

We would then adapt the mapping into the swagger fields, this is done by eve-swagger and therefore easily adaptable as we already use our own fork

@cburchert
Copy link
Member

I like that approach.

@hermannsblum
Copy link
Contributor

For the documentation of validation rules: This is a known swagger issue right now.

It looks like they lost this with the implementation of the example objects as they had it before. Apparently you can see some stuff by hovering, but I do not consider this a solution.

As we can expect this issue to be worked on, I suggest an easy solution for the moment printing out the schema into the implementation notes via our version of eve-swagger.

@hermannsblum
Copy link
Contributor

Doing some more research 😃

I think I actually prefer this much more over swagger: http://rebilly.github.io/ReDoc/
It uses the same documentation resource (swagger-like JSON description is basis of OpenAPI), but describes actually all the stuff we want.
However, it does not yet have an interactive console to try out requests like swagger does...

What are your opinions?

@cburchert
Copy link
Member

cburchert commented Feb 28, 2017

I have at least two issues:

  1. import error: bootstrap.py imports docs, but the file is called documentation.py
  2. I don't like the structure. There are three things in the amivapi package, which all belong together (swagger_ui folder, documentation.py and ReDoc folder). The swagger_ui folder looks like it is API code, while actually it is a library. I would recommend we either have a folder "lib" or "external" or whatever and put it in there, or we move it outside of amivapi altogether and somehow reference it.

An easy solution to 2 might be to have:

amivapi/documentation/lib/swagger_ui/
amivapi/documentation/ReDoc/
amivapi/documentation/documentation.py

@hermannsblum
Copy link
Contributor

You fixed the import error by yourself, thanks and sorry for that 🤙

Concerning the structure: This was actually only there as I never really got a feedback whether we should use ReDoc or SwaggerUI. As nobody seems to care too much, I simply decided for ReDoc, which we can include as external JS and therefore we only need the file amivapi/documentation.py which now inlcudes the 14 lines HTML template.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage increased (+0.01%) to 87.242% when pulling b971e94 on swagger_rebased_updated into 44de894 on master.

@cburchert cburchert merged commit b971e94 into master Mar 6, 2017
@cburchert cburchert deleted the swagger_rebased_updated branch March 6, 2017 19:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants