How to hide server descriptions in Swagger UI? - yaml

I have an OpenAPI 3.0 definition with multiple servers:
servers:
- url: https://development.gigantic-server.com/v1
description: Development server
- url: https://staging.gigantic-server.com/v1
description: Staging server
- url: https://api.gigantic-server.com/v1
description: Production server
When this definition is rendered in Swagger UI, the "Servers" dropdown shows the description of each server:
Is it possible to hide the server descriptions from this dropdown?

Swagger UI always displays the server description if it's provided, this is hard-coded:
https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/oas3/components/servers.jsx#L125
As a workaround you can modify the API definition dynamically after it's loaded and remove server descriptions. To do that, edit your Swagger UI's swagger-initializer.js or index.html file and add the following onComplete function to the SwaggerUIBundle initialization code:
const ui = SwaggerUIBundle({
url: "https://path/to/your/openapi.json",
...
onComplete: function() {
let spec = ui.specSelectors.specJson().toJS();
let servers = spec.servers || [];
for (let i in servers) {
servers[i].description = ""
}
ui.specActions.updateJsonSpec(spec);
}
})

They haven't provided any option to replace this server's description in another place, but they have mentioned the description is optional in swagger specification of object representing a Server.
Swagger UI have not provided any rendering option for this.
The best use of description is define in a single word, like production, development, api, staging, etc..
If you really don't want in dropdown then you can remove it from your server list.
servers:
- url: https://development.gigantic-server.com/v1
- url: https://staging.gigantic-server.com/v1
- url: https://api.gigantic-server.com/v1
This part i am writing for your information, about how to use oas-servers,
I observed your server urls, these can be easily define in single url, how? using server variables.
servers:
- url: https://{environment}.gigantic-server.com/{version}
variables:
environment:
enum:
- 'development'
- 'staging'
- 'api'
version:
enum:
- 'v1'
Hope this help.

Related

How to generate API docs with openapi-generator.tech

I am playing around with https://openapi-generator.tech/ and I have an example openapi.yaml file:
openapi: 3.1.0
info:
title: Sample API
description: My amazing description.
version: 0.0.9
servers:
- url: http://localhost:8080/v1
description: My amazing server description.
paths:
/users:
get:
summary: Returns a list of all users.
description: My amazing /users endpoint description.
responses:
"200":
description: (OK) A JSON array of user objects.
content:
application/json:
schema:
type: array
items:
type: string
I have tried the following generation command:
openapi-generator-cli generate -g go-gin-server --global-property=apiDocs=true -i ./openapi.yaml
both with, and without the --global-property=apiDocs=true part. Neither case generated an /api, /doc, or /docs endpoint.
What am I doing wrong?
Note that the server runs fine, i.e., I can curl the endpoints specified in the yaml file.
It doesn't look like the server stub generator go-gin-server supports adding this type of endpoint. If you look at the routers template that this generator uses you can see that no config option will generate an /api, /doc or /docs endpoint unless you have defined it in your spec.
It's not clear to me exactly what you are expecting from this endpoint, but you could define one of these endpoints in your spec and implement the behavior you would like, or you could customize the template to automatically add this endpoint during code generation

Can i test cypress to capture signature from network tools

When i click on some url it triggers one signature url under Developer tools->network tools.
Can i use cypress to test anything which is triggered in Developer tools.
Did you take a look at Intercept command? You can grab just about any network request with it.
Most basic form:
cy.intercept({
method: 'GET',
url: '/users*',
hostname: 'localhost',
}).as('usersRequest')
cy.wait('#usersRequest')
.then(interception => {
// interception has similar data to Chrome devtools
})

nestjs + socket.io serving websockets from microservice at nested path instead of the root of the host always returns 404 Not Found

I'm using the socket.io implementation with nestjs. My overall in-production architecture is relying on a load balancer to route requests on paths to microservice containers.
One of them contains a websocket that interacts with user data and is nested on mydomain.com/apis/user
On my gateway I've configured it to use this path:
#WebSocketGateway({ path: "/apis/user/gateway", namespace: "/apis/user/gateway" })
and I've tried variations without the namespace there and with just the path.
I also have a global prefix: app.setGlobalPrefix("apis/user"); removing this makes no difference, it seems I need to define the path to the gateway either way prefix or not.
Then on the client I'm trying to just connect to it via either adding the path in the url, or to the options object, as such:
const endpoint = "https://example.com/apis/user/gateway";
socket = io(endpoint, {
secure: true,
path: "/apis/user/gateway",
});
This works for the path and handleConnection triggers on the gateway nested there, however configuring polling on the backend does not work, the client still throws:
https://example.com/apis/user/gateway/?EIO=4&transport=polling&t=NXVpMfB 404 Not Found
I had the same problem, all the various options are confusing. I got it sorted though, here is what worked:
For the nestjs:
#WebSocketGateway({
cors: {
origin: '*',
},
namespace: '/api/v1/ws',
path: '/api/v1/ws/socket.io',
})
For socket.io:
const newSocket = io("http://localhost:3000/api/v1/ws", {
path: "/api/v1/ws/socket.io",
});

How to get Strapi email plugins to show up in the config dropdown

I'm trying to configure a Strapi v3.0.0-alpha.19 server to be able to send emails, specifically for resetting forgotten passwords. It's difficult to find sufficient documentation for this, but what I've read in answers to questions like this one is that I need to install the provider package, e.g. strapi-provider-email-nodemailer, and then set the SMTP server (an instruction with the transparency of a brick). However, when I install the package within project-folder/strapi and then reload http://localhost:1337/admin/plugins/email/configurations/development, the dropdown for providers still only contains the default provider, Sendmail.
I've tried rebuilding the Strapi API within my Docker container, but that doesn't make any difference.
I would expect Nodemailer to appear in the dropdown after refreshing the page, or at least after rebuilding the API, but that isn't happening. What steps do I need to take in order to designate Nodemailer as my email provider?
In the newer Strapi versions, you also have to manually change the email provider in the email plugin settings, as the dropdown with email providers is not available anymore (https://github.com/strapi/strapi/pull/6195). I just did it with amazon-ses after hours of research and it worked. Don't know if it's the right way to do it, but it's for sure the only way I managed to find after a very long time.
Go to api/node_modules/strapi-plugin-email/config/settings.js and change the provider to the desired one.
You should probably change yours like this:
module.exports = {
provider: 'nodemailer',
providerOptions: {},
settings: {
defaultFrom: 'Strapi <no-reply#strapi.io>',
},
};
Considering you've added both strapi-email-nodemailer and strapi-provider-email-nodemailer, next step should be adding configurations.
To add configuration, add below code in plugin.js. If you don't have plugin.js, then create one in root config folder.
module.exports = ({ env }) => ({
email: {
provider: "nodemailer",
providerOptions: {
nodemailer_default_from: "default_from_email#example.com",
nodemailer_default_replyto: "default_replyto_email#example.com",
host: "smtp.gmail.com, // Add your smtp host over here
port: "995", // Add port number
password: "<below-email-password>,
username: "<email-address>",
authMethod: "SMTP", // Auth method
}
},
});
You can save above configurations in your environment file and use it from there.
To send an email programmatically, add below code in your controller:
await strapi.plugins['email'].services.email.send({
to: 'mail#example.com', // email recipient
from: 'sender#example.com', // email sender
subject: 'Email subject line',
text: 'Email body should come here'
});
Under extensions/email you can add a folder config and create the file settings.js, here you can configure this plugin
'use strict';
module.exports = {
provider: 'nodemailer',
providerOptions: {},
settings: {
defaultFrom: 'Name <name#email.com>',
},
};

Raven-js errors not getting "site" property in sentry, while python raven errors are?

I have three python clients and a javascript client (all raven) connecting to a single sentry server. I have a unique site set for each client. However, while errors generated by the three python clients have site properly set in the sentry interface, errors generated by the javascript client have no site set.
My raven-js setup (pardon my Django):
require(['lib/raven-1.0.7'], function(Raven){
Raven.config('{% sentry_public_dsn %}', {
// escapere is a custom tag, simply wraps python's re.escape
includePaths: [new RegExp('{{ request.build_absolute_uri|escapere }}')],
site: 'AJAX'
}).install();
Raven.setUser({
email: "{{ user.email|escapejs }}",
id: "{{ user.id|escapejs }}"
});
});
I did a little bit of digging in the sentry code (using the highly scientific scatter-some-logging-statements-around method), and I'm convinced that the "site" parameter is, indeed, being sent to the sentry API, but for some reason it's getting lost between there and creating the actual event Group.
It seems sentry is moving away from the site parameter in favor of tags. Upgrading to the latest master from the raven-js repo and changing
site: 'AJAX'
to
tags: {site: 'AJAX'}
Makes things behave as expected.

Resources