Package io.apicurio.hub.api.codegen
Class OpenApi2JaxRs
- java.lang.Object
-
- io.apicurio.hub.api.codegen.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOpenApi2JaxRs.JaxRsRuleFactory
-
Field Summary
Fields Modifier and Type Field Description protected static org.jsonschema2pojo.GenerationConfigconfigprotected io.apicurio.datamodels.core.models.Documentdocumentprotected static com.fasterxml.jackson.databind.ObjectMappermapperprotected StringopenApiDocprotected static JavaBeanPostProcessorpostProcessorprotected JaxRsProjectSettingssettingsprotected booleanupdateOnlyprotected static Charsetutf8
-
Constructor Summary
Constructors Constructor Description OpenApi2JaxRs()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected URIclassnameToUri(String path)protected static CodegenJavaBeanfindMatchingBean(CodegenInfo info, String typeSignature)Find a bean that matches the schema signature.ByteArrayOutputStreamgenerate()Generate the JaxRs project.voidgenerate(OutputStream output)Generates a JaxRs project and streams the generated ZIP to the given output stream.protected voidgenerateAll(CodegenInfo info, StringBuilder log, ZipOutputStream zipOutput)Generates all of the content for storage in the ZIP.protected StringgenerateJavaInterface(CodegenInfo info, CodegenJavaInterface _interface)Generates a Jax-rs interface from the given codegen information.protected StringgenerateJaxRsApplication()Generates the JaxRsApplication java class.protected StringgeneratePomXml(CodegenInfo info)Generates the pom.xml file.protected com.squareup.javapoet.TypeNamegenerateReactiveTypeName(com.squareup.javapoet.TypeName coreType)Generates the reactive java type name for a collection (optional) and type.protected com.squareup.javapoet.TypeNamegenerateTypeName(String collection, String type, String format, Boolean required, com.squareup.javapoet.TypeName defaultType)Generates the java type name for a collection (optional) and type.protected StringgetContextRoot(io.apicurio.datamodels.core.models.Document document)protected CodegenInfogetInfoFromApiDoc()Processes the OpenAPI document to produce a CodegenInfo object that contains everything needed to generate appropriate Java class(es).protected URLgetResource(String name)protected StringgetResourceName(String name)JaxRsProjectSettingsgetSettings()booleanisUpdateOnly()protected StringjavaPackageToZipPath(String javaPackage)protected static StringparamNameToJavaArgName(String paramName)protected io.apicurio.datamodels.core.models.DocumentpreProcess(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 pathsprotected StringschemaRefToFQCN(String path)voidsetOpenApiDocument(InputStream stream)Sets the OpenAPI document via an input stream.voidsetOpenApiDocument(String content)Sets the OpenAPI document.voidsetOpenApiDocument(URL url)Sets the OpenAPI document via a URL to the content.voidsetSettings(JaxRsProjectSettings settings)Configure the settings.voidsetUpdateOnly(boolean updateOnly)protected static StringtoStringArrayLiteral(Set<String> values)Converts a set of strings into an array literal format.
-
-
-
Field Detail
-
mapper
protected static com.fasterxml.jackson.databind.ObjectMapper mapper
-
utf8
protected static Charset utf8
-
config
protected static org.jsonschema2pojo.GenerationConfig config
-
postProcessor
protected static JavaBeanPostProcessor postProcessor
-
openApiDoc
protected String openApiDoc
-
document
protected transient io.apicurio.datamodels.core.models.Document document
-
settings
protected JaxRsProjectSettings settings
-
updateOnly
protected boolean updateOnly
-
-
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
-
generate
public ByteArrayOutputStream generate() throws IOException
Generate the JaxRs project.- 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-
-
generatePomXml
protected String generatePomXml(CodegenInfo info) throws IOException
Generates the pom.xml file.- Parameters:
info-- Throws:
IOException
-
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-
-
isUpdateOnly
public boolean isUpdateOnly()
- Returns:
- the updateOnly
-
getSettings
public JaxRsProjectSettings getSettings()
- Returns:
- the settings
-
setUpdateOnly
public void setUpdateOnly(boolean updateOnly)
- Parameters:
updateOnly- the updateOnly to set
-
-