Swagger.json generating with incorrect case "type": "String" - swashbuckle.aspnetcore

In troubleshooting this problem we found that swagger.json contained incorrect case for
"type": "String"
in the generated code
"/api/FrameLookUp": {
"post": {
"tags": [
"Frame"
],
"operationId": "FrameLookup",
"consumes": [
"application/json-patch+json",
"application/json",
"text/json",
"application/*+json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "header",
"name": "Authorization",
"description": "access token",
"required": true,
"type": "String"
},
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/FrameRequest"
}
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/FrameResponse"
}
}
}
}
}
}
I have the following ISchemaFilter
public class SwaggerEnumFilter : ISchemaFilter
{
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
if (model == null)
throw new ArgumentNullException("model");
if (context == null)
throw new ArgumentNullException("context");
if (context.Type.IsEnum)
model.Extensions.Add(
"x-ms-enum",
new OpenApiObject
{
["name"] = new OpenApiString(context.Type.Name),
["modelAsString"] = new OpenApiBoolean(false)
}
);
}
}
What could be causing this?

It turned out to be that I was using
services.AddSwaggerGen(c =>
{
c.OperationFilter<AuthorizationHeaderParameterOperationFilter>();
and inside the class I had
Schema = new OpenApiSchema() { Type = "String" },
it should have had "string" as lower case.

Related

Can I define an extend field for response component Swagger?

Current, I use #/components/responses/Default response as reuseable properties for all api defines. But some API need to add more a field but not change default response format. So Can I reUse default response and add more field for response
{
"openapi": "3.0.3",
"path": {
"/login": {
"post": {
"responses": {
200: {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/responses/defaultResponse"
}
}
}
}
}
}
}
},
"components": {
"schemas" :{
"responseSchema": {
"type": "object",
"properties": {
"httpCode": { "type": "integer" },
"message": { "type": "string" }
}
}
},
"responses": {
"defaultResponse": { "$ref": "#/components/schemas/responseSchema" }
}
}
}
Above is my swagger spec. but with Login, if success I want to put more a field (token) to return token for client, Can I do it with this or have to manual define schema ?
In OpenAPI version 3, you do this with the allOf keyword. Detail document
{
"openapi": "3.0.3",
"info": {
"title": "Example",
"version": "1.0"
},
"paths": {
"/login": {
"post": {
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/responses/defaultResponse"
},
{
"type": "object",
"properties": {
"token": {
"type": "string"
}
}
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"responseSchema": {
"type": "object",
"properties": {
"httpCode": {
"type": "integer"
},
"message": {
"type": "string"
}
}
}
},
"responses": {
"defaultResponse": {
"$ref": "#/components/schemas/responseSchema"
}
}
}
}

Jira error when creating issue in node.js

The following code gives me the error "Invalid request payload. Refer to the REST API documentation and try again" when is executed and I dont know where the error is
const bodyData =
`"fields": {
"summary": "Summit 2019 is awesome!",
"issuetype": {
"name": "Task"
},
"project": {
"key": "PRB"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "This is the description.",
"type": "text"
}
]
}
]
}
}`;
fetch('https://mysite.atlassian.net/rest/api/3/issue', {
method: 'POST',
headers: {
'Authorization': `Basic ${Buffer.from('myemail#gmail.com:mytoken').toString('base64')}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
}).then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
}).then(text => console.log(text)).catch(err => console.error(err));
Problem
Your bodyData is not a valid json
Solution
Wrap it with {}
`{
fields: {
"summary": "Summit 2019 is awesome!",
"issuetype": {
"name": "Task"
},
"project": {
"key": "LOD"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "This is the description.",
"type": "text"
}
]
}
]
}
}
}`
P.S.
You would find this error if you would use JSON.stringify with an object instead of a string.
const bodyData = JSON.stringify(
{
fields: {
"summary": "Summit 2019 is awesome!",
"issuetype": {
"name": "Task"
},
"project": {
"key": "LOD"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "This is the description.",
"type": "text"
}
]
}
]
}
}
});

Using JSON descriptors how to define an array in gRPC?

I'm using JSON descriptors instead of proto format. Everithing works, unless the array of Todo. I need an array of Todos.
How define that? I put the "type": "array", but always return the error:
'Error: no such Type or Enum 'array' in Type .Todos'
My json file is like this:
const todo = {
"nested": {
"Services": {
"methods": {
"createTodo": {
"requestType": "Todo",
"requestStream": false,
"responseType": "Todo",
"responseStream": false
},
"readTodos": {
"requestType": "voidNoParam",
"requestStream": false,
"responseType": "Todos",
"responseStream": false
},
"readTodosStream": {
"requestType": "voidNoParam",
"requestStream": false,
"responseType": "Todo",
"responseStream": true
}
}
},
"Todo": {
"fields": {
"id": {
"type": "int32",
"id": 1
},
"text": {
"type": "string",
"id": 2
}
}
},
"Todos": {
"fields": {
"items": {
"type": "array",
"id": 1
}
}
},
"voidNoParam": {
"fields": {}
}
}
}
module.exports = todo
I found the problem, really simple.
"Todos": {
"fields": {
"items": {
"rule": "repeated",
"type": "Todo",
"id": 1
}
}
},

Error on deploying Smart Contract for Azure Blockchain Workbench

I have been Building a Voting App on Azure Blockchain Workbench.
I am constantly getting errors while uploading the smart contract file that the constructor and the functions are not present.The config file passed their checks though. Pls help out with the error.
This is from the Smart contract file:
pragma solidity >= 0.4.0 <0.6.0;
contract Voting{
enum StateType{
Creation,
Voting,
BallotFinish
}
StateType public State;
mapping(bytes32 => uint256) public votesCount;
address public admin;
bytes32[] public candidatesList;
bytes32[] public voterList;
constructor(bytes32[] memory candidateNames,bytes32[] memory voterNames) public{
State = StateType.Creation;
admin = msg.sender;
candidatesList = candidateNames;
voterList = voterNames;
}
function totalVotesFor(bytes32 candidate) public view returns (uint256)
{
require(validCandidate(candidate));
return votesCount[candidate];
}
function voteForCandidate(bytes32 voter,bytes32 candidate) public {
if(admin == msg.sender)
{
revert();
}
if(State == StateType.Voting)
{
require(validVoter(voter));
require(validCandidate(candidate));
votesCount[candidate] += 1;
}
else
{
revert();
}
}
function validVoter(bytes32 voter) public view returns (bool) {
for(uint i=0;i<voterList.length;i++)
{
if(voterList[i]==voter)
return true;
}
return false;
}
function validCandidate(bytes32 candidate) public view returns (bool) {
for(uint i=0 ; i < candidatesList.length ; i++)
{
if(candidatesList[i]==candidate)
return true;
}
return false;
}
}
This is the config file:
{
"ApplicationName": "Voting",
"DisplayName": "Voting",
"Description": "Test Voting App",
"ApplicationRoles": [
{
"Name": "Admin",
"Description": "Person who generates Candidate and Voter Lists"
},
{
"Name": "Voter",
"Description": "A person who votes"
}
],
"Workflows": [
{
"Name": "Voting",
"DisplayName": "Vote Here",
"Description": "A simple way to vote.",
"Initiators": [ "Admin" ],
"StartState": "Creation",
"Properties": [
{
"Name": "State",
"DisplayName": "State",
"Description": "Holds the state of the contract.",
"Type": {
"Name": "state"
}
}
],
"Constructor": {
"Parameters": [
{
"Name": "candidateNames",
"Description": "List of names of candidates",
"DisplayName": "ListOfCandidates",
"Type":
{
"Name": "array",
"ElementType": {
"Name": "string"
}
}
},
{
"Name": "voterNames",
"Description": "List of names of voters",
"DisplayName": "ListOfVoters",
"Type":{
"Name": "array",
"ElementType": {
"Name": "string"
}
}
}
]
},
"Functions": [
{
"Name": "totalVotesFor",
"DisplayName": "Get Votes for a Candidate",
"Description": "...",
"Parameters": [
{
"Name": "candidate",
"Description": "...",
"DisplayName": "Name of Candidate",
"Type": {
"Name": "string"
}
}
]
},
{
"Name": "voteForCandidate",
"DisplayName": "Vote Function",
"Description": "...",
"Parameters": [
{
"Name": "voter",
"Description": "...",
"DisplayName": "Name of Voter",
"Type": {
"Name": "string"
}
},
{
"Name": "candidate",
"Description": "...",
"DisplayName": "Name of Candidate",
"Type": {
"Name": "string"
}
}
]
}
],
"States": [
{
"Name": "Creation",
"DisplayName": "Ballot Creation",
"Description": "...",
"PercentComplete": 20,
"Style": "Success",
"Transitions": [
{
"AllowedRoles": ["Voter"],
"AllowedInstanceRoles": [],
"Description": "...",
"Function": "voteForCandidate",
"NextStates": [ "Voting" ],
"DisplayName": "Give Vote"
},
{
"AllowedRoles": ["Voter"],
"AllowedInstanceRoles": [],
"Description": "...",
"Function": "totalVotesFor",
"NextStates": [ "Voting" ],
"DisplayName": "Get No of Votes"
}
]
},
{
"Name": "Voting",
"DisplayName": "Voting Stage",
"Description": "...",
"PercentComplete": 20,
"Style": "Success",
"Transitions": [
{
"AllowedRoles": ["Voter"],
"AllowedInstanceRoles": [],
"Description": "...",
"Function": "totalVotesFor",
"NextStates": [ "Voting" ],
"DisplayName": "Vote for a Candidate"
}
]
},
{
"Name": "BallotFinish",
"DisplayName": "Voting Finished",
"Description": "...",
"PercentComplete": 100,
"Style": "Success",
"Transitions": []
}
]
}
]
}
Your sol file needs to have a constructor for the contract as specified in the json file.
I think you need to change the byte32 to string and use StringUtil for comparision of strings

No result returned from the nest c# elasticsearch query

I am indexing an attachment field. The POST query in sense returns expected resultset.
My query is
POST /mydocs/_search
{
"query" : {
"bool" : {
"must" : [
{ "match" : { "file.content":"abc"} },
{ "match":{"otherDetails":"asd"}},
{ "match" : { "filePermissionInfo.accountValue" : "xyz"} }
]
}
}
}
I need to convert it to a c# Nest code. I tried converting it, but its not returning any result,even it contains data. If I remove the
m.Match(mt1 => mt1.Field(f1 => f1.File.Coontent).Query(queryTerm))
from the below experssion, it returns a result set. Is there any problem with the attachement field?
client.Search<IndexDocument>(s => s
.Index("mydocs")
.Query(q => q
.Bool(b => b
.Must(m =>
m.Match(mt1 => mt1.Field(f1 => f1.File.Coontent).Query(queryTerm)) &&
m.Match(mt2 => mt2.Field(f2 => f2.FilePermissionInfo.First().SecurityIdValue).Query(accountName)) &&
m.Match(mt3 => mt3.Field(f3 => f3.OtherDetails).Query(other))
)))
);
My mapping is
{
"mydocs": {
"mappings": {
"indexdocument": {
"properties": {
"docLocation": {
"type": "string",
"index": "not_analyzed",
"store": true
},
"documentType": {
"type": "string",
"store": true
},
"file": {
"type": "attachment",
"fields": {
"content": {
"type": "string",
"term_vector": "with_positions_offsets",
"analyzer": "full"
},
"author": {
"type": "string"
},
"title": {
"type": "string",
"term_vector": "with_positions_offsets",
"analyzer": "full"
},
"name": {
"type": "string"
},
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"keywords": {
"type": "string"
},
"content_type": {
"type": "string"
},
"content_length": {
"type": "integer"
},
"language": {
"type": "string"
}
}
},
"filePermissionInfo": {
"properties": {
"fileSystemRights": {
"type": "string",
"store": true
},
"securityIdValue": {
"type": "string",
"store": true
}
}
},
"id": {
"type": "double",
"store": true
},
"lastModifiedDate": {
"type": "date",
"store": true,
"format": "strict_date_optional_time||epoch_millis"
},
"otherDetails": {
"type": "string"
},
"title": {
"type": "string",
"store": true,
"term_vector": "with_positions_offsets"
}
}
}
}
}
}
It looks like the query hasn't been translated to NEST correctly. In the query you have
"filePermissionInfo.accountValue"
but in the NEST query, you only have
f2 => f2.FilePermissionInfo
which would result only in filePermissionInfo. You need to change this to
f2 => f2.FilePermissionInfo.AccountValue

Resources