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
Make api docs route optional #82
Conversation
and I just realized I was working off an old master... so I'm going to have some work to do rebasing this |
4c624c3
to
e5d40cc
Compare
rebase wasn't as bad as I thought |
…e to support #73 and in preparation for #81
e5d40cc
to
a72a1f4
Compare
Hmm, I can't reproduce either of those test failures locally |
bb38a7f
to
f3b94cd
Compare
1 similar comment
2172daf
to
473b5d5
Compare
5403fa8
to
473b5d5
Compare
Ok, well I tried to run these tests with the same version of tox, using the same hashseed and it still doesn't fail for me locally. Unless someone has some idea of what's going on, I'm going to start looking at changing these tests. My branch should not have modified the behaviour of this function at all (and they pass for other python versions). |
Whoa. Weird. Feel free to change those tests as needed...the intent should be pretty clear. |
) | ||
listing_filename = os.path.join(schema_dir, API_DOCS_FILENAME) | ||
listing_json = _load_resource_listing(listing_filename) | ||
mapping = build_schema_mapping(schema_dir, listing_json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call build_schema_mapping
again in line 84? I was thinking to instead call the validate_swagger_schema
from inside the build_schema_mapping
and pass the mapping
to validate_swagger_schema
during the call. This way validation
will happen before ingest_resources
and with a single call to build_schema
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I don't like that as much is because it makes the validation kind of implicit instead of being it's own call it's just a side-effect of building a schema.
Does ssv need build_schema_mapping()
? I was thinking that it would work off just listing_filename
, which is why I left the duplicate lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, i missed that. ssv
would just need the listing_filename
for its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to not exposing the schema mapping data structure to the outside world. I've explicitly avoided making it public so we have refactoring flexibility going forward. In the event pyramid_swagger is ever 2.0-only, I bet we could (and would want to) do a major refactoring of the data structure itself.
I was finally able to reproduce this failure on a different laptop
I believe these tests are relying on an undefined behavior of |
if settings.get('pyramid_swagger.enable_swagger_spec_validation', True): | ||
validate_swagger_schema(schema_dir) | ||
|
||
if 'pyramid_swagger.schema' not in settings: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put a comment explaining the purpose of stuffing this in here.
Tweak and I'll merge once tests pass |
b9ff48a
to
f67e593
Compare
merged and tests passing! |
I believe this resolves #73
2b092b1 flatten out the call-graph in
ingest.py
. While I was trying to grok this module I noticed that the call graph was pretty deep, but a lot of parameters weren't being used for anything except being passed down to the next function. With a couple small changes I was able to get everything called directly fromcompile_swagger_schema()
which is the entrypoint to this module. My feeling is that this makes it easier to understand because from a single function (compile_swagger_schema()
) you can get a sense of the whole module. The call graph is never really more than depth 2. It also simplies the return value of the functions to single values instead of having to return complex tuples from many of them.0a44a58 was just a sed.
register_swagger_endpoints
made me think of #3. In this case "swagger" should be pretty obvious since the package is already calledpyramid_swagger
, so I thoughtregister_api_doc_endpoints
was more accurate.c259561 addresses the first point of #73. Adds an option to completely disable /api-docs registration, leaving it up to the user. Docs updated.
4c624c3 starts to get more involved in trying to address the second point of #73. I noticed that
compile_swagger_schema()
(andvalidate_swagger_schema()
under that) were being called from two places. I guess this is becausepyramid_swagger
has two primary functions: serving api docs, and the tween for request/response validation. Each was calling compile/validate. It seemed like instead of having them both do the work, we could move that work to be a the first step of including this package. The compile and validate can be done up-front, and the artifact ( theSwaggerSchema
) just gets added to the settings. I think we could also make an interface and have this registered to the registry redirectly (let me know if that feels like a better approach, I wasn't exactly sure what the function was to do that).This change supports the second point in #73 by allowing a user to disable this
compile_swagger_schema()
step entirely. This would allow them to construct their ownSwaggerSchema
in whatever method they want, add it to the settings (or registry) and everything else in the package should work the same way.This change still needs some documentation about the
SwaggerSchema
interface, and how you would build one yourself (and possibly more tests), but I wanted to get it out and get some feedback on it before spending more time on it.