No operations defined in spec! && Resolver error Cannot read properties of undefined (reading 'api') - node.js

I have this error in my node JS in swagger-ui-express I don`t know how to fix it
enter image description here
this is the code in the index.js file
in this code I`am tryin to call the json file that I make and call it swagger.json
const swaggerUi = require('swagger-ui-express'), swaggerDocument = require('./swagger.json')
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
that the pic of the beggin of the code
enter image description here
but I`am think that the error is here in this json file
"paths": {
"/api/category": {
"tages": [
"Category"
],
"summery": [
"Get all Categories"
],
"parameters": [
{
"name": "categoryName",
"in": "query",
"required": false,
"description": "Category name",
"type": "string"
},
{
"name": "page",
"in": "query",
"required": false,
"description": "Page Number",
"type": "integer",
"default": 1
},
{
"name": "PageSize",
"in": "query",
"required": false,
"type": "integer",
"default": 10
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
},
"post": {
"tages": [
"Category"
],
"summery": "Create Category API",
"parameters": [
{
"name": "categoryName",
"in": "formDate",
"descripition": "Category Name",
"required": true,
"type": "string"
},
{
"name": "CategoryDescription",
"in": "formDate",
"descripition": "Category Description",
"type": "string"
},
{
"name": "Category Image",
"in": "formDate",
"descripition": "Category Image",
"type": "file"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
}
},

There are some typos and syntax errors:
The "/api/category" path is missing the "get": node that would wrap the GET operation definition. It should look like this:
"paths": {
"/api/category": {
"get": {
"tags": ...
"tages" should be "tags".
"summery": [...] should be replaced with:
"summary": "Get all Categories",
"in": "formDate" should be "in": "formData" ("a" at the end).
"descripition" should be "description".
Paste your OpenAPI JSON into https://editor.swagger.io - it will show all errors.

Related

Why does this error pop up in the slash command thing?

this is the slash command:
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.commands['#0.0.0'].create({
"guild_id": "1018895233003569193",
"name": "submit-hw",
"description": "trimite tema",
"options": [
{
"type": 3,
"name": "materie",
"description": "",
"choices": [
{
"name": "romana",
"value": "romana"
},
{
"name": "mate",
"value": "mate"
},
{
"name": "religie",
"value": "religie"
},
{
"name": "engleza",
"value": "engleza"
},
{
"name": "franceza",
"value": "franceza"
},
{
"name": "desen",
"value": "desen"
},
{
"name": "sport",
"value": "sport"
},
{
"name": "biologie",
"value": "biologie"
},
{
"name": "fizica",
"value": "fizica"
},
{
"name": "tic",
"value": "tic"
},
{
"name": "istorie",
"value": "istorie"
},
{
"name": "chimie",
"value": "chimie"
},
{
"name": "consiliere",
"value": "consiliere"
},
{
"name": "sociala",
"value": "sociala"
},
{
"name": "optional",
"value": "optional"
},
{
"name": "tehnologica",
"value": "tehnologica"
},
{
"name": "geografie",
"value": "geografie"
},
{
"name": "muzica",
"value": "muzica"
}
],
"required": true
},
{
"type": 3,
"name": "deadline",
"description": "",
"required": true
},
{
"type": 3,
"name": "tema",
"description": "",
"required": true
}
]
});
and this is the error
It says:
Sorry, could not save you slash commands: Invalid Form Body: code 50035:
Can someone help me out? I wrote all of the command options in the ui text boxes, not as code. SO won't let me post this without more string of text thats not code and i have no idea what to type.....
Description is required for all slash commands and options, including subcommands and subcommand groups. Just a heads up, Error code 50035 would go into detail to show which part is causing an error, such as one of the options type being incorrect.

Bot Framework Composer does not seem to interpret "if" well in the schema

This schema is perfectly json-validated but does not work in Bot-Framework-Composer. To be exact, when "has" is "true" the "secondFace" object MUST be set, when "has" is "false" it must be absent.
The Bot Framework Composer validates correctly if "has" is true, while if "has" is "false" it continues to request to set the "secondFace" object. Is it a composer bug or is there anything to do, perhaps at the composer's form-UI level?
"hasSecondFace": {
"type": "object",
"title": "Has second face for comparison ?",
"additionaProperties": true,
"properties": {
"has": {
"type": "boolean",
"default": true,
"title": "Has Second Face",
"description": "If true ha second face else No"
},
"secondFace": {
"title": "Second face to be compared",
"additionalProperties": true,
"required": [
"type",
"param"
],
"oneOf": [
{
"type": "object",
"title": "From Storage",
"properties": {
"type": {
"const": "fromFile"
},
"param": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Storage key",
"description": "key name of the blob"
}
}
},
{
"type": "object",
"title": "image stream",
"properties": {
"type": {
"const": "fromKey"
},
"param": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Stream of second face",
"description": "Second face to compare"
}
}
}
]
}
},
"if": {
"properties": {
"has": { "const": true }
},
"required": [ "has" ]
},
"then": {
"required": [ "secondFace" ]
},
"else": {
"not": { "required": [ "secondFace" ] }
}
}
}

Unable to update the Knowledge in QnA maker

Unable to update the Knowledge in QnA maker whereas i am able to add the data to my Knowledge Base.Below is my update related REQUEST object
references: https://github.com/Azure-Samples/cognitive-services-qnamaker-java/blob/master/update-knowledge-base.java
{
"update": {
"qnaList": [
{
"id": 0,
"answer": "[92 Newcastle Court Roanoke, VA 24012](https://www.google.com/)",
"questions": [
"Where is Virginia located",
"What is the address of Roanoke",
"Roanoke address",
"Roanoke location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Roanoke"
},
{
"name": "type",
"value": "locationinfo"
}
]
},
{
"id": 1,
"answer": "[880 Oakwood St.Billerica, MA 01821](https://www.google.com/)",
"questions": [
"Where is Billerica located",
"What is the address of Billerica",
"Billerica address",
"Billerica location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Billerica"
},
{
"name": "type",
"value": "locationinfo"
}
]
}
]
}
}
and error response is:
{
"error": {
"code": 12,
"message": "Parameter is null",
"target": null,
"details": null,
"innerError": null
}
}
Your API call should be as below format.
More information can be found here
"update": {
"name": "QnA Maker FAQ Prompts Bot",
"qnaList": [
{
"id": 2,
"answer": "You can use our REST apis to create a KB. See here for details: https://learn.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase/create",
"source": "Custom Editorial",
"questions": {
"add": [],
"delete": []
},
"metadata": {
"add": [],
"delete": []
}
}
]
}

How to represent custom token in header in Swagger UI(swagger.json) in nodejs

I am creating a Restful server in ExpressJs. I have integrated swagger-jsdoc. Following is the related files. Below(header.png) is how I expect my header to look like in swagger UI. But, while I open my swagger UI (http://localhost:3000/api-docs/), I am not able to see Token tags (token and Authentication) in the header.
swagger.json
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Viswa API"
},
"host": "localhost:3000",
"basePath": "/api",
"tags": [{
"name": "Customers",
"description": "API for customers in the system"
}],
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
},
"JWT": {
"type": "apiKey",
"name": "token",
"in": "header"
}
},
"paths": {
"/customer": {
"post": {
"tags": [
"Customers"
],
"description": "Create new customer in system",
"parameters": [{
"name": "customer",
"in": "body",
"description": "Customer that we want to create",
"schema": {
"$ref": "#/definitions/Customer"
}
}],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "New customer is created",
"schema": {
"$ref": "#/definitions/Customer"
}
}
}
}
}
},
"definitions": {
"Customer": {
"required": [
"email"
],
"properties": {
"customer_name": {
"type": "string"
},
"customer_email": {
"type": "string"
}
}
}
}
}
app.route
var apiRoutes = express.Router();
app.use('/api', apiRoutes);
// swagger definition
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('../swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/v1', apiRoutes);
Current Swagger UI:
You are missing the security tag. You can define it either globally just below the securityDefinitions tag or one for each API endpoint.
Have a look at this question.
You can add a security tag
"security": [ { "Bearer": [] } ],
After adding it your path section
"paths": {
"/customer": {
"post": {
"security": [ { "Bearer": [] } ],
"tags": [
"Customers"
],
"description": "Create new customer in system",
"parameters": [{
"name": "customer",
"in": "body",
"description": "Customer that we want to create",
"schema": {
"$ref": "#/definitions/Customer"
}
}],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "New customer is created",
"schema": {
"$ref": "#/definitions/Customer"
}
}
}
}
}
},
You can define the header parameters in the path definition. like this
"paths": {
"/customer": {
parameters: [{ name: "Authorization", in: "header", type: "string", description: "auth token" }]
}
}

Missing Subscription Key field in Swagger API connector (trough Azure API Management) in Logic App

I have created a REST API with a Swagger/OPEN API specification which I will like to consume trough a Azure API Management tenant in a Logic App.
When I download the specification it looks like this:
{
"swagger": "2.0",
"info": {
"title": "Leasing",
"version": "1.0"
},
"host": "ENDPOINT.azure-api.net",
"basePath": "/leasing",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"apiKeyHeader": {
"type": "apiKey",
"name": "Ocp-Apim-Subscription-Key",
"in": "header"
},
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
},
"security": [
{
"apiKeyHeader": []
},
{
"apiKeyQuery": []
}
],
"paths": {
"/{Brand}/groups": {
"get": {
"description": "Get a list of leasing groups on a brand",
"operationId": "GetGroups",
"parameters": [
{
"name": "Brand",
"in": "path",
"description": "Selection of possible brands",
"required": true,
"type": "string",
"enum": [
"Volkswagen",
"Audi",
"Seat",
"Skoda",
"VolkswagenErhverv",
"Porsche",
"Ducati"
]
}
],
"responses": {
"200": {
"description": "Returns a list of leasing groups",
"schema": {
"$ref": "#/definitions/GroupArray"
}
},
"400": {
"description": "If the brand is not valid",
"schema": {
"$ref": "#/definitions/Error"
}
}
},
"produces": [
"application/json"
]
}
}
},
"definitions": {
"Group": {
"type": "object",
"properties": {
"id": {
"format": "int32",
"type": "integer"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"leasingModelCount": {
"format": "int32",
"type": "integer"
},
"lowestMonthlyFee": {
"format": "int32",
"type": "integer"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"enum": [
"NotValidBrand",
"NotValidGroupId"
],
"type": "string",
"x-ms-enum": {
"name": "ErrorCode",
"modelAsString": true
}
},
"message": {
"type": "string"
}
}
},
"GroupArray": {
"type": "array",
"items": {
"$ref": "#/definitions/Group"
}
}
}
}
When I add this in a Logic App with the connector HTTP + Swagger I only get to define the {Brand} query input but not the various ways of using the Subscriptions key (header or query) as defined in SecurityDefiniations.
The whole securityDefinitions and security section are automatically generated in the Azure API Management service, but not recognized in Logic App.
See image of missing subscription key field:
What am I doing wrong?
Update
I have tried the following:
Usage of the 'Authentication' field (but this field is limited to certain types of auths flows https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http#authentication)
Change the Logic App 'Http + Swagger'-action in code to add the header parameter, but this action converts the action to a simple 'Http' action and therfore loosing the automatic schema generation from Swagger.
I think you need to specify this in the Authentication-field in a JSON format. Something like:
{
"apiKeyHeader" : "your Ocp-Apim-Subscription-Key",
"apiKeyQuery" : "your subscription key"
}

Resources