ergo / pyramid_apispec

Pyramid plugin for openapi spec generation (using ApiSpec)
BSD 3-Clause "New" or "Revised" License
23 stars 10 forks source link

Different views based on match_param predicates are not documented separately #21

Closed smsearcy closed 3 years ago

smsearcy commented 3 years ago

When a route pattern includes placeholders that are used as predicates in a view's match_param, this means there can be multiple view functions with different documentation and unique URLs, however currently only one view's documentation is loaded and the path documented with APISpec includes placeholders the end user likely does not know about.

For example, the following route and views would currently only document as a single endpoint (/foo/{id}/{view}) when I think it should document two endpoints (/foo/{id}/bar and /foo/{id}/baz).

config.add_route("foo", "/foo/{id}/{view}")

@view_config(route_name="foo", match_param="view=bar")
def foo_bar(request):
    """
    ---
    description: bar a foo
    """

@view_config(route_name="foo", match_param="view=baz")
def foo_baz(request):
    """
    ---
    description: baz a foo
    """

Edit: Grammar/clarity

smsearcy commented 3 years ago

I have a working implementation for this and will open a PR once I get the tests sorted out (assuming the enhancement is agreeable).

Edit: Tests fail with Pyramid 2.0 due to changes in how the finished_callbacks are handled via scripting.prepare(). I think we should be able to use pyramid.testing.testConfig instead. I've started another branch to sort that out (to keep this PR simple).