Class SwaggerBuilder


  • public class SwaggerBuilder
    extends Object
    Builds a 'Swagger' object from Swagger-Core by walking the static Elide entity metadata contained in the 'EntityDictionary'. The 'Swagger' object can be used to generate a Swagger document.
    • Field Detail

      • dictionary

        protected com.yahoo.elide.core.dictionary.EntityDictionary dictionary
      • rootClasses

        protected Set<com.yahoo.elide.core.type.Type<?>> rootClasses
      • allClasses

        protected Set<com.yahoo.elide.core.type.Type<?>> allClasses
      • swagger

        protected io.swagger.models.Swagger swagger
      • globalResponses

        protected Map<Integer,​io.swagger.models.Response> globalResponses
      • globalParams

        protected Set<io.swagger.models.parameters.Parameter> globalParams
      • filterOperators

        protected Set<com.yahoo.elide.core.filter.Operator> filterOperators
      • supportLegacyDialect

        protected boolean supportLegacyDialect
      • supportRSQLDialect

        protected boolean supportRSQLDialect
      • UNAUTHORIZED_RESPONSE

        public static final io.swagger.models.Response UNAUTHORIZED_RESPONSE
      • FORBIDDEN_RESPONSE

        public static final io.swagger.models.Response FORBIDDEN_RESPONSE
      • NOT_FOUND_RESPONSE

        public static final io.swagger.models.Response NOT_FOUND_RESPONSE
      • REQUEST_TIMEOUT_RESPONSE

        public static final io.swagger.models.Response REQUEST_TIMEOUT_RESPONSE
      • TOO_MANY_REQUESTS_RESPONSE

        public static final io.swagger.models.Response TOO_MANY_REQUESTS_RESPONSE
    • Constructor Detail

      • SwaggerBuilder

        public SwaggerBuilder​(com.yahoo.elide.core.dictionary.EntityDictionary dictionary,
                              io.swagger.models.Info info)
        Constructor.
        Parameters:
        dictionary - The entity dictionary.
        info - Basic service information that cannot be generated.
    • Method Detail

      • withGlobalResponse

        public SwaggerBuilder withGlobalResponse​(int code,
                                                 io.swagger.models.Response response)
        Decorates every operation on every path with the given response.
        Parameters:
        code - The HTTP status code to associate with the response
        response - The global response to add to every operation
        Returns:
        the builder
      • withLegacyFilterDialect

        public SwaggerBuilder withLegacyFilterDialect​(boolean enableLegacyDialect)
        Turns on or off the legacy filter dialect.
        Parameters:
        enableLegacyDialect - Whether or not to enable the legacy filter dialect.
        Returns:
        the builder
      • withRSQLFilterDialect

        public SwaggerBuilder withRSQLFilterDialect​(boolean enableRSQLDialect)
        Turns on or off the RSQL filter dialect.
        Parameters:
        enableRSQLDialect - Whether or not to enable the RSQL filter dialect.
        Returns:
        the builder
      • withGlobalParameter

        public SwaggerBuilder withGlobalParameter​(io.swagger.models.parameters.Parameter param)
        Decorates every path with the given parameter.
        Parameters:
        param - the parameter to decorate
        Returns:
        the builder
      • withExplicitClassList

        public SwaggerBuilder withExplicitClassList​(Set<com.yahoo.elide.core.type.Type<?>> classes)
        The classes for which API paths will be generated. All paths that include other entities are dropped.
        Parameters:
        classes - A subset of the entities in the entity dictionary.
        Returns:
        the builder
      • withFilterOps

        public SwaggerBuilder withFilterOps​(Set<com.yahoo.elide.core.filter.Operator> ops)
        Assigns a subset of the complete set of filter operations to support for each GET operation.
        Parameters:
        ops - The subset of filter operations to support.
        Returns:
        the builder
      • build

        public io.swagger.models.Swagger build()
        Builds a swagger object.
        Returns:
        the constructed 'Swagger' object
      • find

        protected Set<SwaggerBuilder.PathMetaData> find​(com.yahoo.elide.core.type.Type<?> rootClass)
        Finds all the paths by navigating the entity relationship graph - starting at the given root entity. Cycles are avoided.
        Parameters:
        rootClass - the starting node of the graph
        Returns:
        set of discovered paths.
      • getDocument

        public static String getDocument​(io.swagger.models.Swagger swagger)
        Converts a swagger document to human-formatted JSON.
        Parameters:
        swagger - Swagger-Core swagger POJO
        Returns:
        Pretty printed 'Swagger' document in JSON.