In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to generate Java API jar packages through OpenAPI and upload them to private repositories". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to generate Java API jar packages through OpenAPI and upload them to private warehouses.
Purpose
Through the interface information defined in OpenAPI format, the SpringBoot Reactive interface Jar package is generated and uploaded to the private repository
Environmental confession
Development work IDEA build tool Gradle interface definition OpenAPI 3.0.0 Java version JDK11 SpringBoot version 2.1.7.RELEASE
Implement the generation of SpringBoot Reactive interface Java classes based on OpenAPI interfaces
Here we use the third-party plug-in in Gradle to generate the OpenAPI interface into the Java interface
Plugins {/ / Gradle third-party plug-in, which can generate the code id "org.hidetake.swagger.generator" version "2.18.1"} through the swagger interface document
At the same time, dependency openapi-generator-cli is introduced
Dependencies {/ / the following swaggerCodegen, choose one / / swaggerCodegen 'io.swagger:swagger-codegen-cli:2.4.2' / / Swagger Codegen V2 / / swaggerCodegen' io.swagger.codegen.v3:swagger-codegen-cli:3.0.5' / / or Swagger Codegen V3 swaggerCodegen 'org.openapitools:openapi-generator-cli:3.3.4' / / or OpenAPI Generator}
Configure the OpenAPI yaml file location
/ / Code generation, api defines yaml configuration swaggerSources {buddie {/ / specify api yaml file inputFile = file ("$projectDir/src/main/resources/swagger/openApi.yaml")}}
Specify the configuration file for the swagger generated code
/ / Code generation Api defines the yaml configuration swaggerSources {buddie {/ / specify the api yaml file inputFile = file ("$projectDir/src/main/resources/swagger/openApi.yaml") code {/ / specify the type of code generated language = 'spring' / / specify the personalized configuration file configFile = file when the code is generated ("$projectDir / src/main/resources/swagger/config.json ")}
The config.json file specifies the name of the package generated by the code, the library used, whether it supports Reactive, various paths, and the conversion of the specified Java type, etc.
{"library": "spring-boot", "dateLibrary": "java8", "reactive": true, "hideGenerationTimestamp": true, "modelPackage": "cn.buddie.demo.api.model", "apiPackage": "cn.buddie.demo.api.controller", "invokerPackage": "cn.buddie.demo.api", "java8": true, "configPackage": "cn.buddie.demo.api.configuration", "useBeanValidation": true, "interfaceOnly": true "typeMappings": {"OffsetDateTime": "Instant"}, "importMappings": {"java.time.OffsetDateTime": "java.time.Instant"}} the interface code class to be generated Package, upload
The official Gradle plug-in maven-publish is used here, and the java plug-in is introduced.
Plugins {id 'java' / / Gradle official plugin, which is used to publish the jar package id "maven-publish"}
At the same time, SpringBoot,Springfox-Swagger package and so on are introduced.
Dependencies {/ / introduces spring-boot-starter-webflux:2.1.x version to support reactive, implementation ('org.springframework.boot:spring-boot-starter-webflux:2.1.7.RELEASE') / / springfox-swagger2 is required for packaging to support swagger-generated interfaces, and implementation ("io.springfox:springfox-swagger2:2.9.2")} is required for packaging
Configure to publish jar packages to specified private repositories
/ / publish jar package publishing {publications {maven (MavenPublication) {/ / specify group/artifact/version information, which can be left unfilled. The project group/name/version is used by default as groupId/artifactId/version / / artifactId = rootProject.name / / if it is a war package, fill in components.web If it is a jar package, fill in components.java from components.java}} / / do not configure repositories It will be posted to the local maven repository repositories {maven {/ / specify the maven private server repository url = "http://localhost:8081/repository/maven-releases/" / / authenticated user and password credentials {username 'admin' password' buddie'} to this point. I believe you have a deeper understanding of "how to generate Java API jar packages through OpenAPI and upload them to private warehouses". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.