ergo / pyramid_apispec

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

Integration with Cornice #9

Closed pansen closed 5 years ago

pansen commented 5 years ago

Hi @ergo ,

thank you very much for that lib. I integrated it nicely working into a playground project, rendered it with a different yaml lib

    # this requires `apispec==1.0.0b3`
    spec = APISpec(title="Some API", version="1.0.0", openapi_version='3.0.0', plugins=[MarshmallowPlugin()])
    # you can further mutate the spec dict to include things like security definitions
    my_spec = spec.to_dict()
    return Response(pyaml.dump(my_spec, safe=False, force_embed=False, vspacing=[2, 1], string_val_style='"'))

convert that output via widdershins

widdershins \
                --headings 4 \
                --resolve true \
                --search false \
                --language_tabs \
                    'shell:Bash' \
                    'javascript:JavaScript' \
                    'python:Python' \
                    'ruby:Ruby' \
                    'java:Java' \
                --outfile var/index.html.md \
                --verbose \
                --expandBody true \
                var/openapi_direct.yaml

and put that index.html.md into Slate. Much wow ;)

Now I integrated it into my real project, which is using Cornice. Unfortunately this does not seem as an easy pick.

# Cornice `service.name` becomes `route_name` of Pyramid
c1_login_service = Service(name='c1_login',
                           path='/auth',
                           description='Validate a JWT and create a session for us.')

@c1_login_service.post(accept='application/json',
                       schema=PostJwtSchema,
                       validators=(body_validator,),
                       require_csrf=False)
def checkout_authentication(request):
    """
    Validate a JWT and create a session for us

    ---
    x-extension: value
    post:
      # headline/name of the resource (renders as `h2`)
      ...

I can register that route, but the docblock is not being read.

Do you have any guess, or hint where to go?

Cheers

ergo commented 5 years ago

Interestingly - I also wrote cornice marshmallow support :), I did not look at cornice.ext.apispec - they have that package that currently supports colander schemes. I don't know why the docblock is not being read, you would have to do some debugging on your end, probably introspection does not pick cornice services or its wrapped somehow.

pansen commented 5 years ago

The problem seems to be, that in pyramid_apispec.helpers.add_pyramid_paths it detects 3 introspectables (in the playground, without Cornice, only 1). That alone seems not to be the problem, but that the last of the 3 does not have the __doc__ anymore..

image

Ideas?

pansen commented 5 years ago

Ah. There must be some exclusion on maybe_view.get("callable").__name__ == '_fallback_view'...

ergo commented 5 years ago

That's probably caused by cornice internals and venusian handling that. I don't really have time to look at that right now, but it would be easier for us to test if you could provide a minimal test case, it would be useful to file a bug against pyramid_apispec or cornice depending on where the problem appears. I could look at it when I have a moment, debugging from screenshots will be hard.

pansen commented 5 years ago

Sure, I will prepare something. Thanks for your fast replies :)

pansen commented 5 years ago

Looking forward for your feedback @ergo

ergo commented 5 years ago

@pansen Hey, I've left some comments for you.

ergo commented 5 years ago

@pansen hey any news on this?

ergo commented 5 years ago

This issue was fixed by other commits.