pyramid_openapi3 icon indicating copy to clipboard operation
pyramid_openapi3 copied to clipboard

Add Support For Not Enabling Spec View

Open zach-hamm opened this issue 2 years ago • 8 comments

I was hoping to update the config.pyramid_openapi3_spec directive so that it registers the spec file to the library, but doesn't enable the route/view. The reason being is we need to perform some filtering on our spec file to determine if you have access to see all of the contents or not. Alternatively, there could be another way to just register the spec file without creating a view for it like:

config.pyramid_openapi3_register_spec

zach-hamm avatar Apr 20 '23 03:04 zach-hamm

Routes and views are not registered by config.pyramid_openapi3_spec, one has to call pyramid_openapi3_register_routes to register routes. Views are always registered by the user.

So I'm not sure what the problem is, can you provide more detail?

zupo avatar Apr 20 '23 08:04 zupo

A route and view is added when you register your spec which you can see here:

https://github.com/Pylons/pyramid_openapi3/blob/6e9c6b7f3124dba45584915f4cd928080a45461d/pyramid_openapi3/init.py#L251

By default a view is added and you can see the spec file. I had to disable it by committing the config and adding my own afterwards, but it would be nice if it was optional by the library. If there’s a different way to setup the library without creating a view let me know. I poked around and didn’t see anything so I followed what was in the README

zach-hamm avatar Apr 20 '23 14:04 zach-hamm

Ahhh, now I see, you mean the route/view for the Swagger UI, I thought you meant the routes/views for endpoint defined in openapi.yaml file.

If you wanna contribute this feature, having config.pyramid_openapi3_spec(swagger_ui=False) seems like the cleanest way to do it in my eyes.

zupo avatar Apr 20 '23 16:04 zupo

No that’s for the OpenAPI yaml file. The swagger UI registration has its own endpoint which is here:

https://github.com/Pylons/pyramid_openapi3/blob/6e9c6b7f3124dba45584915f4cd928080a45461d/pyramid_openapi3/init.py#L148

The link I sent previously creates a route/view for the YAML file which you can see here:

https://github.com/Pylons/pyramid_openapi3/blob/6e9c6b7f3124dba45584915f4cd928080a45461d/pyramid_openapi3/init.py#L248

It’s generating a new view where the YAML file is the response.

zach-hamm avatar Apr 20 '23 16:04 zach-hamm

Ah, yes, you are correct, long day here, sorry.

zupo avatar Apr 20 '23 17:04 zupo

All good! I’ve been out on vacation, but I don’t mind making these changes when I get back and opening up a PR for them if that sounds like a good idea to you.

zach-hamm avatar Apr 26 '23 22:04 zach-hamm

A register_view=True default flag for add_spec_view sounds reasonable.

zupo avatar Apr 27 '23 07:04 zupo

Hey @zach-hamm, do you want to keep working on this, or should I close the issue?

zupo avatar Mar 07 '24 21:03 zupo