Skip to content
Merged
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
4 changes: 3 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@

<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="FileLength"/>
<module name="FileLength">
<property name="max" value="3000"/>
</module>

<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
projectVersion=4.4.4-SNAPSHOT
projectVersion=4.5.0-SNAPSHOT
projectGroup=io.micronaut.openapi

micronautDocsVersion=2.0.0
micronautVersion=3.5.3
micronautTestVersion=3.4.0
groovyVersion=3.0.11
micronautVersion=3.6.1
micronautTestVersion=3.5.0
groovyVersion=3.0.12
spockVersion=2.1-groovy-3.0

title=OpenAPI/Swagger Support
projectDesc=Configuration to integrate Micronaut and OpenAPI/Swagger
projectUrl=https://micronaut.io
githubSlug=micronaut-projects/micronaut-openapi
developers=Puneet Behl,Álvaro Sánchez-Mariscal,Iván López
developers=Puneet Behl,Álvaro Sánchez-Mariscal,Iván López

githubCoreBranch=3.6.x

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,26 @@ private void processParameterAnnotationInMethod(MethodElement element,
paramAnn.stringValue("name").ifPresent(parameter::name);
paramAnn.enumValue("in", ParameterIn.class).ifPresent(in -> parameter.in(in.toString()));
paramAnn.stringValue("description").ifPresent(parameter::description);
paramAnn.booleanValue("required").ifPresent(parameter::required);
paramAnn.booleanValue("deprecated").ifPresent(parameter::deprecated);
paramAnn.booleanValue("allowEmptyValue").ifPresent(parameter::allowEmptyValue);
paramAnn.booleanValue("allowReserved").ifPresent(parameter::allowReserved);
paramAnn.booleanValue("required").ifPresent(value -> {
if (value) {
parameter.setRequired(true);
}
});
paramAnn.booleanValue("deprecated").ifPresent(value -> {
if (value) {
parameter.setDeprecated(true);
}
});
paramAnn.booleanValue("allowEmptyValue").ifPresent(value -> {
if (value) {
parameter.setAllowEmptyValue(true);
}
});
paramAnn.booleanValue("allowReserved").ifPresent(value -> {
if (value) {
parameter.setAllowReserved(true);
}
});
paramAnn.stringValue("example").ifPresent(parameter::example);
paramAnn.stringValue("ref").ifPresent(parameter::$ref);
paramAnn.enumValue("style", ParameterStyle.class).ifPresent(style -> parameter.setStyle(paramStyle(style)));
Expand Down Expand Up @@ -585,8 +601,8 @@ private void processParameter(VisitorContext context, OpenAPI openAPI,
newParameter.setName(parameter.getName());
}

if (newParameter.getRequired() == null) {
newParameter.setRequired(!parameter.isNullable() && !parameter.getType().isOptional());
if (newParameter.getRequired() == null && !parameter.isNullable() && !parameter.getType().isOptional()) {
newParameter.setRequired(true);
}
if (javadocDescription != null && StringUtils.isEmpty(newParameter.getDescription())) {
CharSequence desc = javadocDescription.getParameters().get(parameter.getName());
Expand All @@ -598,7 +614,7 @@ private void processParameter(VisitorContext context, OpenAPI openAPI,

Schema schema = newParameter.getSchema();
if (schema == null) {
schema = resolveSchema(openAPI, parameter, parameterType, context, consumesMediaTypes, null);
schema = resolveSchema(openAPI, parameter, parameterType, context, consumesMediaTypes, null, null);
}

if (schema != null) {
Expand All @@ -610,14 +626,11 @@ private void processParameter(VisitorContext context, OpenAPI openAPI,
private void processBodyParameter(VisitorContext context, OpenAPI openAPI, JavadocDescription javadocDescription,
MediaType mediaType, Schema schema, TypedElement parameter) {
Schema propertySchema = resolveSchema(openAPI, parameter, parameter.getType(), context,
Collections.singletonList(mediaType), null);
Collections.singletonList(mediaType), null, null);
if (propertySchema != null) {

Optional<String> description = parameter.getValue(io.swagger.v3.oas.annotations.Parameter.class,
"description", String.class);
if (description.isPresent()) {
propertySchema.setDescription(description.get());
}
Optional<String> description = parameter.getValue(io.swagger.v3.oas.annotations.Parameter.class, "description", String.class);
description.ifPresent(propertySchema::setDescription);
processSchemaProperty(context, parameter, parameter.getType(), null, schema, propertySchema);
if (parameter.isNullable() || parameter.getType().isOptional()) {
// Keep null if not
Expand Down Expand Up @@ -820,7 +833,7 @@ private void processBody(VisitorContext context, OpenAPI openAPI,
if (existedMediaType.getExamples() == null) {
existedMediaType.setExamples(mediaType.getExamples());
}
if (existedMediaType.getExample() == null) {
if (existedMediaType.getExample() == null && mediaType.getExampleSetFlag()) {
existedMediaType.setExample(mediaType.getExample());
}
}
Expand Down Expand Up @@ -980,10 +993,18 @@ private io.swagger.v3.oas.models.Operation readOperation(MethodElement element,
}
swaggerParam.setName(paramAnn.name());
swaggerParam.setDescription(paramAnn.description());
swaggerParam.setRequired(paramAnn.required());
swaggerParam.setDeprecated(paramAnn.deprecated());
swaggerParam.setAllowEmptyValue(paramAnn.allowEmptyValue());
swaggerParam.setAllowReserved(paramAnn.allowReserved());
if (paramAnn.required()) {
swaggerParam.setRequired(true);
}
if (paramAnn.deprecated()) {
swaggerParam.setDeprecated(true);
}
if (paramAnn.allowEmptyValue()) {
swaggerParam.setAllowEmptyValue(true);
}
if (paramAnn.allowReserved()) {
swaggerParam.setAllowReserved(true);
}
swaggerParam.setExample(paramAnn.example());
swaggerParam.setStyle(paramStyle(paramAnn.style()));
swaggerParam.$ref(paramAnn.ref());
Expand Down Expand Up @@ -1321,7 +1342,8 @@ private void addTagIfNotPresent(String tag, io.swagger.v3.oas.models.Operation s
private void readTags(MethodElement element, VisitorContext context, io.swagger.v3.oas.models.Operation swaggerOperation, List<io.swagger.v3.oas.models.tags.Tag> classTags, OpenAPI openAPI) {
element.getAnnotationValuesByType(Tag.class).forEach(av -> av.get("name", String.class).ifPresent(swaggerOperation::addTagsItem));

List<io.swagger.v3.oas.models.tags.Tag> operationTags = processOpenApiAnnotation(element, context, Tag.class, io.swagger.v3.oas.models.tags.Tag.class, openAPI.getTags());
List<io.swagger.v3.oas.models.tags.Tag> copyTags = openAPI.getTags() != null ? new ArrayList<>(openAPI.getTags()) : null;
List<io.swagger.v3.oas.models.tags.Tag> operationTags = processOpenApiAnnotation(element, context, Tag.class, io.swagger.v3.oas.models.tags.Tag.class, copyTags);
// find not simple tags (tags with description or other information), such fields need to be described at the openAPI level.
List<io.swagger.v3.oas.models.tags.Tag> complexTags = null;
if (CollectionUtils.isNotEmpty(operationTags)) {
Expand All @@ -1338,17 +1360,17 @@ private void readTags(MethodElement element, VisitorContext context, io.swagger.
if (CollectionUtils.isEmpty(openAPI.getTags())) {
openAPI.setTags(complexTags);
} else {
for (io.swagger.v3.oas.models.tags.Tag operationTag : complexTags) {
for (io.swagger.v3.oas.models.tags.Tag complexTag : complexTags) {
// skip all existed tags
boolean alreadyExists = false;
for (io.swagger.v3.oas.models.tags.Tag apiTag : openAPI.getTags()) {
if (apiTag.getName().equals(operationTag.getName())) {
if (apiTag.getName().equals(complexTag.getName())) {
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
openAPI.getTags().add(operationTag);
openAPI.getTags().add(complexTag);
}
}
}
Expand All @@ -1367,14 +1389,16 @@ private List<io.swagger.v3.oas.models.tags.Tag> readTags(ClassElement element, V
final List<io.swagger.v3.oas.models.tags.Tag> readTags(List<AnnotationValue<Tag>> annotations, VisitorContext context) {
return annotations.stream()
.map(av -> toValue(av.getValues(), context, io.swagger.v3.oas.models.tags.Tag.class))
.filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
}

private Content buildContent(Element definingElement, ClassElement type, List<MediaType> mediaTypes, OpenAPI openAPI, VisitorContext context) {
Content content = new Content();
mediaTypes.forEach(mediaType -> {
io.swagger.v3.oas.models.media.MediaType mt = new io.swagger.v3.oas.models.media.MediaType();
mt.setSchema(resolveSchema(openAPI, definingElement, type, context, Collections.singletonList(mediaType), null));
mt.setSchema(resolveSchema(openAPI, definingElement, type, context, Collections.singletonList(mediaType), null, null));
content.addMediaType(mediaType.toString(), mt);
});
return content;
Expand Down
Loading