I have multiple API path for admin level APIs and for customer APIs, I have defined two route folders. I want to set two swaggerOptions, but Unfortunately it only read one of them but not both, how can I set both of them but different routes.
Customer Level:
const swaggeroption1: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Customer API",
version: "x.x.x",
description: "Customer level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server1",
},
],
},
apis: ["./routes/customer/*.ts"],
};
Admin Level:
const swaggeroption2: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Admin API",
version: "x.x.x",
description: "Admin level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server2",
},
],
},
apis: ["./routes/admin/*.ts"],
};
Any Idea, how to handle these, in a single file?
Related
Hi guys i'm works with swagger ui v2, and has a problem with organization.
The current structure of my project is like this.
const swaggerDocument = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Hello",
description: "hello",
},
basePath: "/api",
tags: [
{
name: "Users",
description: "API for users in the system",
},
],
schemes: [
"https",
"http",
],
consumes: [
"application/json",
],
produces: [
"application/json",
],
paths: {
"/users": {
// ...
},
},
definitions: {
User: {
// ...
},
},
};
In my path there are several routes (many actually) that reference my definitions, example: " $ref: "#/definitions/Users"," and my swagger.ts file is gigantic, I would like a better solution to organize, I tried something below but it didn't work.
swagger.ts
import { user, userDefinitions } from './user';
const swaggerDocument = {
paths: {
"/users": {
...user,
},
},
definitions: {
User: {
...userDefinitions,
},
},
};
Can someone help me?
User.ts
const user = {
"/users": {
...
},
};
const userDefinitions = {
User: {
properties: {
...
},
},
};
export { user, userDefinitions };
I would like to ask how to custom payload for carousel, image in other platforms like Facebook, Telegram and etc.
Information
DialogFlow API version: V2 API
Node version: v8.10.0
body-parser version: ^1.18.3
express: ^4.16.4
return res.json({
payload: {
google: {
expectUserResponse: true,
systemIntent: {
intent: "actions.intent.OPTION",
data: {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
carouselSelect: {
items: [{
optionInfo: {
key: "car",
synonyms: ["automobile", "vehicle"]
},
description: "A four wheel vehicle",
title: "Car"
},
{
optionInfo: {
key: "plane",
synonyms: ["aeroplane", "jet"]
},
description: "A flying machine",
title: "Plane"
}
]
}
}
},
richResponse: {
items: [{
simpleResponse: {
textToSpeech: "Category List"
}
}]
}
},
telegram: {
text: "Category list",
expectUserResponse: true,
systemIntent: {
intent: "actions.intent.OPTION",
data: {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
carouselSelect: {
items: [{
optionInfo: {
key: "car",
synonyms: ["automobile", "vehicle"]
},
description: "A four wheel vehicle",
title: "Car"
},
{
optionInfo: {
key: "plane",
synonyms: ["aeroplane", "jet"]
},
description: "A flying machine",
title: "Plane"
}
]
}
}
}
}
},
outputContexts: []
});
This is code snippet to return carousel response to Telegram and Google. It worked in google assistant but failed to display carousel list in Telegram. Only text "Category list" was displayed in Telegram.
Is there any mistake in the payload for Telegram? Could anyone provide guidance on this?
Option responses(such as Carousel and List) are response type of actions-on-google modules and it is created for Google Assistant. Every platform has different screen abilities so you can not use every response type for every platform. As far as I know, there is no carousel or list type supported by Telegram. You may consider to use different options. For more information you may check out :
Rich messages
i use Express-js and express graphQL module to create my endpoint and web service ;
i am looking for way to create custom response in graphQL my endpoint is simple
select books from database my response is
{
"data": {
"books": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}
}
but in need something like this
{
"result": "success",
"msg" : "list ...",
"data": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}
here is my bookType
const BookType = new GraphQLObjectType({
name: 'Book',
fields: () => ({
id: {type: GraphQLID},
name: {type: GraphQLString},
genre: {type: GraphQLString},
author_id: {type: GraphQLString},
author: {
type: AuthorType,
resolve(parent, args) {
return Author.findById(parent.author_id);
}
}
})
});
That's not a legal GraphQL response. As per section 7.1 of the spec, after describing the data, errors, and extensions: top-level keys:
... the top level response map must not contain any entries other than the three described above.
You might put this data into extensions; or make it an explicit part of your GraphQL API; or simply let "success" be implied by the presence of a result and the lack of an error.
I am using sails in my node js application. And want to implement swagger api documentation. And I follow Swagger Sails JS document. I got the result from my api doc. And my expected result from api doc . I have write the route in router.js file like below
'post /login': {
controller: 'user/UserController',
action: 'login',
skipAssets: 'true',
//swagger path object
"get": {
"tags": [
"Users"
],
"description": "Get a login user data",
"parameters": [{
"email": "abc#gmail.com",
"password": "12345678y",
"deviceToken": "12345678y",
"deviceType": 2
}],
"responses": {
"200": {
"statusCode": 0,
"status": true,
"message": "string",
"result": {}
}
}
}
}
If I had write wrong in my routes. Then how to write the routes, so that I will get my expected result from api docs?
Thanks!
You can try using this.
And I suppose router file should be like this:
'post /login': {
controller: 'user/UserController',
action: 'login',
skipAssets: 'true',
swagger: {
methods: ["get"],
tags: ["Users"],
description: "Get a login user data",
parameters: [{
email: "abc#gmail.com",
password: "12345678y",
deviceToken: "12345678y",
deviceType: 2
}],
responses: {
'200': {
statusCode: 0,
status: true,
message: "string",
result: {}
}
}
}
}
With swagger 2.0 spec, i'm describing an 'operation' to add new resources:
A POST request with 3 parameters:
{
name: "username",
in: "header",
description: "New user unsername",
required: true,
type: "string"
},
{
name: "password",
in: "header",
description: "New user password",
required: true,
type: "string"
},
{
name: "pensis",
in: "body",
description: "New pensis to create",
required: true,
schema: {
properties: {
content: {
type: "string",
description: "Content of this pensis stored as markdown text"
}
}
}
}
I setup the POST request with the 3 previous parameters:
username: "Bob",
password: "Yo!",
pensis: {
content: "The content"
}
I send the POST request, and when i parse it using swagger-tool metadata 0.8.6 middleware, i get a strange response :
The value of req.swagger.params.pensis.value provided by this middleware is not:
{ content: 'The content' }
but:
{ content: 'The content',
username: 'ClementVidal',
password: 'r'
}
Do you have any idea about why those 3 parameters are merged together inside the same pensis object ??
Thanks for your help
Clément Vidal