Swagger editor how to specify which fields in request body (POST) are required? - openapi

I'm trying to define a POST method on a user class in the online Swagger editor.
I want to be able to specify multiple fields in the request body and I would like the generated documentation to reflect that only 2 fields are required, the others are optional.
What do I have to do/change to make that so?
I have tried various variations with the "required" key word (see picture below for one), but haven't been able to make that work, it doesn't show in the generated documentation (see picture below right side with my annotations in red).
Here is my POST definition in the editor:
Here is the generated documenation preview where I have indicated the things I should like to see changed.
PS. There are some more (olders) posts addressing this, but I really don't think this is a duplicate.

I want to be able to specify multiple fields in the request body and I would like the generated documentation to reflect that only 2 fields are required, the others are optional.
Your second example is correct. To specify the required object properties, add required: [prop1, prop2, ...] on the object level (i.e. alongside type: object). Properties not listed in the required list are optional. If the required list is not provided, all properties are optional.
type: object
required: [email, password] # <--------
properties:
email:
type: string
password:
type: string
name:
type: string
In Swagger UI, operation-specific schema documentation is displayed on the Schema (or Model) tab. That's where the property descriptions, data types, "required" indicators, and other schema info is displayed.
Now I'll have to figure out how to have that "schema" shown as default
To make the Schema/Model tab active by default, configure Swagger UI with the defaultModelRendering option set to "model".

Related

Azure Dev Ops: How to set a boolean item's default value on a work item template

I have all required permissions to do whatever I want. This is our bug item template. We have a pre-existing Boolean item we've used for years now (To be Triaged - pictured below). It used to be defaulting to false, I want to default to true.
Is the only way / correct way to do this via a custom rule on create? Seems odd. Other text based fields for example allow you to specify required (this is greyed out, presumably because it's a bool?) and subsequently a default. This does not. Seems to require an explicit "rule" be created.
I could not find a way to do this without a custom rule. This rule worked for me:

Sample code for KeystoneJS 5 custom fields?

I'm interested in writing custom fields for KeystoneJS 5. The documentation is here, but I find it somewhat opaque (i.e., not fully explicatory). Is there sample code available? I looked in 'demo projects' and 'test projects' in the Keystone repo, but didn't see anything.
KeystoneJs custom fields are poorly documented and not easily accessible. in fact the whole concept of writing the whole custom field may be overkill.
here is the example one core team member has put copied form the test-project. - https://github.com/MadeByMike/keystone-custom-field/blob/7caf0139c189eadda1884a86073c6945bdd6ff05/index.js#L15
this is what you need to do:
1. you need to create a folder for the field
2. you can copy the Text field implementation to start with
3. there index.js file must export specific object (default export) like this ( I have added some comment for each line)
{
type: 'Stars', // name of the implementation
implementation: Stars, // implementation itself
views: { // all views are required you can copy the implementation from Text field)
Controller: Integer.views.Controller, // it is using controller from Integer field type
Field: require.resolve('./views/Field'), // field which goes into edit page or create dialog
Filter: Integer.views.Filter, // this adds filters in the list page
Cell: require.resolve('./views/Cell'), // view for list page where you usually see the text, for Relationship it is rendered as link.
},
adapters: {
mongoose: MongoIntegerInterface, // mongoose adapter specific inplementation
knex: KnexIntegerInterface, // knex adapter specific implementation,.
},
}
create views for each type (Field, Filter, Cell etc.)
import the field (default import) in the schema definition and use it like regular field. any custom option is passed on to the custom implementation.

Mask input for sap.m.Date(Time)Picker

With the sap.m.DateTimePicker, it's possible for a user to either select a value from the drop-down list or enter it manually. I'm wondering if there's a way to add a mask to the manual input box that matches the valueFormat of the DateTimePicker.
I know there's a sap.m.MaskInput as well, so maybe there's a way to combine the two elements.
There is a new private module named sap.m.MaskEnabler which the sap.m.InputBase (i.e. DateTimePicker) is supposed to make use of.
(MaskEnabler) should be applied to the prototype of a sap.m.InputBase.
The mask feature is currently enabled only in sap.m.TimePicker (v1.54). According to this commit message, however, the same feature will arrive to the Date(Time)Picker as well:
This change prepares for refactoring of DatePicker and TimePicker so the
common code of both pickers can be moved to a new common control that
they may extend.
Therefore, if it's not urgent, and depending on your project, I'd not create a new custom control and then throw it away once the mask feature has arrived.
I'll update my answer when it's available.
Until then (and even afterwards), you can still guide the user to enter the data in the correct format via OData binding type sap.ui.model.odata.type.DateTime:
<DateTimePicker
value="{
path: 'myODataModel>myDateTime',
type: 'sap.ui.model.odata.type.DateTime',
constraints: {
isDateOnly: true,
displayFormat: 'Date'
}
}"
minDate="{...}"
maxDate="{...}"
/>
In contrast to formatter, type allows us to keep two-way data binding.
The entered value is automatically intercepted from updating the model data when...
It could not be parsed due to an invalid format (fires parseError)
It could be parsed but the constraints were violated (fires validationError)
If you enable handling UI messages
additionally, the framework will then take care of creating the appropriate
message for the user:
Example: https://stackoverflow.com/a/48482544
I think the only way to combine the two sap.m.DateTimePicker and sap.m.MaskInput is to develop your own control . Documentation : https://sapui5.hana.ondemand.com/#/topic/91f1703b6f4d1014b6dd926db0e91070.
Another way is to just use the Placeholder of the DateTimePicker Input field. This does not provide the same functionality as a MaskInput, but helps the user which valueFormat is expected in the input when entering it manually.
If you have a binding in your input box, you could set the type in the binding to eg. sap.ui.model.type.Date. This way you get some automatic formatting when field validation is triggered. There are other types available and you could inherit from sap.ui.model.SimpleType to code your own.

Schema.org: How to use isAccessoryOrSparePartFor in JSON-LD?

I'm trying to declare products in JSON-LD for schema.org. I came across isAccessoryOrSparePartFor. So what do I put inside this tag? Schema.org says it should be a Product - but do I really have to put full product-declarations in it? Could I put URLs or EANs of the sparepart-products in it?
For the isAccessoryOrSparePartFor property, a Product value is expected, but not required.
From the Schema.org documentation:
Expected types vs text. When browsing the schema.org types, you will notice that many properties have "expected types". This means that the value of the property can itself be an embedded item (see section 1d: embedded items). But this is not a requirement—it's fine to include just regular text or a URL. […]
Of course, some consumers might not support other values than the expected ones.
You can use a minimal product declaration with only #context, #type and the product URL as id.
Example:
isAccessoryOrSparePartFor: [
{
'#context': 'http://schema.org',
'#type': 'Product',
id: UNIQUE_PRODUCT_ID_1'
},
{
'#context': 'http://schema.org',
'#type': 'Product',
id: UNIQUE_PRODUCT_ID_2'
},
...
]
You can check use Google's testing tool for structured data to validate.

Autocompleter for Mootools to set multiple form values

I need a Mootools based autocompleter that retrieves data by ajax, and will fill in multiple form input elements when an option is selected. I.E, a user searches for "foo", and one of the options might be "foobar", which has associated with it the variables objecttype AND objectid, both of which need to be set in the form when the user clicks on "foobar".
I've been looking at two autocompleters: Meio.Autocomplete and AutoCompleter as my best bet, but neither of them really seem to handle what I need them to handle.
I'm considering either rewriting/extending one of those, or possibly using the Meio version (which handles a single value) and storing my multiple variable in the form in one field, possibly as a json object that can be parsed client side with jsonParse and inserted into the form with an additional function after the selection is made.
Does anyone know of a simpler solution?
You could use the Meio.Autocomplete's onSelect event with an identifier, that JSON encodes all of the needed properties.
var data = [
{value: 'name1', identifier: {
id: 'id1',
type: 'type1'
}},
...
}
I made a quick example