I'm using MicroProfile OpenAPI with JAX-RS on Quarkus and would like to mark the resource as deprecated, ie. achieve the following result in the generated JSON:
get:
...
deprecated: true
Marking the method as #Deprecated does not help. Any other way of doing this?
This can be achieved by setting deprecated inside #Operation, i.e.:
#Operation(
deprecated = true,
...
)
Related
In a Spring Boot 2.7. Camel 3.20.x project written in Kotlin I have a REST endpoint that receives a JSON payload. I've added the Camel Jackson dependency to deal with JSON<->POJO transformation:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>${camel.version}</version>
</dependency>
data class Payment(val iban: String, val amount: Float)
rest("/payments")
.post("/")
.to("direct:processPayment")
from("direct:processPayment")
.log("Body \${body}")
.log("Body \${body.getClass()}")
These are the logs of the route:
Body {"payment":{"iban":"ABCD","amount":150.0}}
Body class org.apache.camel.converter.stream.InputStreamCache
As you can see the body is correctly displayed as String, however, the type is InputStreamCache instead of my Payment DTO.
I updated the route to unmarshall the body to the Payment DTO:
from("direct:processPayment")
.unmarshal().json(JsonLibrary.Jackson, Payment::class.java)
.log("Body \${body}")
.log("Body \${body.getClass()}")
This fails with:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `xxx.Payment` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
Why isn't the conversion working?
The encountered error has nothing to see with Camel nor Spring, but is directly related to Jackson.
As the error message indicates it, the reason is that the Payment pojo does not satisfy the requirement of having a default (parameterless) constructor.
The source of the problem was correctly described in the accepted answer. However there's a Kotlin compatible solution that allows the use of data classes without default (empty) constructors.
Add jackson-module-kotlin dependency:
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
With this, Spring Boot will tweak its own Jackson ObjectMapper. Now, just tell Camel to use that Spring configured object mapper:
camel:
dataformat:
jackson:
auto-discover-object-mapper: true
I need to parse kotlin docs (not swagger annotation) for swagger-ui.
I tried this, but it don't work.
Here my springdoc dependencies (springdocVersion = "1.6.6"). By the way, I can't use therapi version 0.13.0 if it's important.
runtimeOnly("org.springdoc:springdoc-openapi-kotlin:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-ui:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-webflux-ui:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-javadoc:$springdocVersion")
annotationProcessor("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0")
implementation("com.github.therapi:therapi-runtime-javadoc:0.12.0")
After I replaced annotationProcessor("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0") with kapt("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0"), all worked well!
An example of the build file can be found here
I use the openapi generator kotlin module to generate kotlin classes from my openapi.yaml file. The process works fine until I try to deserialize the received JSON in my code to a kotlin class using Jackson.
This is the generated class
data class Request (
#field:JsonProperty("name")
var name: kotlin.String,
)
This is the error I get
java.lang.IllegalArgumentException: Cannot construct instance of `...package.Request` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; byte offset: #UNKNOWN]
I noticed that when I remove the "#field:" part in the generated code, then everything works like a charm.
So now my question is can I either remove the #field from the generator or make Jackson deserialize it correctly?
The versions that I use are
jackson: 2.13.1
open-api-generator (gradle plugin): 5.3.0
I had the same error and registering the Kotlin Jackson module fixed it for me: https://github.com/FasterXML/jackson-module-kotlin
I'm doing my first test in Java, and I have a Shiro Security... I follow the tutorial (https://shiro.apache.org/testing.html) but says:
(this example uses EasyMock, but Mockito works equally as well):
Subject subjectUnderTest = createNiceMock(Subject.class);
expect(subjectUnderTest.isAuthenticated()).andReturn(true);
Because I use Mockito I implement with
Subject mockSubject = mock(Subject.class);
expect(subjectUnderTest.isAuthenticated()).andReturn(true);
But when I do it have this error
The method expect(boolean) is undefined for the type AdminControllerTest
And don't give me the posibility to import it. I don't know if expect is especific of EasyMock and if yes what I have to use in Mockito.
I search here and see more person doing it and always recomend use this expect
How to mock a shirosession?
If we look at this code example ...
Subject mockSubject = mock(Subject.class);
expect(subjectUnderTest.isAuthenticated()).andReturn(true);
We can see that ...
You are using mockito syntax to do the mocking.
You are using easyMock syntax to configure the mock. It is not even in the dependency list, so this method is not found.
The solution is to use mockito syntax to configure the mock.
Subject mockSubject = mock(Subject.class);
when(mockSubject.isAuthenticated()).thenReturn(true);
This will make everything work as expected and your Subject will return true, when the isAuthenticated() method is called.
If you want to up your mockito game, try this resource, which comes with working github code examples.
My struts 2 (2.3.1) application at debug mode for url http://localhost/app/check.action?13239 raises such kind of exceptions
2011-12-15 14:45:06,455 DEBUG [CommonsLogger.java:68] : Setting static parameters {}
2011-12-15 14:45:06,456 DEBUG [CommonsLogger.java:68] : Setting params NONE
2011-12-15 14:45:06,456 DEBUG [CommonsLogger.java:68] : Setting params 13239 => [ ]
2011-12-15 14:45:06,461 WARN [CommonsLogger.java:60] : Error setting expression '13239' with value '[Ljava.lang.String;#33b4450e'
ognl.InappropriateExpressionException: Inappropriate OGNL expression: 13239
at ognl.SimpleNode.setValueBody(SimpleNode.java:312)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
I was expecting silently ignoring them according to documentation. What is the correct way to fix this problem?
By the way it seems that struts looking for a setter field for the value 13239 however I guess that it is not suitable for a property which is started by a number.
That is more or less a issue of your personal taste.Sometime we wants to know any time a parameter is submitted that doesn't have a matching getter/setter on the action and its a common use case in development our application and we forget a getter/setter on an action, we want to know about any possible error case.
One possible way to is setting the logging level differently from dev to production.There was a long discussion about this on Struts2 mailing list here is the link for same
OgnlValueStack Error setting expression warnings after upgrade from struts 2 to struts 2.1.7