YAML validation on API plaftform - api-platform.com

I use API platform with YAML instead of Annotations. It's very easy to add validation constraint on Annotation but how add constraint in YAML. In the doc in Validation chapter I don't find. https://api-platform.com/docs/core/validation/#validation

API Platform uses the constraint validator from Symfony, you can refer to the symfony constraints documentation.
For example, using the Product sample from API platform with NotBlank constraint you should have:
# config/validator/validation.yaml
App\Entity\Product:
properties:
name:
- NotBlank: ~

Related

Order Springdoc operation parameters alphabetically

Migrating from springfox - springdoc
springfox generated an openApi definition that ordered all the parameters in alphabetical order, I've migrated to springdoc, but have been unable to find a way to keep the springfox ordering(alpha) of the parameters, e.g.
Controller:
getPerson(name, address, mobile)
springfox generated openApi definition:
getPersonService(address, mobile, name)
springdoc generated openApi definition:
getPersonService(name, address, mobile)
There are properties to order other aspects of the generated definition with:
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
springdoc.writer-with-order-by-keys: true
I have been unable to find a property to order the operation parameters, is there a setting to accomplish this? or can it be achieved cleanly with:
OpenApiCustomiser or OperationCustomizer

Can swagger use predefined java enums during code gen

I am using Swagger to generate the client code my APIs. One of the endpoint's input uses a enum. So I had to define the enum as part of YAML definition file, after which Swagger generates the enum java file. But I already have a java enum in the persistence layer. For Example:
This is the swagger definition:
/api/entity/
- entityType
--type1
--type2
But i already have a java enum defined and used on the server side called MyEntityType. Is it possible to mention this java enum in swagger, so that it wont generate the enum again but use the predefined java enum?

oneOf in Swagger schema does not work

I want to define PaymentMethod as below. Is oneOf supported in swagger.yaml?
PaymentMethod:
oneOf:
- $ref: '#/definitions/NewPaymentMethod'
- $ref: '#/definitions/ExistPaymentMethod'
The ExistPaymentMethod will have just id, and cardNumber where NewPaymentMethod will have no id, but all other details, e.g. cardNumber, cardholderName, cardholderAddress etc.
oneOf is supported in OpenAPI version 3 (openapi: 3.0.0), but not in Swagger version 2 (swagger: '2.0').
PaymentMethod:
oneOf:
- $ref: '#/components/schemas/NewPaymentMethod'
- $ref: '#/components/schemas/ExistPaymentMethod'
GitHub issue ref: https://github.com/OAI/OpenAPI-Specification/issues/333
For a list of changes in OpenAPI 3.0 compared to 2.0, see: https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/
What Swagger uses is only inspired by JSON Schema. They haven't deviated too much from JSON Schema, but they leave some things out, add some things, and change some behaviors. One of the things Swagger leaves out is oneOf.
More details can be found at http://swagger.io/specification/#schemaObject
OneOf, anyOf and other similar directives are not supported swagger 2.0, but supported in Open API 3.0 specifications.
You will need to convert your Swagger 2.0 file to Open API 3.0 file.
Here is the link -
https://blog.runscope.com/posts/tutorial-upgrading-swagger-2-api-definition-to-openapi-3
Here is one more useful link -
https://github.com/swagger-api/swagger-ui/issues/3803

Spring Boot YAML Config

I am trying to deploy a Spring Boot application for which I am not able to change the code. I'd prefer to configure it using YML, however I am hitting this YAML limitation:
Elements have a value or children, never both.
The config scheme for the application includes multiple instances of:
com.company.feature=default
com.company.feature.config=value
Is there any way to configure these as YAML, as the following would be invalid:
com:
company:
feature: default
config: value
You can't put it all in one hierarchy. Any property whose key has children and a value must be listed with the value without the heirarchy.
GOOD EXAMPLE:
com:
company:
feature:
config: value
com.company.feature: default
BAD EXAMPLE
com:
company:
feature:
config: value
com:
company:
feature: default
If you tried to do previous code then according to YAML, you overwrote com:company:feature with default instead of config: value

BeanValidation to check if delete is possible

How can I use BeanValidation to validate record before delete? For example I can only delete record when executeDate field is in the future.
I'm using with success beanvalidation in my project. It's annotation based configured. I use it by #Valid annotation on Controller method. It's Spring based MVC application.
my environment:
<hibernate4.core.version>4.2.1.Final</hibernate4.core.version>
<spring.version>3.2.2.RELEASE</spring.version>
<hibernate.search.version>4.2.0.Final</hibernate.search.version>
Edit:
I have seen this: hibernate validator - different groups on create, update, delete, and Hibernate Documentation also, but it is steel not clear for me.
If I have validation working so far do I need only add special case for delete? I'm confused what steps I need to do for get only this one feature.
add to your persistence configuration
<property name="javax.persistence.validation.group.pre-remov">MyDeleteGroup</property>
Add this annotation to your date field
#Past(groups=MyDeleteGroup.class)
Delete Group MyDeleteGroup is just a marker interface like javax.validation.groups.Default
For Spring Boot users:
application.yml
spring:
jpa:
properties:
javax:
persistence:
validation:
group:
pre-remove: com.your_package.MyDeleteGroup
or
application.proeprties
spring.jpa.properties.javax.persistence.validation.group.pre-remove=com.your_package.MyDeleteGroup
see this link for BeanValidation documentation
you can use #Past annotation for your case
see section 6.1
<event type="pre-delete">
<listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/>
</event>

Resources