OpenAPI parameter with brackets and variable name - openapi

I am working on an API which allows searching with URLs like:
GET https://example.com/api/data?search[field1]=value1
GET https://example.com/api/data?search[field2]=value2
GET https://example.com/api/data?search[field1]=value1&search[field2]=value2
Basically, you can search for one or more field values by putting a field name in brackets. The problem is, the field names are defined by the user in their settings. The field name will be a string, but otherwise is not known ahead of time at a global level.
This answer is almost what I am looking to do, I just can't find a way to define the value inside the brackets to be "any string" rather than a list of known names.

The search parameter can be defined as a free-form object with the deepObject serialization style and minProperties: 1 to enforce the presence of at least one field in the search query.
Make sure you use OpenAPI 3.0 (openapi: 3.0.x) and not OpenAPI 2.0 (swagger: "2.0"); the latter does not support objects in query strings.
openapi: 3.0.2
...
paths:
/api/data:
get:
parameters:
- in: query
name: search
required: true
schema:
type: object
additionalProperties: true # Default value, may be omitted
minProperties: 1
# Optional example to use as a starting value for "try it out" in Swagger UI
example: >
{
"field1": "value1",
"field2": "value2"
}
style: deepObject
explode: true
responses:
200:
description: OK

Related

OpenAPI 3.0 specifications - validating an array that is not required, but has minItems=1

optionalids:
type: array
items:
$ref: '#/components/schemas/Id'
minItems: 1
optionalIds is included inside another complex-type. and optionalIds is not a "required" property
Using openapi-codegen to generate code along with beanValidations.
The validation checks for the array optionalIds to at least contain one element. Since this is not a required property, not passing the optionalIds in the request should go through fine.
Is this understanding correct ?
What should be done to beanValidation templates so that this works

Swagger codegen: generate array elements with the correct names

I am using swagger codegen with the following YAML snippet:
lineItem:
type: array
xml:
wrapped: true
name: 'lineItems'
items:
#xml:
#name: 'lineItem'
$ref: '#/components/schemas/lineItem'
The object model is serialized to XML and needs to be in the format:
<lineItems>
<lineItem/>
<lineItem/>
</lineItems>
I have referred to the documentation here but cannot get the expected output:
https://swagger.io/docs/specification/data-models/representing-xml/
I have tried various things but the wrapping element and the individual elements always have the same name! e.g.
<lineItem>
<lineItem/>
<lineItem/>
</lineItem>
What is the correct configuration for this?

How to note a calculated default value in OAS3

I'm updating my API spec (OAS 3.0.0), and am having trouble understanding how to properly model a "complex" default value.
In general, default values for parameters are scalar values (i.e. the field offset has a default value of 0). But in the API I'm spec'ing, the default value is actually calculated based on other provided parameters.
For example, what if we take the Pet model from the example documentation, and decide that all animals need to be tagged. If the user of the API wants to supply a tag, great. If not, it will be equal to the name.
One possibility:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
default: '#/components/schemas/Pet/name'
This stores the path value as the default, but I'd like to have it explain that the default value will be calculated.
Bonus points if I can encode information from a parent schema.
Is the alternative to just describe the behavior in a description field?
OpenAPI Specification does not support dynamic/conditional defaults. You can only document the behavior verbally in the description.
That said, you can use specification extensions (x-...) to add custom information to your definitions, like so:
tag:
type: string
x-default: name
or
tag:
type: string
x-default:
propertyName: name
# or similar
and extend the tooling to support your custom extensions.

Sensenet length filter Not working

I want to query the Field which are empty and which are not empty using Sensenet Odata Rest API. Their documentation mentions a filter function called 'length'. I have tried to query the field with the length operation but it fails with the error.
This is the filter I have used
$filter=length(Name) eq 2
Sense/Net 6.5.4.9496
Exception
"code": "NotSpecified",
"exceptiontype": "SnNotSupportedException",
"message": {
"lang": "en-us",
"value": "Unknown method: length"
},
Wiki Link http://wiki.sensenet.com/OData_REST_API
The length operation was included in the list of supported methods incorrectly, we apologise for that. SenseNet compiles these filters to Lucene queries and it is not possible to compose such a query in Lucene that performs an operation on a field.
(the remaining methods, like substringof or startswith can be compiled to a wildcard expression easily, so that should work)
Unfortunately 'empty' expressions are also not supported by Lucene, because of their document/term structure. So the following expression does not work either:
Description eq ''
Edit: as a workaround, developers may create a custom field index handler.
For every field you want to check for emptiness (e.g. Description), you may create a technical hidden bool field (IsDescriptionEmpty) in the content type definition. The only thing you have to create and define is a custom field index handler class. In your case it would inherit from the built-in bool field index handler and you could return a boolean index value based on whether the target field (in this case Description) is empty or not.
After this you would be able to define search exressions like the following:
+Type:File +IsDescriptionEmpty:true
Please check the wiki article below and the source code for index handler examples.
How to create a field indexhandler

Mongoid and collections

I am trying to configure and use mongoid for the first time. I have set the mongoid.yml config file simply as:
host: localhost
database: table
and my code:
Mongoid.load!("/mongoid.yml")
class Data
include Mongoid::Document
field :study, type: String
field :nbc_id, type: String
field :short_title, type: String
field :source, type: String
field :start_date, type: Date
end
puts Data.study
I keep getting an error:
NoMethodError at / undefined method `study' for Data:Class
I think it is because I have not specified the collection name which is 'test'. However I can find no examples on how to do this. Do I specify it in the .yml file or in the code. What is the correct syntax. Can anyone point me in the right direction?
Tx.
According to the Mongoid documentation, "Mongoid by default stores documents in a collection that is the pluralized form of the class name. For the following Person class, the collection the document would get stored in would be named people."
http://mongoid.org/docs/documents.html
The documentation goes on to state that Mongoid uses a method called ActiveSupport::Inflector#classify to determine collection names, and provides instructions on how to specify the plural yourself.
Alternatively, you can specify the collection name in your class by including "store_in" in your class definition.
class Data
include Mongoid::Document
store_in :test
Hope this helps!