Skip to content

[SCB-1225][WIP][WEAK] swagger generator core not depend on dynamic class#1157

Merged
liubao68 merged 14 commits intoapache:weak-contract-typefrom
wujimin:weak-swagger-generator-core-not-depend-on-dynamic-class
Apr 10, 2019
Merged

[SCB-1225][WIP][WEAK] swagger generator core not depend on dynamic class#1157
liubao68 merged 14 commits intoapache:weak-contract-typefrom
wujimin:weak-swagger-generator-core-not-depend-on-dynamic-class

Conversation

@wujimin
Copy link
Contributor

@wujimin wujimin commented Mar 29, 2019

rewrite generate mechanism, make extend simpler
Swagger swagger = SwaggerGenerator.generate(cls)

@wujimin wujimin force-pushed the weak-swagger-generator-core-not-depend-on-dynamic-class branch from af3d78c to d8cfa56 Compare March 30, 2019 07:42
}

public static boolean isComplexProperty(Property property) {
if (RefProperty.class.isInstance(property) || ObjectProperty.class.isInstance(property)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instanceof is better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}

public static void setCommaConsumes(Swagger swagger, String commaConsumes) {
if (org.apache.commons.lang3.StringUtils.isEmpty(commaConsumes)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove org.apache.commons, already import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public static void setProduces(Operation operation, String... produces) {
// same to consumes
List<String> produceList = convertConsumes(produces);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why produces use method name convertConsumes, maybe the method name can be changed more appropriately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to covertConsumesOrProduces

return false;
}

if (cls == String.class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can simply

    return cls != String.class
            && cls != Date.class
            && cls != LocalDate.class
            && cls != byte[].class
            && !Part.class.isAssignableFrom(cls);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less code, but logic is more complex.

return property;
}

private boolean isEnum(List<String> enums) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced with CollectionUtils.isEmpty(enums);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depend on spring
or use org.apache.commons.collections4.CollectionUtils, still need new dependency

just a judgment, no need to change.

Annotation annotation) {
if (StringUtils.isEmpty(name)) {
throw new IllegalStateException(
String.format("%s.name should not be empty. method=", annotation.annotationType().getSimpleName(), method));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe lose one %s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Type type = processor.getGenericType(annotation);
if (type != null) {
genericType = type;
Copy link
Contributor

@heyile heyile Mar 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not break when type != null, want the later covers the former?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, always override.

@wujimin wujimin force-pushed the weak-swagger-generator-core-not-depend-on-dynamic-class branch from 7a0bb6f to 9327b93 Compare April 4, 2019 16:13
@Documented
public @interface RawJsonRequestBody {
@AliasFor("name")
// aliasFor "name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it introduce some backward compatibility issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will not, because we read both of the two field

import io.swagger.models.parameters.Parameter;

public class ParameterGenerator {
public String parameterName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use private as usually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to private.
done

@wujimin wujimin force-pushed the weak-swagger-generator-core-not-depend-on-dynamic-class branch from 9327b93 to 8e9a746 Compare April 8, 2019 01:47
@liubao68
Copy link
Contributor

liubao68 commented Apr 9, 2019

What's the status of this PR? I see some compile errors and imcomplete code.

@wujimin
Copy link
Contributor Author

wujimin commented Apr 10, 2019

What's the status of this PR? I see some compile errors and imcomplete code.

all PR about "[WEAK]" is a new branch
will can not compile for a long time, because core mechanism changed, need modify one by one.

@liubao68 liubao68 merged commit af7cecf into apache:weak-contract-type Apr 10, 2019
@wujimin wujimin deleted the weak-swagger-generator-core-not-depend-on-dynamic-class branch April 16, 2019 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants