Swagger2.0 Securitydefinition and Smartdocs

I have swagger 2.0 yaml defined for set of APIs where securityDefinition is set for apikey as queryparams. When I create Smardocs model using this swagger, I have following issues:

1. On the individual API page, in Resource Summary section, I see ‘Auth Type’ defined as ‘No auth’. Won’t Smartdocs pick the ‘securityDefinitions’ from swagger? Do we need to explicitly set the custom token authentication settings in Smartdocs ?

2. On the API list page, I see ‘field_pyo_model_authschemes’ field dangling on all the APIs. How do I get rid of this? ( I tried to locate and delete this field by traversing through, Structure -> ContentType -> {Api-Model-Name-that-I-created} -> Manage Fields, but i don’t see this field )

1615-dangling.png

Thanks in advance!

Solved Solved
0 8 1,412
1 ACCEPTED SOLUTION

Not applicable

Hi @Vikaas,

I couldn't figure out what is going wrong. But you can find a similar issue stated here. I would suggest you to rather update the developer portal, since this functionality is working fine on my developer portal (build info version: 15.07.08.00). If you update the portal, then following steps can be helpful:

1. Create a model.

2. Import Swagger JSON.

3. Go to Content-> Smartdoc-> API Revisions-> Security Settings. If you have already specified securityDefinitions in swagger, then you will find it here. Else, you can add security scheme. Specify 'Type' as 'API Key'.

step3.png

4. To give value of API Key, go to: Content-> Smartdoc-> API Revisions-> Security Settings-> template auth settings. Specify the apikey to be used.

step4.png

5. Edit each method, and set authentication to API Key scheme.

step5.png

Now, the request will be sent along with header/query param containing predefined apikey, and resource summary will also get updated.

result1.png

result2.png

You can also refer docs.

View solution in original post

8 REPLIES 8

Not applicable

Hi @Vikaas,

This answer is only for the 1st point you have specified. You need to add security scheme (docs reference), in order to get Auth Type as API Key under Resource Summary. While adding security scheme, you can specify Type as ApiKey and the query param's name.

My Swagger spec already has the required security definition, should I again add the security scheme through smartdocs ?

You will need to choose one of them, either adding in swagger or adding security scheme. Both will work correct, but latter is preferable since it is out of box and will update the resource summary as you needed.

I have defined below section in my swagger (which works fine on swagger editor) :

...

securityDefinitions:
  apiKeyQuery:
    type: apiKey
    name: apikey
    in: query

but smartdocs resource summary shows - 'NoAuth'

After specifying securityDefinitions and security in swagger, add template auth settings for your API and specify an API key there. To add template settings follow: Content-> Smartdoc-> API Revisions-> Security Settings-> template auth settings.

@Neha Pamnani Not sure if I am missing something... But this is what i did,

1 . Created a smart-doc model

2. Added a new API revision by importing Swagger JSON

3. Modified the revision by setting the 'Auth Settings' with 'Custom Token' section with API Key

4. Edit API 'Method' and Set the authentication to CUSTOM --> Update Method

1644-authentication.png

But still i see that the 'Resource Summary' section displays 'No Auth':

1645-rs.png

Here is the build info of the portal :

Version: Developer Services 15.01.30.00

Not applicable

Hi @Vikaas,

I couldn't figure out what is going wrong. But you can find a similar issue stated here. I would suggest you to rather update the developer portal, since this functionality is working fine on my developer portal (build info version: 15.07.08.00). If you update the portal, then following steps can be helpful:

1. Create a model.

2. Import Swagger JSON.

3. Go to Content-> Smartdoc-> API Revisions-> Security Settings. If you have already specified securityDefinitions in swagger, then you will find it here. Else, you can add security scheme. Specify 'Type' as 'API Key'.

step3.png

4. To give value of API Key, go to: Content-> Smartdoc-> API Revisions-> Security Settings-> template auth settings. Specify the apikey to be used.

step4.png

5. Edit each method, and set authentication to API Key scheme.

step5.png

Now, the request will be sent along with header/query param containing predefined apikey, and resource summary will also get updated.

result1.png

result2.png

You can also refer docs.

Upgraded the Developer Portal to 15.12.11.01, now it seems to be working!!

Thanks @Neha Pamnani