Skip to content

Enhance OpenAPI generation #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 2, 2023
Merged

Enhance OpenAPI generation #115

merged 10 commits into from
Jan 2, 2023

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Dec 25, 2022

  • fixes param openapi generation
  • Adds an annotation we can use to add openapi responses with.

With this, we can define 4xx and 5xxx in our openapi and even have the correct schema for the error body

Adding with a 2xx code will override the default 2xx status code for the endpoint.

This is especially useful when people are using the Helidon ServerResponse/Javalin Context in void method controllers

Thoughts?

  /**
   * Standard Post
   *
   * @param b the body
   * @return the response body (from javadoc)
   */
  @Post("/post")
  @OpenAPIReturns(responseCode = "200", description = "from annotaion")
  @OpenAPIReturns(responseCode = "201")
  @OpenAPIReturns(responseCode = "400", description = "User not found")
  @OpenAPIReturns(
      responseCode = "500",
      description = "Some other Error",
      type = ErrorResponse.class)
  RequestModel testPost(RequestModel b) {
    System.out.println("got " + b);
    return new RequestModel("Hmmm, now that I think about it");
  }

This will generate

other endpoints...
  "/javalin/post" : {
      "post" : {
        "tags" : [ ],
        "summary" : "Standard Post",
        "description" : "",
        "requestBody" : {
          "description" : "the body",
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/RequestModel"
              }
            }
          },
          "required" : true
        },
        "responses" : {
          "200" : {
            "description" : "from annotaion",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/RequestModel"
                }
              }
            }
          },
          "201" : {
            "description" : "the response body (from javadoc)",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/RequestModel"
                }
              }
            }
          },
          "400" : {
            "description" : "User not found"
          },
          "500" : {
            "description" : "Some other Error",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }

@SentryMan SentryMan changed the title Enhance OpenAPI generation (WIP) Enhance OpenAPI generation Dec 26, 2022
@SentryMan SentryMan marked this pull request as ready for review December 26, 2022 01:54
Copy link
Contributor

@rbygrave rbygrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks right on the money - awesome, ta.

@rbygrave rbygrave merged commit b4a3ccf into avaje:master Jan 2, 2023
@rbygrave rbygrave added this to the 1.21 milestone Jan 2, 2023
@SentryMan SentryMan deleted the openapi branch January 2, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants