Class OpenApiSpecLoader


  • public class OpenApiSpecLoader
    extends Object
    Detects whether a file in the routes directory is an OpenAPI spec (Swagger 2.x or OpenAPI 3.x) in either JSON or YAML format, and parses it into an OpenAPI model.

    Detection logic:

    1. File extension must be .json, .yaml, or .yml.
    2. The parsed root object must contain an openapi key (OAS 3.x) or a swagger key (Swagger 2.x).

    Normal OpenIG route JSON files contain a handler or name root key but not openapi/swagger, so they are not matched.

    • Constructor Detail

      • OpenApiSpecLoader

        public OpenApiSpecLoader()
    • Method Detail

      • tryLoad

        public Optional<io.swagger.v3.oas.models.OpenAPI> tryLoad​(File file)
      • isOpenApiFile

        public boolean isOpenApiFile​(File file)
        Returns true if the given file has a supported extension AND its root document contains an openapi or swagger key, meaning it looks like an OpenAPI spec rather than a regular OpenIG route configuration.
        Parameters:
        file - the file to test
        Returns:
        true if the file appears to be an OpenAPI specification