I'm using Swashbuckle to generate documentation for my ASP MVC Web API. Everything works great, except documentation to JsonResult. Here is an example. I have a test class:
public class Test
{
public string Testing { get; set; }
}
and method in controller:
[HttpGet]
public JsonResult<Test> GetTest()
{
Test test = new Test { Testing = "testing json" };
return Json(test);
}
Based on this configuration, Swagger generates example value:
{
"Content": {
"Testing": "string"
},
"SerializerSettings": {
"ReferenceLoopHandling": 0,
"MissingMemberHandling": 0,
"ObjectCreationHandling": 0,
"NullValueHandling": 0,
"DefaultValueHandling": 0,
"Converters": [{
"CanRead": true,
"CanWrite": true
}
],
"PreserveReferencesHandling": 0,
"TypeNameHandling": 0,
"MetadataPropertyHandling": 0,
"TypeNameAssemblyFormat": 0,
"TypeNameAssemblyFormatHandling": 0,
"ConstructorHandling": 0,
"ContractResolver": {},
"EqualityComparer": {},
"ReferenceResolver": {},
"ReferenceResolverProvider": {
"Method": {},
"Target": {}
},
"TraceWriter": {
"LevelFilter": 0
},
"Binder": {},
"SerializationBinder": {},
"Error": {},
"Context": {
"m_additionalContext": {},
"m_state": 1
},
"DateFormatString": "string",
"MaxDepth": 0,
"Formatting": 0,
"DateFormatHandling": 0,
"DateTimeZoneHandling": 0,
"DateParseHandling": 0,
"FloatFormatHandling": 0,
"FloatParseHandling": 0,
"StringEscapeHandling": 0,
"Culture": "string",
"CheckAdditionalContent": true
},
"Encoding": {
"m_codePage": 0,
"dataItem": {
"m_dataIndex": 0,
"m_uiFamilyCodePage": 0,
"m_webName": "string",
"m_headerName": "string",
"m_bodyName": "string",
"m_flags": 0
},
"m_isReadOnly": true,
"encoderFallback": {
"bIsMicrosoftBestFitFallback": true
},
"decoderFallback": {
"bIsMicrosoftBestFitFallback": true
}
},
"Request": {}
}
Which is incorrect. I don't want a documentation for JsonResult, but only for my Test class. How can I change that? How can I tell Swagger to prepare documentation only for Test class?
An option is be to use SwaggerResponse take a look at this sample:
[SwaggerResponse(400, "Bad request")]
public class SwaggerAnnotatedController : ApiController
{
[SwaggerResponseRemoveDefaults]
[SwaggerResponse(HttpStatusCode.Created, Type = typeof(int))]
[SwaggerResponse(HttpStatusCode.BadRequest, "Invalid message", typeof(HttpError))]
public int Create(Message message)
{
throw new NotImplementedException();
}
Here is a link to the project:
https://github.com/domaindrivendev/Swashbuckle/blob/5489aca0d2dd7946f5569341f621f581720d4634/Swashbuckle.Dummy.Core/Controllers/SwaggerAnnotatedController.cs#L15
Related
I wanted to create ECS task that takes all json as its environment input. But my cdk code won't deploy because of following error message, the error message is so vague and it is difficult for me to figure out why my code is wrong.
Failed to call Step Functions for request: 'com.amazonaws.services.stepfunctions.model.CreateStateMachineRequest'. (Service: null; Status Code: 500; Error Code: null; Request ID: null)
new StateMachine (/local/home/miae/Explanation/src/ForecastingDeepLearningExplanationInfrastructure/node_modules/#aws-cdk/aws-stepfunctions/lib/state-machine.ts:101:26)
My cdk code
...
const ecsFargateTask = new sfn.Task(this, 'myEcs', {
inputPath: "$",
resultPath: "$.ecs",
task: new class implements sfn.IStepFunctionsTask {
bind(): sfn.StepFunctionsTaskConfig {
return {
resourceArn: "arn:aws:states:::ecs:runTask.sync",
parameters: {
"LaunchType": "FARGATE",
"Cluster": props.cluster.clusterArn,
"TaskDefinition": taskDefinition.taskDefinitionArn,
"Overrides": {
"ContainerOverrides": [{
"Name": "myContainer",
"Environment.$": "$.envs"
}]
}
}
};
}
}
});
}
const chain = sfn.Chain.start(ecsFargateTask);
new sfn.StateMachine(this, `StateMachineCopy${props.stage}`, {
definition: chain,
timeout: cdk.Duration.seconds(3000)
});
This is the Step function I want, and I could manually create this without problem.
{
"StartAt": "ExplanationEcs",
"States": {
"ExplanationEcs": {
"End": true,
"InputPath": "$",
"Parameters": {
"LaunchType": "FARGATE",
"Cluster": "arn:aws:ecs:us-west-2:123456789:cluster/myCluster482E02CC-1VWQ5XRG4II88",
"TaskDefinition": "arn:aws:ecs:us-west-2:123456789:task-definition/myTaskDefinitionE3E6548C:3",
"Overrides": {
"ContainerOverrides": [
{
"Name": "myContainer",
"Environment.$": "$.envs"
}
]
}
},
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"ResultPath": "$.ecs"
}
},
"TimeoutSeconds": 3000
}
I am unable to insert multiple rows in database using Post method in MVC web API. I have written code for it but when i am testing by inserting multiple rows through postman it is giving error. At line first the variable "delegatetable" shows null due to which error is coming. i am not doing database connection through entity framework, i have created a DelegateTable class.
public HttpResponseMessage Post(List<DelegateTable> delegatetable)
{
try
{
using (var delegateContext = new ShowContext())
{
foreach (DelegateTable item in delegatetable)
{
DelegateTable delegates = new DelegateTable();
delegates.Salutation__c = item.Salutation__c;
delegates.First_Name__c = item.First_Name__c;
delegates.Last_Name__c = item.Last_Name__c;
delegates.Account_Name__c = item.Account_Name__c;
delegates.Contact_Email__c = item.Contact_Email__c;
delegates.Category__c = item.Category__c;
delegates.Conference_Type__c = item.Conference_Type__c;
delegates.Conference_Selection__c = item.Conference_Selection__c;
delegates.Payment_Statuss__c = item.Payment_Statuss__c;
delegates.Barcode__c = item.Barcode__c;
delegateContext.SaveChanges();
}
var message = Request.CreateResponse(HttpStatusCode.Created, delegatetable);
message.Headers.Location = new Uri(Request.RequestUri.ToString());
return message;
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Json data that i am passing is below
[
{
"attributes": {
"type": "Registration__c",
"url": "/services/data/v43.0/sobjects/Registration__c/a3h8E0000009VuVQAU"
},
"Salutation__c": "Dr.",
"First_Name__c": "Test",
"Last_Name__c": "Test",
"Account_Name__c": "Test",
"Contact_Email__c": "test123#gmail.com",
"Category__c": "Test",
"Conference_Type__c": null,
"Conference_Selection__c": null,
"Payment_Statuss__c": null,
"Barcode__c": "Test"
},
{
"attributes": {
"type": "Registration__c",
"url": "/services/data/v43.0/sobjects/Registration__c/a3hD0000001kEfOIAU"
},
"Salutation__c": "Mr.",
"First_Name__c": "Demo",
"Last_Name__c": "Demo",
"Account_Name__c": "Demo",
"Contact_Email__c": "Demo#gmail.com",
"Category__c": "Demo",
"Conference_Type__c": null,
"Conference_Selection__c": null,
"Payment_Statuss__c": null,
"Barcode__c": null
}
]
You may try to reformat your payload as a JSON array, as the problem might be that the payload cannot be converted to a List.
Try this:
{
"delegates" :
[
{
"attributes": ..., ...
},
{ "attributes": ..., ...
},
...
]
}
I am trying to hide columns for the records which are having null or zero values in the row, for this I am using filter method achieve. But for some reason filter function is not calling.
Below is the data sample,
[
{
"cs": 1000,
"DateTime": "02/06/2015",
"subject": "lect",
"math": 1777.655,
"politics": 0.88
},
{
"cs": null,
"DateTime": "02/07/2015",
"subject": "lect",
"math": 344,
"politics": 0.99
},
{
"cs": null,
"DateTime": "02/08/2015",
"subject": "lect",
"math": 920.304,
"politics": 0.777
},
]
Here is the my custom aggregators function and pivotable configuration, where in filter is called.
pivotUI configuration
.pivotUI( {
rows: ["subject"],
cols: ["DateTime"],
aggregators: {
"math": successRate,
"politics": successRate2,
"cs":successRate3
},
hiddenAttributes: ['Date'],
})
Custom aggregator function
var successRate3 = function() {
return function() {
return {
sumSuccesses: "",
sumTrials: 0,
push: function(record) {
if (!isNaN(parseFloat(record['cs'])) && record['cs'] !== null) {
this.sumSuccesses = parseFloat(record['cs']);
}
},
value: function() { return this.sumSuccesses },
format: function(x) { return x; },
filter: function(record){ return record["cs"] > 0; },
rendererName: "TABLE",
numInputs: 0
};
};
};
I’ve got a question I can’t seemingly resolve on my own.
Together with basic Query, Mutation and so on types I’ve made the following type definition:
module Types
UserType = GraphQL::ObjectType.define do
name 'User'
description 'A user'
implements GraphQL::Relay::Node.interface
global_id_field :id
field :email, !types.String, 'Email address'
connection :docs, DocType.connection_type, 'Available docs'
end
end
And I then try to query it with:
query FileListQuery(
$after: String
$first: Int
) {
viewer {
currentUser {
docs(first: $first, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
And I pass the following as query variables:
{
"first": 1,
"after": null
}
The problem is it bails out with the following:
{
"errors": [
{
"message": "Int isn't a defined input type (on $first)",
"locations": [
{
"line": 3,
"column": 3
}
],
"fields": [
"query FileListQuery"
]
}
]
}
I honestly have no clue why it complains about the Int type…
If I get rid of the problematic $first query variable in the request, it works fine.
This:
query FileListQuery(
$after: String
) {
viewer {
currentUser {
docs(first: 10, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
Produces this:
{
"data": {
"viewer": {
"currentUser": {
"docs": {
"edges": [
{
"node": {
"id": "1",
"name": "First Doc",
"__typename": "Doc"
},
"cursor": "MQ=="
}
],
"pageInfo": {
"endCursor": "MQ==",
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "MQ=="
}
},
"id": "1"
},
"id": "VIEWER"
}
}
}
Any hints, ideas on how to fix this? I use the graphql gem v1.6.3.
Currently, there seems to be a bug in graphql-ruby that prevents types not explicitly used in a schema from being propagated. Check out this issue on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/788#issuecomment-308996229
To fix the error one has to include an Int field somewhere in the schema. Turns out I haven't had one. Yikes.
This fixed it for me:
# Make sure Int is included in the schema:
field :testInt, types.Int
I'm new to swagger documentation. We have an existing project developed in progress language for RESTFul Web Services. The different resource based urls consumes and produces in application/json format. The input and output json formats for one of our resource url is given below:
Request:
{
"request": {
"companyNumber": 5000,
"operatorInit": "sys",
"operatorPassword": "",
"customerNumber": 101,
"shipTo": "",
"warehouse": "01",
"productCode": "2-001",
"crossReferenceFlag": false,
"retrieveFlag": false,
"tInbinlocation": {
"t-inbinlocation": [
{
"binloc": "",
"icswbinloc1fl": false,
"icswbinloc2fl": false,
"addrecordfl": false,
"deleterecordfl": false,
"charuser": "",
"user1": "",
"user2": "",
"user3": "",
"user4": "",
"user5": "",
"user6": 0,
"user7": 0,
"user8": null,
"user9": null
}
]
},
"tInfieldvalue": {
"t-infieldvalue": [
{
"level": "",
"lineno": 0,
"seqno": 0,
"fieldname": "",
"fieldvalue": ""
}
]
}
}
}
Response:
{
"response": {
"cErrorMessage": "",
"crossReferenceProduct": "2-001",
"crossReferenceType": "",
"tOutbinlocation": {
"t-outbinlocation": []
},
"tOutfieldvalue": {
"t-outfieldvalue": []
}
}
}
How to convert above request and response json formats into swagger 2.0 json format?
Thanks!
Try using api-spec-converter.
this tool supports converting API descriptions between popular formats.
Supported formats:
* swagger_1
* swagger_2
* api_blueprint
* io_docs
* google
* raml
* wadl