OpenApi 3.0: How to define uniqueness of array elements based upon a key (property) in object that is used as an element schema for that array? - yaml

I am having following schema defined in 'components' section of my openApi 3.0:
schema1:
required:
- prop1
- prop2
properties:
prop1
prop2:
enum:
- option1
- option2
prop3
This Schema is being used to define array elements in another schema as:
schema2:
required:
- prop4
- items
- prop6
properties:
prop4
prop5:
type: array
items:
$ref: '#/components/schemas/schema1'
maxItems: 2
prop6
Now in prop5 of Schema 2, I want the elements of array having unique value of prop2. Any ideas how to achieve this.

This is not possible as of OpenAPI 3.1 and JSON Schema 2020-12. Currently such validations need to be implemented on the backend.
Here's the corresponding feature request in one of the JSON Schema issue trackers:
https://github.com/json-schema-org/json-schema-vocabularies/issues/22
OpenAPI Schema is based on JSON Schema so any new schema keywords will come from JSON Schema.

Related

Should I write two times each objects as 'input' and 'type' in a graphql schema file

I have to use a Java object in GraphQL in response as well as in request.
Should I have to write two times each objects as 'input' and 'type' in a GraphQL schema file? For getting that object in request as well as in response.
Should I define the same object two times with input and type?
file: test.graphqls
input Employee {
id: Integer
name: String
dept: String
active: String
}
type Employee {
id: Integer
name: String
dept: String
active: String
}
Yes, because the type system rules are very different for input and output types. Input types can not be unions, can not implement interfaces etc, so you can not simply use the same definition for both purposes.
Moreover, you must give each type a unique name. So it should be Employee and EmployeeInput for example.

How to desialize Aerospike record in Go?

I am having quite complex schema in aerospike:-
DATA SCHEMA:
bin name: user_ids
Type: List of Strings
bin name: user_w
Type: List of Integers
bin name: users
Type: map<String<List>> where list is again list(size 3) of lists each of type String
I am able to read this schema directly into Java object with following data structure:-
userIds = (List<String>) r.getList("user_ids");
userWeights = (List<String>) r.getList("user_w");
users = (Map<String, List>) r.getValue("users");
However my following go struct is not able to retrieve it. Its coming as empty. Is something wrong with the struct schema?
type AudienceRecord struct {
user_ids []string
user_w []int64
users map[string][][]string
}
Your user_w schema is either List of integers, or list of strings ?
Because your java and go schemas aren't equivalent here.
That is why Go struct is not able to parse your aerospike data.

Additional fields retrieved while using reflection

I am writing a simple java class that makes use of the reflection API to find out the declared fields in the java.lang.class. Following is the piece of java code I have written.
Field[] fields = String.class.getDeclaredFields();
for (Field f : fields) {
System.out.println("Field name: " + f.getName());
}
I am getting the following output when I run this program.
Field name: serialVersionUID
Field name: CASE_INSENSITIVE_ORDER
Field name: ascii
Field name: stringArray
Field name: stringArraySize
Field name: enableCopy
Field name: value
Field name: offset
Field name: count
Field name: hashCode
Field name: hashCode32
Field name: seed
Field name: startCombiningAbove
Field name: endCombiningAbove
Field name: upperValues
Field name: serialPersistentFields
When I looked at the source code of the String class, I found that there were only 6 fields defined for the class in API.
I am not able to figure out where these additional fields are coming from in the output. Please help here.
There is nothing wrong with your code; when I run it, I get the expected output:
Field name: value
Field name: hash
Field name: serialVersionUID
Field name: serialPersistentFields
Field name: CASE_INSENSITIVE_ORDER
I'm guessing that you're using a non-Oracle Java Virtual Machine that adds (either in its bundled libraries or through some runtime magic) adds some nonstandard fields to the String class.

Doctrine2 + CodeIgniter and database table creation issue

I'm using Doctrine2 with codeIgniter, I've created some models in yml format. Using command line I've created the Proxies and Entities. When I'm trying to create the database tables, I'm getting the following error:
[Doctrine\ORM\Mapping\MappingException]
Invalid mapping file 'Entities.category.dcm.yml' for class
'Entities\category'.
Here's Entities.category.dcm.yml:
Entities\Category:
type: entity
table: categories
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 50
nullable: false
description:
type: string
length: 255
First of all, check the paths configured for your entities and for the YML mapping driver.
Also, your Entities.category.dcm.yml contains mappings for Entities\Category, and not Entities\category.
As you can see in the base FileDriver Doctrine ORM does direct matching for mapped classes, and applies no normalization on the class names. Category and category are therefore different.

How do I setup query cache results for built in doctrine2 repository functions?

I have a site that is for a video game I play and am working on improving the performance of the site by implementing some additional caching. I've already been able to implement query result caching on custom repository functions, but haven't been able to find anywhere that explains how I can include query result caching on the built in functions (findOneById, etc). I'm interested in doing this because many of my database queries are executed from these 'native' repository functions.
So as an example I have a character entity object with the following properties: id, name, race, class, etc.
Race and class in this object are references to other entity objects for race and class.
When I load a character for display I get the character by name (findOneByName) and then in my template I display the character's race/class by $characterObject->getRace()->getName(). These method calls in the template result in a query being run on my Race/Class entity tables fetching the entity by id (findOneById I assume).
I've attempted to create my own findOneById function in the repository, but it is not called under these circumstances.
How can I setup doctrine/symfony such that these query results are cache-able?
I am running Symfony 2.1.3 and doctrine 2.3.x
I've found out that it isn't possible to enable query cache on doctrine build in functions. I will post a link which explains why later after I find it again.
Your entities probably look something like this:
MyBundle\Entity\Character:
type: entity
table: Character
fields:
id:
id: true
type: bigint
name:
type: string
length: 255
manyToOne:
race:
targetEntity: Race
joinColumns:
raceId:
referencedColumnName: id
MyBundle\Entity\Race:
type: entity
table: Race
fields:
id:
id: true
type: bigint
name:
type: string
length: 255
oneToMany:
characters:
targetEntity: Character
mappedBy: race
If that's the case, then modify your Character entity mapping so that it eagerly loads the Race entity as well:
MyBundle\Entity\Character:
...
manyToOne:
race:
targetEntity: Race
joinColumns:
raceId:
referencedColumnName: id
fetch: EAGER
Doctrine documentation on the fetch option: #ManyToOne

Resources