Pylons / pyramid_openapi3

Pyramid addon for OpenAPI3 validation of requests and responses.
https://pypi.org/project/pyramid-openapi3/
MIT License
84 stars 47 forks source link

Add Support For Not Enabling Spec View #208

Open zach-hamm opened 1 year ago

zach-hamm commented 1 year ago

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

zupo commented 1 year ago

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?

zach-hamm commented 1 year ago

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

zupo commented 1 year ago

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.

zach-hamm commented 1 year ago

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.

zupo commented 1 year ago

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

zach-hamm commented 1 year ago

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.

zupo commented 1 year ago

A register_view=True default flag for add_spec_view sounds reasonable.

zupo commented 8 months ago

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