Is there a way to remove the input field below value? I would like to keep (required)
I am not using using the Try Out button either. It would be nice to get rid of it as well; however, I am not seeing the option in the JSON.
UPDATE
I tried the following code, but no avail:
"paths": {
"/login": {
"post": {
"summary": "Test",
"description": "Test API.",
"parameters": [
{
"name": "email",
"supportedSubmitMethods": [],
"in": "body",
"description": "email address",
"required": true,
"type": "string",
"format": "email address"
},
Not sure if that's the right place to put supportedSubmitMethods.
Have a look to this Swagger-ui discussion on the subject here, which references the following Swagger ui parameters.
You could use supportedSubmitMethods empty array to disable the Try it out functionality, but this does not remove it from the page:
An array of the HTTP operations that will have the 'Try it out!'
option. An empty array disables all operations. This does not filter
the operations from the display
To remove it from DOM, you could add some JS to place the textarea with text, and remove the try it out button.
You can also just use display: none on the CSS class "submit" (used on all try it out buttons).
Related
I have used description to add details for query parameter like
"parameters": [
{
"name": "role",
"in": "query",
"required": true,
"schema": {
"type": "string"
},
"description": "This is test description to reproduce placeholder not fit to textbox"
}]
When I load openapi.json to swagger it shows description as well as in text box placeholder. Is there any way to add separate text for placeholder or any way to fix show all text in placeholder? Here text is stripped
If the parameter has an example or default value (or x-example in OpenAPI 2.0), Swagger UI will use this value as a placeholder instead.
Otherwise, as you've noticed, the placeholder text will be the same as the parameter's description.
There's an existing feature request to remove or improve the default placeholder text:
https://github.com/swagger-api/swagger-ui/issues/3920
I have a REST endpoint that returns a body that looks like this:
"posts": [
{
"message": "This is another message",
"created": "2019-12-27 21:33:54+10",
"items": [...],
"tags": [...],
"toot_id": "12345"
},
{
"message": "This is a message",
"created": "2019-12-26 20:42:15+10",
"items": [...],
"tags": [...],
"toot_id": "12344"
}
]
I want to extract just the message and toot_id fields and use a "Choose from List" action to display the message text, and upon selection pass the corresponding toot_id of the chosen message to the next action. Unfortunately I'm greatly struggling with how to do this... I know Javascript and TypeScript and can handle this sort of thing in those languages with no problems, but iOS's Shortcuts app is thwarting me. I've got as far as a "Repeat with each item" with the posts key as a result of hitting my REST endpoint, but I'm stuck as to how to continue from there, and I'm not clear on whether I should be setting the various actions inside the loop to "as Text" or "as Dictionary" either.
Thanks!
This is a screenshot of how I got it to work in a similar situation.
The key for me was the combination of "Get dictionary from Input" (use the variable), "Set Dictionary Value", and then "Set Variable". Trying to do "Set Dictionary Value" on the variable directly (in one step) never worked.
I've got a POST endpoint described in Swagger and I want that endpoint to also have query parameters. We're using 1.2 swagger format because, well, legacy reasons. We use 3scale, it hosts the documents and you edit your swagger in their web UI. However, when I try to save the document it gives me the following error.
JSON Spec can not have paramType='body' and paramType='query' on the same method
I can't find anything in the swagger specs that says this is an actual limitation. Is this likely something specific to 3Scale or is this a general swagger limitation? And if the latter, can someone point me at a spec is that clarifies it?
The actual REST endpoint doesn't care, it's happy with query params on a POST. It's just getting the Swagger tool to be happy. Here's the abbreviated snippet of the swagger doc:
{
"parameters": [
{
"name": "myQueryParam",
"dataType": "string",
"paramType": "query",
"required": true
},
{
"name": "body",
"dataType": "string",
"paramType": "body",
"required": true
}
],
"httpMethod": "POST"
}
not sure if the error message is a generic validation error, but there a couple of error in the specification you shared:
it is "method" and not "httpMethod"
it is "type" and not "dataType"
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md
The following example works for me, but I use required=false:
{
"in": "query",
"name": "myQueryParam",
"required": false,
"type": "string"
}
See also Swagger parameters in query and/or body
I'm building a very small e-commerce website for selling customizable jewels, so I have a graphical configurator that lets you design the jewel and then you can add it to the cart. The product should have a custom field in JSON format that contains the item configuration. I see that Snipcart has data-item-custom{x} fields, but is populated only with dropdowns... is not suitable for me.
Do you think I can handle this situation with Snipcart? Can I simply update via JS the HTML data-item- fields content? Or add the item to the cart via JS?
addToCart({
name: 'Bracelet 1',
customField1: 'JSON HERE'
})
There's a Javascript API available for Snipcart.
It does allow to add product dynamically, however, the syntax for custom fields is slightly different. The example from the doc for Snipcart.api.items.add show how to use custom fields (removed unused fields for brevity):
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"name": "Memory size",
"options": "16GB|32GB[+50.00]",
"value": "32GB"
}]
});
So instead of the flattened version with customFieldX, you can pass an array to customFields. The dropdown format is only used if you pass an options. For your use case this would become:
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"name": "configuration",
"value": "{\"option1\":\"value1\"}" //...
}]
});
However, custom fields are shown to the customer which would not be ideal to show them the raw json data. To pass hidden data you can instead use metadata which already expect a JSON object:
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"metadata": {
"configuration": "configuration data"
}
});
I am trying to access an url similar to http://example.com/service1?q1=a&q2=b. However q1 will not have any values associated with it sometimes but is required to access the service (http://example.com/service1?q1=&q2=b). How do I achieve this through swagger ui JSON. I've tried using allowEmptyValue option but it doesn't seem to work.
Please find below the sample JSON I tried using allowEmptyValue option,
{
"path": "/service1.do",
"operations": [{
"method": "GET",
"type": "void",
"parameters": [{
"name": "q1",
"in" : "query",
"required": false,
"type": "string",
"paramType": "query",
"allowEmptyValue": true
},{
"name": "q2",
"in" : "query",
"required": true,
"type": "string",
"paramType": "query",
}
],
"responseMessages": [{
"code": 200,
"responseModel": "/successResponseModel"
}
}
When an empty value is passed to q1, swagger frames the URL as http://example.com/service1?q2=b. Is there anyway to include q1 with empty values to be included in the URL (http://example.com/service1?q1=&q2=b) ?
Any help would be greatly appreciated.
It looks like your problem is a known issue of swagger-ui that hasn't fixed yet. see.
As a workaround you may do one of the followings.
Option 1: Specify a default value.
This option have nothing to do with swagger-ui. In your ws-implementation, You have to add a default value(in your case "") to use when 'q1' is not added. Any REST framework has this option.
As the ws-implementation perspectives, this should be there in your ws, unless you have another service to be triggered when 'q1' is not added. (which might not be a good design in most cases) And you can use this as a forever solution, not temporary.
Option 2: using enums (not a consistent solution)
As Explained in this. You can specify your query parameter 'q1' as follows for your swagger definition.
{
"in": "query",
"name": "q1",
"type": "boolean",
"required": false,
"enum" : [true],
"allowEmptyValue" : true
}
(1) "required" must be false.
(2) "allowEmptyValue" must be true.
(3) "enum" must have exactly one non-empty value.
(4) "type" must be "boolean". (or "string" with a special enum, say "INCLUDE")
I managed to solve this by setting:
"required": true,
"allowEmptyValue": true
In the Swagger-UI a checkbox will then be displayed where you can send the empty value. That worked for me. If that was checked and an empty query parameter was passed, the URL would look something like this: https://example.com?