Beginners Extension questions

Hi folks,
I’m trying to develop my first extension for Squidex and some question popped up:

Swagger: Can I somehow also generate a swagger api docu with an annotation so I see it in the some page as the “squidex” swapper api docu?

GraphQL:
Can I integrate my “extension” somehow in the graphql editor if I implement a graphql interface?

Permission:
How to apply permissions to my controller / extension?
[ApiPermission(Permissions.AppClientsRead)] )

Routing:
What would be the best practices to “generalize” the extension. I mean so every new app can use it. Can I also restrict this extension to just the apps?
[Route("{appname}/plugins/sample")]

Sorry for this basic questions.
Cheers and greetings
Mirko

Hi, welcome to the community

Swagger:
The swagger is generated from all controllers. Your custom controller should be part of the documentation then as well.

GraphQL
Right now there is no extension system for graphql, but we can talk about it.

Permissions
Exactly, this is the way to go.

Routing
You have to derive from ApiController, the {name} route value is used for the app name automatically. I would use the same patterns like the other controllers, e.g.

But it is your extension, you can do whatever you want.

Hi Sebastian,

Swagger: Can I somehow also generate a swagger api docu with an annotation so I see it in the some page as the “squidex” swapper api docu?

About Swagger, i created a controller as you described on the support page. And added the DLL to the squidex project.
The route is accessible but it isnt showing up in the swagger api docu.

Is there something special we need to add or is it somehow not working yet?

Or do i need to open a new ticket?

Which Swagger doc have you tested?

Thanks for your reply.

The one that is provided in the Squidex dashboard (/api/content/{app}/docs)

The 3 schema’s that are created in Squidex are visible.

Hi,

there is a general documentation: https://cloud.squidex.io/api/docs

It should appear there.

The different endpoints are described in the documentation: https://docs.squidex.io/02-documentation/developer-guides/api-overview

Hi,

But the one I created as an extenstion (als you can see below) Isn’t showing up.

image

I created a c# .net core library and added the .dll to the plugin part in appsettings.json.
The PluginController you created in Squidex.Extensions is also not showing up in one of the swagger docs.

Its not that big of a deal, I can add Swagger to my plugin aswell, but if its possible to add the plugin end-points to one of the current documents that would be nice :slight_smile:

To be honest I have never tried, I always thought that swagger uses the same controller detection mechanisms that ASP.NET Core is using as well. Perhaps you need the ApiExplorerSettings attribute?

I am not entirely sure to be honest. I was a while ago, that I had to create a new controller and it is a lot of copy and paste :wink:

No problem!

I will try to figure it out, when i found the solution i will share it with you.

1 Like

I found it…we indeed need the ApiExplorerSetting attribute…but i misunderstood it.
You have to add the attribute above the classname and not above the functions.

[ApiExplorerSettings(GroupName = "Sample")]
public class SampleController : ApiController

Maybe is it an idea to add this to the tutorial.

But thanks for your help, in the end we are all getting smarter by the day.

It is kind of documented here: https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/conventions?view=aspnetcore-3.1

1 Like

Hi @Sebastian and @mdijk,
thank you both for your answers. I’m looking forward to finish my first extension.

Cheers
Mirko

Awesome. I am also planning to create dedicated Nuget packages, but it has not been decided yet how to solve the problem with versioning.

1 Like