Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add generate openapi logic #14797

Open
wants to merge 3 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1362,4 +1362,62 @@ public static List<String> tokenizeToList(String str, char... separators) {
}
return tokens;
}

public static String trimToNull(String substring) {
if (substring == null) {
return null;
}
String trimmed = substring.trim();
return trimmed.isEmpty() ? null : trimmed;
}

public static boolean contains(CharSequence seq, CharSequence searchSeq) {
return (seq != null && searchSeq != null) && indexOf(seq, searchSeq, 0) >= 0;
}

private static int indexOf(CharSequence cs, CharSequence searchChar, int start) {
String searchString = searchChar.toString(); // 将 searchChar 转为 String

if (cs instanceof String) {
return ((String) cs).indexOf(searchString, start);
} else if (cs instanceof StringBuilder) {
return ((StringBuilder) cs).indexOf(searchString, start);
} else if (cs instanceof StringBuffer) {
return ((StringBuffer) cs).indexOf(searchString, start);
} else {
return cs.toString().indexOf(searchString, start);
}
}

public static boolean containsAny(CharSequence cs, CharSequence... searchCharSequences) {
return containsAny(StringUtils::contains, cs, searchCharSequences);
}

private static boolean containsAny(
ToBooleanBiFunction<CharSequence, CharSequence> test,
CharSequence cs,
CharSequence... searchCharSequences) {

if (!isEmpty(cs) && searchCharSequences != null && searchCharSequences.length > 0) {
for (CharSequence searchCharSequence : searchCharSequences) {
if (test.applyAsBoolean(cs, searchCharSequence)) {
return true;
}
}
}
return false;
}

private static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
}

public static String defaultIfEmpty(String str, String defaultStr) {
return isEmpty(str) ? defaultStr : str;
}

@FunctionalInterface
private interface ToBooleanBiFunction<T, U> {
boolean applyAsBoolean(T t, U u);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.metadata.swagger.model.OpenAPI;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -226,4 +227,6 @@ static boolean isMetadataService(String interfaceName) {
* @since 3.0
*/
String getAndListenInstanceMetadata(String consumerId, InstanceMetadataChangedListener listener);

OpenAPI getOpenAPI();
}
Loading
Loading