Swagger "required" vs "nullable" for codegen - swagger

I noticed while generating an API client using the typescript-fetch generator that the generated interfaces designate all properties as nullable, even when not designated as nullable in the swagger/open API definition. Furthermore, the only time they were made non-nullable is when the property was annotated with required = true.
I haven't found a clear distinction between "required" and "nullable" as it relates to how it should affect codegen, but intuitively, "required" seems like it should have clients enforce that a value be present when creating a request, while having nullable = false (which is the default) should generate a property on the response object that isn't nullable.
I'm looking for a clear distinction between the two, in order to identify if there is an issue with code-gen with respect to designating fields nullable or not.

Related

Why redudant attribute DW_AT_endianity with TAG_variable and TAG_base_type?

I was reading DWARFv4 spec and came across attribute DW_AT_endianity.
Correct me if my understanding is wrong.
As per spec, Two of the tag values TAG_variable and TAG_base_type both can have that attribute.
But as far as, i understand when you create a TAG_variable you have to pass the "Type", which can be of TAG_base_type(others are also possible).
So my question is if we are setting DW_AT_endianity on TAG_variable, why TAG_base_type also supports that attribute.
In other words every variable is of some type and can have that attribute, so why need attribute support for both type and variable?
The DW_AT_endianity attribute was the response to a proposed C compiler extension allowing the "creation of data in both big and little endian formats". It appears that the attribute was intended for base types (like this example) or structs/unions (like this one). Using the same attribute for both a simple variable and its underlying base type would, as you say, be redundant — note that the attribute is optional (see DWARF 4, sections 4.1.12 and 5.1).

How form values are persisted after postback?

After i populate some form(asp.net mvc) and press submit button after that form values are the same as before submit the form and i do not repopulate input fields from backend code. Can explain me how values are persisted cross request(and that values are not repopulated)?
Assuming you are asking about how MVC moder binder works(parsing posted data on the server), the default Model binder, which was designed to effectively bind most model types, does a relatively simple and recursive logic for each property of the target model.
1 It determines whether the property is a simple type or complex type by checking the property name are registered as a prefix. The prefix pattern is [ParentProperty].[Property]
2 Get the ValueProviderResult from the registered value providers for the property’s name.
3 If the property is a simple type, it tries to convert the property using the properties TypeConverter from the source value of type string to the from the source value of type string to the target type
4 Otherwise, the property is a complex type, so perform a recursive binding.
If you try to see the posted value the browser sends to the server, you could understand how to form data is sent, and get the idea. For reference, consult this link https://msdn.microsoft.com/en-us/magazine/hh781022.aspx

Wrong selected option for selectOneMenu with POJOs and Converter

in our company we're hitting a serious problem which we think is a serious design flaw of the JSF spec, if it is the normal behavior.
This is our usecase:
SelectOneMenu (standard JSF or primefaces, doesn't matter, same behavior)
SelectItems with a database entity as it's value and a string as the label
A converter (via attribute on the selectOneMenu) which translates the entity to its ID (getAsString) and from the ID to the entity (getAsObject)
Everything works as expected as long as the entity inside the value attribute of the selectOneMenu is loaded using the same entityManager as the entities inside the selectItems. We have the same POJOs and therefore the same hashcode (Object#equals() returns true). But as soon as one of the entities is loaded via a different entityManager and therefore has a different hashcode, we are never able to get a match to generate the expected selected attribute of an select item (HTML <option /> ).
The cause of this behavior is, that the JSF-impl and primefaces both use the POJOs in the call
boolean selected = isSelected(context, menu, itemValue, valuesArray, converter);
for itemValue and valuesArray. The implementation of isSelected relies on Object#equals() for POJOs. In my opinion it should always use the value of Converter#getAsString if we have a Converter and pass it to isSelected. This is also the behavior for a POST request. Here we got a submittedValue for the selectOneMenu which is compared to the converted value of the POJO (Converter#getAsString).
Now the question:
Is this the expected behavior as it's described in the spec? Isn't the output of the converter the better way to handle this comparision? Now we have to modify our entity classes and overwrite the equals method to be able to use this construct.
Your mistake is that you forgot to implement/autogenerate equals() (and hashCode()) method conform the contract. This is beyond control of JSF. Pointing the accusing finger to JSF isn't making any sense.
It's handy to have a base entity where all your entities extend from so that you don't need to repeat the task over all entities (even though the average IDE/tool can easily autogenerate them). You can find an elaborate example in 2nd "See also" link.
See also:
Validation Error: Value is not valid
Implement converters for entities with Java Generics
I believe that this is the correct behavior. On Java side the values of the component and selection are POJOs. You have full control of the logic of their equality etc. It should not matter how it is converted to UI display and back. As a component user you should not bother to know how the POJO is displayed. As text, icon, color, whatever. The Java side of the component undestands and communicats with POJOs
YOUR CODE ----------> JAVA COMPONENT --------> CONVERTER ----------> HTML
Also I guess that relying on reference equality for entities is a road to problems. Setting equals/hashCode to use actual ID is the best approach.

Validating navigation properties, bug or feature?

I am having problems with the validation of navigation properties.
I do not know if it's a bug or just does not work as I expected.
When you have a navigation property required with his foreign key (in my case int type) is successfully added the validator and, as an int can not be null, is assigned the default value 0, but when the entity is being validated, as the property has value (0), is given as correct. I expected that the entity was not valid.
Is it a bug or correct behavior?
Greetings.
It is a good question. I don't think this is a bug or a feature. Nor would I consider an async validation option.
Instead, I would add a custom validation on the FK (or the property) that declared that the FK property is invalid when it is 0. Yes, that means the entity is in an invalid state at the moment of creation. Nothing can be done about that. You're using '0' as a sentinel value that means "I don't know yet". The validation means "... and the entity is invalid until I know."
Btw, Breeze cannot assume that 0 is invalid. That could be a valid FK to the related entity.
This problem isn't unique to FKs. You have it when creating a new order lineitem with 'quantity=0' and your business rules say it must be >0. The type requires you to specify SOMETHING and yet you cannot provide the correct answer a priori. Again, Breeze can't assume that '0' is a bad value. You have to specify that.
There is no bug per se in either scenario. Both require additional developer attention to "do the right thing".
It's a good question.
Breeze can't actually validate the foreign key alone without performing a roundtrip to the datastore/database, and if it did, validation would become a asynchronous operation. Currently, breeze does not support async validations, but, this might be exactly what you want in some scenarios.
There are some problems with async validations that we would need to tackle. The most important is that another operation such as a save or requery or another change to the fk field might occur before the first validation completes. These can all be handled but there is additional complexity.
If you think that this would be a useful addition, please add it to the Breeze UserVoice. We take these submissions seriously.

Modifying return value of getters of String fields

Let's say I have classes similar to domain classes in my application with some Long, Double, Date and String fields. These classes extend base class with some common fields and few common methods. Whenever I access class field (though getter) that is String, I want to make some changes to the value returned (for example remove html tags). Is there a better way than making implementations of getters for each fields of String type? What about inherited fields?
Don't change default getter/setter implementations created for you by Grails. You would definitely mess up your application in various places. Grails uses convention over configuration so getters/setters should definitely remain unchanged.
Create your own methods that return what you want: for a field title create method getStrippedTitle(). You can add this method to transients too.
If you change the value that's set, or return a value that's different from what was set, you'll confuse Hibernate. That's because when you load an instance from the database, Hibernate keeps the original data in its 1st-level cache, and returns a domain object instance to you. When you flush, it compares the current state with the original, and if it changed, it will push the changes to the database. So if you return a different value than what was set, but don't really change the value, Hibernate can't tell the difference.
You're much better off leaving the properties alone and creating methods that return altered data. One convention I've used is that if for example you have a String body field, you can access it via the property name body or the getter getBody(), but you can create a body() method that's unknown to Hibernate and returns whatever you want.

Resources