Default value for jhipster entity field - entity

The answer to this question searched in Google and stackoverflow. On the right answer is not found. I created entity with jhipster. Now want to change, I want to add a new field with the default options. How to add default option for entity field with Entity.json file?
This piece of the desired location of the entity.json file:
....,
{
"fieldId": 3,
"fieldName": "retry",
"fieldType": "Integer",
"????????": 10;
"fieldValidateRules": [
"required"
]
}
.....
instead the sign ????? need keywords that would give a default option

It is not currently supported, you have to edit the code by hand.
You can set the default value in EntityResource.java:createEntity or change the table specification in the liquibase changelog for the entity (Liquibase - addDefaultValue).

Related

How do I require only one of a set of properties are specified with json schema

I have three properties: one, two, three.
If one of those properties is specified the other two must not be included. So this is a mutual exclusion rule.
I tried to write this rule in a concise way, but this appears not to work:
"oneOf": [
{
"required": ["one"],
"not": {"required": ["two", "three"]}
},
{
"required": ["two"],
"not": {"required": ["one", "three"]}
},
{
"required": ["three"],
"not": {"required": ["one", "two"]}
},
]
That will only throw an error if all three are specified together instead of just more than one. I almost want something like an enum, but for properties- to be able to say only one of this list of properties can be specified.
EDIT
Per user comments I removed the nots and that worked, but I'm really disappointed in the error message:
- (root): Must validate one and only one schema (oneOf)
- myObj.0: Must validate one and only one schema (oneOf)
Super not helpful. It doesn't say anything about which properties are failing validation. Is there a way to describe this in a way where users will get an error that looks more like:
- myObj.0: Must include one and only one of properties one, two, or three
Otherwise it kind of leaves you in the dark and forces you to review the actual schema instead of making it more obvious.
You can use maxProperties: 1 along with additionalProperties: false.
additionalProperties: false prevents the inclusion of properties you don't define, which means they have to use yours, but then maxProperties: 1 will require that they can only use one of them.

Vue Formulate FormulateForm issue

Trying to use Vue Formulate to generate dynamic forms based on a schema. The problem I'm having is if I have two elements that are the same in my schema I get a duplicate keys detected error. Is it possible to specify the index as the key? Or is there a way I can incorporate IDs into my schema to avoid this error? thanks in advance.
Unclear whether this is your issue, but I've found that non-form elements in the schema, e.g. a <component>, h3, or <div> often produce this error, but can have a "key" attribute added in the schema to fix it e.g.:
[
{
"component": "h3",
"key": "h3",
"children": "Sample Text",
"class": "m-image-request-form__h3"
},
]

Is there a way to add a default to a json schema array

I just want to understand if there is a way to add a default set of values to an array. (I don't think there is.)
So ideally I would like something like how you might imagine the following working. i.e. the fileTypes element defaults to an array of ["jpg", "png"]
"fileTypes": {
"description": "The accepted file types.",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"enum": ["jpg", "png", "pdf"]
},
"default": ["jpg", "png"]
},
Of course, all that being said... the above actually does seem to be validate as json schema however for example in VS code this default value does not populate like other defaults (like for strings) populate when creating documents.
It appears to be valid based on the spec.
9.2. "default"
There are no restrictions placed on the value of this keyword. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations SHOULD remove duplicates.
This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.
See https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.2
It's up to the tooling to take advantage of that keyword in the JSON Schema and sounds like VS code is not.

Why is the avro default value not used ? (with avro-python)

I'm serializing some data with Avro (using the python library), and I have a hard time figuring how to make the "default" value work.
I have this schema:
{
"type": "record",
"fields":[
{"name": "amount", "type": "long"},
{"name": "currency", "type": "string", "default": "EUR"}
],
"name": "Monetary",
}
So as I understood, I could pass an amount and no currency, and the currency field would take the "EUR" value. However, if I don't pass a "currency" field when writing, I get the error avro.io.AvroTypeException: The datum { ... } is not an example of the schema xxx...
If I replace the currency field's type as an union ["string", "null"], then the data is serialized, but currency is null.
So it seems the "default" value is not taken into account at all.
What am I missing ? Are default value applicable for primitive types ?
Thanks in advance
Here is the relevant cite from avro specification
default: A default value for this field, used when reading instances that lack this field (optional)
The 'default value' field is used when you try to read an instance written with one schema and convert it to an instance written with another schema. If the field does not exist at the first schema (thus the instance lacks this field), the instance you get will take the default value of the second schema.
That't it!
The 'default value' is not used when you read/write instance using the same schema.
So, for your example, when you set the currency field a default value, if you try to read an instance which was written with older schema which did not contain currency field, the instance you get will contain the default value you've defined at your schema.
Worth to mention, when you use union, the default value refers only to the first type of the union.

Change/Update Field name in the NiFi Schema Text property Across various parallel flows

I have few identical parallel flows(as shown in screenshot). I have convertRecord in each of the identical flows and in the Record Reader I have used "Schema Text Field Property" as access strategy and specified the "Schema text". For Example:
{
"type": "record",
"name": "AVLRecord0",
"fields" : [
{"name": "TimeOfDay", "type": "string", "logicalType":"timestamp-millis"},
{"name":"Field1", "type": "double"},
{"name":"Field2", "type": "double"},
{"name":"Field3", "type": "double"},
{"name": "Filename", "type": "string"}
]
}
Lets say the above schema I have used across various parallel flows ConvertRecord, and now I want to update one field name from Field to Field_Name so is there any way I can do it in one go across all the convert record Schema Text?
If I want to change/update one of the Field in the schema Text do I have to change/Update the field name in each processor manually? Or there is a global way that will change the field name across all the parallel flow I have?
Is there Any way that I can update the Schema Text across various processors In one go?
Any help is much appreciated! Thanks
As you are using Schema Text Field Property so you need to change in all ConvertRecord processor manually.
Try with this approach:
In ConvertRecord processor use Schema Access Strategy as
Use Schema Name Property
Then set up AvroSchemaRegistry and define your schema by adding new property
I have added sch as schema.name and defined the avro schema.
After GetFile Processor use UpdateAttribute processor and add schema.name attribute(for ex: with value sch) to the flowfile.
Now in reader controller service use the Schema Access strategy as Use Schema Name Property and Schema Registry asAvroSchemaRegistry` that has already setup.
By following this way we are not defining schema on all ConvertRecord processors instead we are referring to same schema that defined in AvroSchemaRegistry in case if you want to change one field name it is easy to go into Registry and change the value.
Flow:
1.GetFile
2.UpdateAttribute //add schema.name attribute
3.ConvertRecord //define/use AvroSchemaRegistry and access strategy as schemaname property
..other processors
Refer to this link for more details regards to defining/using AvroSchemaRegistry.