Modify

Opened 3 years ago

Last modified 2 years ago

#22034 new enhancement

[PATCH] Improve OpenAPI and remote control output

Reported by: hiddewie Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: Cc:

Description (last modified by hiddewie)

I was using the remote control APIs and found the OpenAPI file lacking in details. Especially the types of parameters were all string which removes validation in the Swagger UI and other OpenAPI tools.

There was a TODO in the code for this.

To solve the issue of parameter typing, I added a RequestParameter class that handles the conversion and parsing from request parameters to the actual parameter value. It also contains the metadata like whether the parameter is required and the OpenAPI type.

Attached is the patch file.

Changes:

  • Add response codes & descriptions to each API
  • OpenAPI version from 3.0.0 to 3.0.3
  • Use the configured port in the OpenAPI server block from the configured property remote.control.port or the default (using IntegerProperty).
  • Add RequestParameter object that describes and parses a mandatory/optional request parameter. This information is used in the OpenAPI specification as well
  • Capitalize descriptions of the request handlers

The class RequestHandler should be backwards compatible for use in plugins.

Ref https://swagger.io/specification/ for OpenAPI specification

Attachments (6)

remote-control.patch (58.6 KB ) - added by hiddewie 3 years ago.
patch v1
remote-control.2.patch (64.3 KB ) - added by hiddewie 3 years ago.
patch v2
remote-control.3.patch (70.4 KB ) - added by hiddewie 3 years ago.
patch v3
Screenshot from 2022-04-24 13-22-23.png (261.2 KB ) - added by hiddewie 3 years ago.
Swagger UI (https://editor.swagger.io/ for hosted version)
Screenshot from 2022-04-24 13-23-07.png (70.7 KB ) - added by hiddewie 3 years ago.
Single operation in swagger UI
22034.patch (73.8 KB ) - added by taylor.smock 2 years ago.
Use classes to generate OpenAPI types

Download all attachments as: .zip

Change History (12)

by hiddewie, 3 years ago

Attachment: remote-control.patch added

patch v1

by hiddewie, 3 years ago

Attachment: remote-control.2.patch added

patch v2

comment:1 by stoecker, 3 years ago

First look comments:

  • New functions+classes should have an "@since xxx" so they are properly attributed during checkin
  • Are the uppercase/lowercase text changes really necessary?

comment:2 by hiddewie, 3 years ago

Added the @since on the new class and functions.

I also noticed I forgot to include RequestParameter in the patch (this is pretty difficult compared to a Git branch and a pull request). I added the missing file.

Are the uppercase/lowercase text changes really necessary?

I think they are: descriptions should be verbose pieces of text with full sentences. And those start with a capital letter. It also looks neater when the specification is opened in a Swagger UI (or similar tool).

See attached screenshots of the usage with a Swagger UI.

by hiddewie, 3 years ago

Attachment: remote-control.3.patch added

patch v3

by hiddewie, 3 years ago

Swagger UI (https://editor.swagger.io/ for hosted version)

by hiddewie, 3 years ago

Single operation in swagger UI

comment:3 by hiddewie, 3 years ago

Description: modified (diff)

comment:4 by hiddewie, 3 years ago

The documentation could be improved even further by textually documenting each parameter with a description field in the OpenAPI specification.

comment:5 by taylor.smock, 3 years ago

For RequestParameter static constructors, why have a parameter for String openapiType? Why not Class<T> classType? (I'd prefer to just use the generic class type from the rest of the static constructor, but I don't believe that is currently possible). I'd prefer to avoid Strings being passed around, since typos happen.

It looks like you have duplicated the same if condition in LoadAndZoomHandler#handleRequest (see lines with selectParameter.isPresent). The last one should probably be searchParameter instead (typos happen). This should be caught by AlreadyChecked, but errorprone decided to bump their minimum required Java version (8 -> 11) in the version where the AlreadyChecked detection was added. Feel free to bump the version of errorprone in your local copy, but please don't include that diff in the patch.

comment:6 by taylor.smock, 2 years ago

@hidewie: Are you still working on the patch?

by taylor.smock, 2 years ago

Attachment: 22034.patch added

Use classes to generate OpenAPI types

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to hiddewie.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.