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?
Related
I am writing a custom OpenApiConfigurator that adds some examples to my api dynamically.
When I add the examples using the value field of io.smallrye.openapi.api.models.examples.ExampleImpl, which is an object, the example is null in swagger-ui. It only works when I added the actual json.
To add the actual json I have to generate it from my response dto using Jackson. But how can I access the quarkus object mapper, for which I have some customisations using ObjectMapperCustomizer, if in the OpenApiConfigurator CDI is not available?
It's actually possible to access the CDI container statically with Arc.container().instance(ObjectMapper::class.java).get()
That solved it for me.
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
The external class I am using: https://github.com/arrow-kt/arrow/blob/5e0db6b7aaeb1ac99ecbfff74f03cce28e234391/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt#L725
Either Sealed class from Arrow.Core library.
This is my custom serializer for Either
#Serializer(forClass = arrow.core.Either::class)
object EitherSerializer : KSerializer<Either<ErrorResponse, SuccessResponse>> {
With this setup, I am expecting Springboot to use Kotlin serializer instead of jackson2. own class Kotlin serializers(using #Serializable) is recognized by the Kotlin runtime and it's using KotlinSerializationJsonHttpMessageConverter but in the above case, (using #Serialzer) default Jackson HTTP message converter is invoked.
How to get access and customize Freemarker's Configuration object in spring-boot 2.x?
It allows to set square bracket syntax as default option with something like:
Configuration#setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX)
which is not possible with any of spring.freemarker.* configuration property.
Also, it should be possible to introduce default imports having access to direct configuration of this object.
It's possible to set any FreeMarker configuration settings with spring.freemarker.settings.<settingName>, like spring.freemarker.settings.tagSyntax = square_bracket. See the JavaDoc of Configuration.setSetting(String, String) for more (https://freemarker.apache.org/docs/api/freemarker/core/Configurable.html#setSetting-java.lang.String-java.lang.String-). This is the method to which Spring delegates the assignments under spring.freemarker.settings; Spring itself doesn't know what "settings" exist or how to parse them.
I want to get io.swagger.models.Swagger object in my system, which is a restful backend based on jersey and swagger.
I saw in class ApiListingResource there is such a statement
Swagger swagger = (Swagger) context.getAttribute("swagger");
, which can retrieve the swagger object from servlet context.
Can I do the same in my own code? This seems not a contract that the attribute name will always be "swagger". So I dare not.
Is there any reliable way to retrieve the object?
You can rely on the context (yes, it is set to the name swagger, or with your own logic by extending BeanConfig