Class OpenApi2JaxRs

  • Direct Known Subclasses:
    OpenApi2Quarkus, OpenApi2Thorntail

    public class OpenApi2JaxRs
    extends Object
    Class used to generate a simple JAX-RS project from an OpenAPI document.
    Author:
    eric.wittmann@gmail.com
    • Field Detail

      • mapper

        protected static com.fasterxml.jackson.databind.ObjectMapper mapper
      • utf8

        protected static Charset utf8
      • config

        protected static org.jsonschema2pojo.GenerationConfig config
      • openApiDoc

        protected String openApiDoc
      • document

        protected transient io.apicurio.datamodels.core.models.Document document
      • updateOnly

        protected boolean updateOnly
    • Constructor Detail

      • OpenApi2JaxRs

        public OpenApi2JaxRs()
        Constructor.
    • Method Detail

      • setSettings

        public void setSettings​(JaxRsProjectSettings settings)
        Configure the settings.
        Parameters:
        settings -
      • setOpenApiDocument

        public void setOpenApiDocument​(String content)
        Sets the OpenAPI document.
        Parameters:
        content -
        Throws:
        IOException
      • setOpenApiDocument

        public void setOpenApiDocument​(URL url)
                                throws IOException
        Sets the OpenAPI document via a URL to the content.
        Parameters:
        url -
        Throws:
        IOException
      • setOpenApiDocument

        public void setOpenApiDocument​(InputStream stream)
                                throws IOException
        Sets the OpenAPI document via an input stream. The stream must be closed by the caller.
        Parameters:
        stream -
        Throws:
        IOException
      • generate

        public final void generate​(OutputStream output)
                            throws IOException
        Generates a JaxRs project and streams the generated ZIP to the given output stream.
        Parameters:
        output -
        Throws:
        IOException
      • generateAll

        protected void generateAll​(CodegenInfo info,
                                   StringBuilder log,
                                   ZipOutputStream zipOutput)
                            throws IOException
        Generates all of the content for storage in the ZIP. Responsible for generating all classes and other resources that make up the generated project.
        Parameters:
        info -
        log -
        zipOutput -
        Throws:
        IOException
      • getInfoFromApiDoc

        protected CodegenInfo getInfoFromApiDoc()
                                         throws IOException
        Processes the OpenAPI document to produce a CodegenInfo object that contains everything needed to generate appropriate Java class(es).
        Throws:
        IOException
      • getContextRoot

        protected String getContextRoot​(io.apicurio.datamodels.core.models.Document document)
      • preProcess

        protected io.apicurio.datamodels.core.models.Document preProcess​(io.apicurio.datamodels.core.models.Document document)
        Pre-process the document to modify it in the following ways: 1) Inline any re-usable simple-type schemas 2) Check for the "x-codegen-contextRoot" property in the Paths object and prepend its value to all paths
        Parameters:
        document -
      • findMatchingBean

        protected static CodegenJavaBean findMatchingBean​(CodegenInfo info,
                                                          String typeSignature)
        Find a bean that matches the schema signature.
        Parameters:
        info -
        typeSignature -
      • generateJaxRsApplication

        protected String generateJaxRsApplication()
                                           throws IOException
        Generates the JaxRsApplication java class.
        Throws:
        IOException
      • generateJavaInterface

        protected String generateJavaInterface​(CodegenInfo info,
                                               CodegenJavaInterface _interface)
        Generates a Jax-rs interface from the given codegen information.
        Parameters:
        info -
        _interface -
      • generateTypeName

        protected com.squareup.javapoet.TypeName generateTypeName​(String collection,
                                                                  String type,
                                                                  String format,
                                                                  Boolean required,
                                                                  com.squareup.javapoet.TypeName defaultType)
        Generates the java type name for a collection (optional) and type. Examples include list/string, null/org.example.Bean, list/org.example.OtherBean, etc.
        Parameters:
        collection -
        type -
        format -
        required -
        defaultType -
      • generateReactiveTypeName

        protected com.squareup.javapoet.TypeName generateReactiveTypeName​(com.squareup.javapoet.TypeName coreType)
        Generates the reactive java type name for a collection (optional) and type. Examples include list/string, null/org.example.Bean, list/org.example.OtherBean, etc.
        Parameters:
        collection -
        type -
        format -
        required -
        defaultType -
      • toStringArrayLiteral

        protected static String toStringArrayLiteral​(Set<String> values)
        Converts a set of strings into an array literal format.
        Parameters:
        values -
      • getResource

        protected URL getResource​(String name)
      • getResourceName

        protected String getResourceName​(String name)
      • classnameToUri

        protected URI classnameToUri​(String path)
      • schemaRefToFQCN

        protected String schemaRefToFQCN​(String path)
      • javaPackageToZipPath

        protected String javaPackageToZipPath​(String javaPackage)
      • paramNameToJavaArgName

        protected static String paramNameToJavaArgName​(String paramName)
      • isUpdateOnly

        public boolean isUpdateOnly()
        Returns:
        the updateOnly
      • setUpdateOnly

        public void setUpdateOnly​(boolean updateOnly)
        Parameters:
        updateOnly - the updateOnly to set