add method to return the title

This commit is contained in:
William Cheng 2024-09-19 11:28:44 +08:00
parent 410113fd6d
commit 090f1b31ba
8 changed files with 20 additions and 7 deletions

View File

@ -8480,4 +8480,17 @@ public class DefaultCodegen implements CodegenConfig {
} }
operation.hasParams = !operation.allParams.isEmpty(); operation.hasParams = !operation.allParams.isEmpty();
} }
/**
* Returns the title in the info section of the spec or default to openapi if not defined.
*
* @return title
*/
protected String getInfoTitle() {
if (openAPI.getInfo() != null) {
return openAPI.getInfo().getTitle();
} else {
return "openapi"; // default to openapi if title not set
}
}
} }

View File

@ -160,7 +160,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
@Override @Override
public void preprocessOpenAPI(OpenAPI openAPI) { public void preprocessOpenAPI(OpenAPI openAPI) {
String calloutLabel = openAPI.getInfo().getTitle(); String calloutLabel = getInfoTitle();
if (StringUtils.isNotBlank(namedCredential)) { if (StringUtils.isNotBlank(namedCredential)) {
calloutLabel = namedCredential; calloutLabel = namedCredential;
} }

View File

@ -550,7 +550,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
@Override @Override
public void preprocessOpenAPI(OpenAPI openAPI) { public void preprocessOpenAPI(OpenAPI openAPI) {
String baseTitle = openAPI.getInfo().getTitle(); String baseTitle = getInfoTitle();
if (StringUtils.isBlank(baseTitle)) { if (StringUtils.isBlank(baseTitle)) {
baseTitle = "OpenAPI"; baseTitle = "OpenAPI";

View File

@ -275,7 +275,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
@Override @Override
public void preprocessOpenAPI(OpenAPI openAPI) { public void preprocessOpenAPI(OpenAPI openAPI) {
// From the title, compute a reasonable name for the package and the API // From the title, compute a reasonable name for the package and the API
String title = openAPI.getInfo().getTitle(); String title = getInfoTitle();
// Drop any API suffix // Drop any API suffix
if (title == null) { if (title == null) {

View File

@ -471,7 +471,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
if (!additionalProperties.containsKey(TITLE)) { if (!additionalProperties.containsKey(TITLE)) {
// From the title, compute a reasonable name for the package and the // From the title, compute a reasonable name for the package and the
// API // API
String title = openAPI.getInfo().getTitle(); String title = getInfoTitle();
// Drop any API suffix // Drop any API suffix
if (title != null) { if (title != null) {

View File

@ -771,7 +771,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
// This is an additional step we add when pre-processing the API spec, if // This is an additional step we add when pre-processing the API spec, if
// there is no user configuration set for the `title` of the project, // there is no user configuration set for the `title` of the project,
// we try build and normalise a title from the API spec itself. // we try build and normalise a title from the API spec itself.
String title = openAPI.getInfo().getTitle(); String title = getInfoTitle();
// Drop any API suffix // Drop any API suffix
if (title != null) { if (title != null) {

View File

@ -689,7 +689,7 @@ public class SpringCodegen extends AbstractJavaCodegen
if (!additionalProperties.containsKey(TITLE)) { if (!additionalProperties.containsKey(TITLE)) {
// From the title, compute a reasonable name for the package and the API // From the title, compute a reasonable name for the package and the API
String title = openAPI.getInfo().getTitle(); String title = getInfoTitle();
// Drop any API suffix // Drop any API suffix
if (title != null) { if (title != null) {

View File

@ -230,7 +230,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
Markdown markInstance = new Markdown(); Markdown markInstance = new Markdown();
openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription)); openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription));
} else { } else {
LOGGER.error("OpenAPI object description is empty [{}]", openAPI.getInfo().getTitle()); LOGGER.error("OpenAPI object description is empty [{}]", getInfoTitle());
} }
} }