Change API display order in Swagger (using Spring) - java

I am trying to change the displayed method order in swagger-ui page using java.
I need to show first welcome later hello controller method.
Below is my code.

In the #ApiOperation annotation you have an attribute position that you can set to change the order. Note that the attribute is deprecated but still works.

As you can read here the core developer of spring-fox states the problem very clear:
Just to be clear, we have an internal model that totally works as
expected and functional. The api descriptions and api operations will
be sorted as expected from springfox's standpoint. We're only using
the swagger models as DTOs to handle the serialization of our internal
service models. Once the DTO's are fixed to preserve the ordering this
problem will go away.
We can certainly add a note to describe the problem and the cause to
the Readme. Other than waiting for swagger core to fix this, there is
nothing to do here other than that I'm afraid.
So unless the Open API will fix/ enhance their models it will not work for spring-fox.

Default -
{controller-name}-controller
For Custom Name Add -
#Tag(name="1. YOUR CUSTOM NAME HERE")
on the Controller Class. Remember, we have used 1 in the name so that it can be on the top.
Example -
#RestController
#Tag(name="1. Project Resource")
public class ProjectResource {...}
Add the following to the application.yml file
springdoc:
swagger-ui:
tagsSorter: alpha
Result -

Related

How to reduce or organize swagger declarations with Kotlin

how can I organize the swagger annotations, for example I have an endpoint that catches all the users, so the swagger statements were huge. Is there any way I can organize this in another file to be more organized?
One of strategies often used is creating an interface (e.g. PersonApi in your case) and moving all swagger annotations there. The actual controller should implement this interface.
In regard to the error responses: you may consider adding them programatically to all operations/endpoints using OpenApiCustomiser.

How to configure REST controller for graphql-java without datafetcher?

I'm currently using DataFetcher for GraphQL-Java in Springboot based on the tutorial here. This works well, but I'm looking for another way to get the endpoints without implementing DataFetchers, as it seems like extra work where I have to (1) implement the resolver method, then (2) create a separate method for the corresponding DataFetcher. Is there another way to consolidate this to expose my GraphQL API a la some form of Rest controller? I have looked around quite a bit but haven't found any workable solution. Preferably (not sure if it's related) there would be a better way of annotating the endpoint as well (currently provided in the linked example with RuntimeWiring, which I'm hoping to remove as well).
In short, I would like, in Springboot, to not need for RuntimeWiring and DataFetcher (primarily this so as to remove double code for the same method and improve maintainability), and instead have another way to configure the global REST controller for my GraphQL-Java code, while also having another way to annotate the endpoint (maybe some annotator on top of the implemented methods).
Thanks!
Managed to fix it by using graphql.kick.start.tools' SchemaParser and GraphQLResolver as follows:
return SchemaParser.newParser()
.files(schemaFiles)
.scalars(scalars)
.resolvers(resolvers)
.dictionary(typeDictionary)
.build()
.makeExecutableSchema();
where the resolvers were implemented using this amazing plugin as codegen.

Cas - Custom acceptable usage policy view

We are using acceptable usage policy feature to implement a requirement where the user has to accept some licence agreement before using our registered services.
We have implemented our custom AcceptableUsagePolicyRepository as proposed in the docs and the user is successfully redirected to acceptance policy view based on a condition.
At this point we need to customize this view, so we have added the generated casAcceptableUsagePolicyView.html in the overlay. Our goal is to present different terms text based on the user status(admin,typical user etc). Terms text and user status should be fetched from the database.
In a typical MVC application, a controller would be used to generate the java objects that would be finally rendered in the view.
Question: What is the recommended way of customizing the aforementioned view to dynamically render our content?
Question: What is the recommended way of customizing the aforementioned view to dynamically render our content?
The easiest way, for the time being, would be to supply your own AcceptableUsagePolicyVerifyAction bean in a #Configuration class:
#Bean
public Action acceptableUsagePolicyVerifyAction() {
return new MyAcceptableUsagePolicyVerifyAction(...);
}
In your own MyAcceptableUsagePolicyVerifyAction, you'd then fetch the user status/text you need and stuff it into the RequestContext's relevant scope. In the casAcceptableUsagePolicyView, you can next write a bit of conditional logic to determine the relevant text based on the status found in the webflow scope.
To learn about how #Configuration classes work in general, you can:
Review this post
or This post
or consult the documentation for Spring and/or Spring Boot.

Google cloud endpoints. Omitting properties dynamically - by api method

The requirement is very simple. Let's say I have a model Book, with the properties:
author (string)
views (integer)
code (string)
Let's say I have code property, which is a String. I would like to keep this code property protected and not expose it in most of my API Methods. However, only in 2 API Methods, I would like to return the books, with the code property viewable.
The question in short is. How can you achieve this in google cloud endpoints (java), where I would like to omit specific properties from model in response, conditionally (According to API Method being called).
Anything that points me in the direction would be appreciated. For some reason I'm just unable to find this information in google docs, nor searching in google.
I thought of few solutions, but none elegant enough. For example, I could do kind of a transformer, which loops over models returned and set properties I wanna hide to null for example, but I feel like there's a more elegant solution that I'm missing.
Thank you in advance.
Here are a few options, but they might not be elegant enough:
Have one class per subset of properties (bonus: statically enforces that the properties won't appear)
Set properties you don't want to expose to null in each API
I don't think transformers work for you, as they are API-wide.

Apache beehive and localizing default pager for DataGrid

I am trying to localize strings created by Apache Beehive and netui default pager.
I'd like to translate language of this output.
Page 1 of 3 First / Previous Next / Last
My .jsp code looks something like this
<netui-data:dataGrid name="searchResultsGrid" dataSource="pageInput.someData">
<netui-data:header>
...
</netui-data:header>
<netui-data:rows>
...
</netui-data:rows>
<netui-data:configurePager pagerFormat="firstPrevNextLast" pageAction="refresh" pageSize="10"
disableDefaultPager="false" />
</netui-data:dataGrid>
I already found keys I should use in translation, but how I configure message properties file(s) that the pager should use?
As far as I can tell, IDataGridMessageKeys is merely an exposed internal interface, not really meant to be used by end-users. As a guess, I'd wager they had to expose it as public from within that package in order for other packages to be able to use it, and couldn't find another way (with their build scheme) to safely pass it to the rest of the code.
(Of course, I might be wrong. I'll try rooting through the source some more.)

Categories