Swagger (#Schema(required = true)) override the javax.validation message - swagger

We have introduced swagger to our existing spring rest application. We already had javax.validation's #NotNull to validate the payload, which was working fine.
After we introduce Swagger 3, we used #Schema(required = true) along with #NotNull. Now the Swagger override's the error message of javax.validation.
Before swagger: "XXX must not be null" which was generated by javax.validation.
After swagger : Missing required creator property 'XXX'.
Is it possible to disable swagger validation?
Thanks in advance

Related

Delete unused generated ResponseEntityReq schema in swagger apidoc or in swagger ui

I tried adding the ResponseEntity as a response to my endpoint
#ApiResponse(responseCode = "200", description = "Success", content = {#Content(mediaType = "application/json", schema = #Schema(implementation = ResponseEntity.class))})
But in my apidoc I was getting
Error-ModelName{namespace='org.springframework.http', name='ResponseEntity'}
under my response section.
After some digging the solution I found was adding that model in my bean
.additionalModels(
typeResolver.resolve(ResponseEntity.class)
)
And I was able to get the correct schema for ResponseEntity called ResponseEntityRes, but now swagger had generated another schema ResponseEntityReq.
This has nothing in it and I don't need this schema, so is there a way to remove this from the apidoc or better way to appraoch the Error-ModelName problem?
My swagger ui. I don't need this ResponseEntityReq schema:

Create team from group fails with exception

I created teams in Microsoft Teams (from groups as documented here) via the C# graph-api sdk without any problems - everything was working just fine.
But suddenly this is not working anymore. I will always get the following exception at the line return await graphServiceClient.Teams.Request().AddAsync(team);:
Message: Failed to execute Templates backend request
CreateTeamFromGroupWithTemplateRequest. Request Url:
https://teams.microsoft.com/fabric/emea/templates/api/groups/theGroupId/team,
Request Method: PUT,
And further:
Team Visibility can not be specified as it is inherited from the
group.
I know that the visibility property must not be set if creating the team from a group as it states in the Microsoft documentation:
The team that's created will always inherit from the group's display name, visibility, specialization, and members. Therefore, when making this call with the group#odata.bind property, the inclusion of team displayName, visibility, specialization, or members#odata.bind properties will return an error.
But the currently used code below shows that I am not setting any forbidden properties - and this code worked for the last few days, too:
private async Task<Team> CreateTeamFromGroup(string groupId)
{
var graphServiceClient = [...]
var groupResourceLink = $"https://graph.microsoft.com/v1.0/groups('{groupId}')";
var team = new Team
{
AdditionalData = new Dictionary<string, object>()
{
{ "template#odata.bind", "https://graph.microsoft.com/beta/teamsTemplates('standard')" },
{ "group#odata.bind", groupResourceLink }
},
Channels = new TeamChannelsCollectionPage
{
new Channel
{
DisplayName = "WhatEver"
}
}
};
return await graphServiceClient.Teams.Request().AddAsync(team);
}
Is anyone else experiencing this problem? Was there an API change? Was the teams backend changed? Anyone any ideas?
P.S.: I am using the latest NuGet-Package for Microsoft Graph - downgrading didn't help.
Update (with a not very satisfying work-around)
The error can be reproduced via the graph api explorer, too.
The POST command above issues a PUT command, that is described here. With this request, the team can be created.
The documentation and the graph api snippet for C# is out-dated, though. You have to add odatatype = null to the properties when using the sdk
Unfortunately it is not possible to add channels in the same step. If you specify the property 'channels' it will just be ignored.
Update (Detailed error message)
System.AggregateException: 'One or more errors occurred. (Code:
BadRequest Message: Failed to execute Templates backend request
CreateTeamFromGroupWithTemplateRequest. Request Url:
https://teams.microsoft.com/fabric/emea/templates/api/groups/theGroupId/team,
Request Method: PUT, Response Status Code: BadRequest,
ErrorMessage : {"errors":[{"message":"Team Visibility can not be
specified as it is inherited from the
group."}],"operationId":"639448e414ece64caee8f52839585bf7"} Inner
error: AdditionalData: date: 2020-11-24T10:21:22 request-id:
37a28cac-3ac5-4bd2-a061-daf44c442fac client-request-id:
37a28cac-3ac5-4bd2-a061-daf44c442fac ClientRequestId:
37a28cac-3ac5-4bd2-a061-daf44c442fac )'
Just tested this morning and I can say, that the "old way" by using the beta API to create a team with a template works again. Don't know, how many other ways exist to do these things, but here is our current request, that works now (again).
POST https://graph.microsoft.com/beta/teams
{
"displayName": "My Group Name",
"description": "Some description",
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"owners#odata.bind": [
"https://graph.microsoft.com/beta/users('<someValidUserId>')"
]
}
I think this will be just an intermediate state and when the bugs are fixed, they will publish the new version again and this kind of creation will fail again, but if in this case the v1.0 documented way will work this wouldn't be a big problem. But being informed BEFORE there roll-out starts would be great.
This was a Microsoft issue/ bug and is currently being fixed as stated here.

Mask input (example - password) in Swagger UI?

I have three path variables for an API. I want to mask one input on Swagger UI with *****.
How can I do this when using Springdoc OpenAPI?
You just use the swagger annotations:
#Parameter(schema = #Schema(type = "string", format = "password"))
As already shown by jenkinsme in their answer, set the format to password. Also, the type field is not needed as it defaults to string (hopefully all passwords are strings).
#Parameter(schema = #Schema(format = "password"))
The above will show up as shown in the below image
Refer the OpenAPI specification page on Data Types for all the supported types

WSDL service reference giving error

I am using a doc data payments gateway service and when I try to give it a request to create an order it throws the following exception:
XmlSerializer attribute
System.Xml.Serialization.XmlAttributeAttribute is not valid in
version. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and
XmlAnyElement attributes are supported when IsWrapped is true.
I don't think it is an exception that has anything to do with the service. What am I doing wrong on my side of implementation. Can anyone help me with that?
EDIT
I have used DocDataPayments gateway and used the wsdl refrence they give to make the call.
The create call I am making is as follows:-
PaymentServiceSOAPClient client = new PaymentServiceSOAPClient();
createSuccess success = new createSuccess();
client.create(merchant, strMTID, paymentPreferences, menuPreferences, shopper, totalGrossAmount, billTo, "description", "Thanks for your purchase", true, new paymentRequest(), new invoice(), new technicalIntegrationInfo(), Convert.ToDecimal(0.9), out success);
I think, you are using wcf default serializer to make proxy classes.you can try with DataContract serializer instead default serializer.

Swagger UI error: Unable to fetch API Listing

I'm documenting a REST web API with Swagger. I've downloaded the petstore example. It consists of the resources.json which references pet.json and user.json:
{
"apiVersion":"0.2",
"swaggerVersion":"1.0",
"basePath":"http://petstore.swagger.wordnik.com/api",
"apis":
[
{
"path":"/pet.{format}",
"description":"Operations about pets"
},
{
"path":"/user.{format}",
"description":"Operations about user"
}
]
}
But even after uploading the original files to my web server, Swagger UI tells me:
Unable to fetch API Listing. Tried the following urls:
http://www.myserver.org/resources.json
http://www.myserver.org
http://www.myserver.org/resources.json
http://www.myserver.org/resources
Can you tell what causes Swagger not find my json file?
I'm assuming you're going to www.myserver.org and it brings up the swagger ui? In the "Explore" textbox in the Swagger UI... be sure to type in the location of your resources.json.
I personally have my swagger api documentation set up this way...
http://adamclerk.com/api --Swagger UI
http://adamclerk.com/api/doc --returns json representing resources.js
http://adamclerk.com/api/doc/donuts --returns json representing donut operations
you can checkout a more detailed explaination here - Swagger With Static Documentation
If you have any more questions feel free to ask.

Resources