Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<central-publishing-maven-plugin.version>0.7.0
</central-publishing-maven-plugin.version>
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
<swagger-api.version>2.2.43</swagger-api.version>
<swagger-api.version>2.2.45</swagger-api.version>
<swagger-ui.version>5.32.0</swagger-ui.version>
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>
<jjwt.version>0.9.1</jjwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.swagger.v3.core.jackson.SwaggerAnnotationIntrospector;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.StringUtils;

import static org.springdoc.core.utils.SpringDocAnnotationsUtils.hasADefaultValue;

/**
* The type Spring doc required module.
Expand All @@ -57,7 +58,7 @@ public Boolean hasRequiredMarker(AnnotatedMember annotatedMember) {
if (schemaAnnotation.required() || requiredMode == Schema.RequiredMode.REQUIRED) {
return true;
}
else if (requiredMode == Schema.RequiredMode.NOT_REQUIRED || StringUtils.isNotEmpty(schemaAnnotation.defaultValue())) {
else if (requiredMode == Schema.RequiredMode.NOT_REQUIRED || hasADefaultValue(schemaAnnotation)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ private String getDescription(String parameterName, String originalDescription)
* @return the default value
*/
private String getDefaultValue(String parameterName, PageableDefault pageableDefault, String defaultSchemaVal) {
String defaultValue = null;
String defaultValue = defaultSchemaVal;
switch (parameterName) {
case "size":
if (pageableDefault != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public class Builder {
/**
* Provides a default value.
*/
private String defaultValue = "";
private String defaultValue = Schema.DEFAULT_SENTINEL;

/**
* Provides a discriminator property value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.lang.annotation.Annotation;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityRequirementEntry;

/**
* The type Security requirement builder.
Expand All @@ -47,6 +48,12 @@ public class Builder {
*/
private String[] scopes = {};

/**
* If multiple requirements apply at the same time, use this value instead of {@link #name} and {@link #scopes}.
* If any one of multiple security schemes is required, use multiple {@link SecurityRequirement} annotations instead.
* <p>Exactly one of this and {@link #name} must be set.</p>
*/
private SecurityRequirementEntry[] securityRequirementEntries = {};

/**
* Instantiates a new Security requirement builder.
Expand Down Expand Up @@ -85,6 +92,17 @@ public Builder scopes(String[] scopes) {
return this;
}

/**
* SecurityRequirementEntries security requirement builder.
*
* @param securityRequirementEntries the securityRequirementEntries
* @return the security requirement builder
*/
public Builder securityRequirementEntries(SecurityRequirementEntry[] securityRequirementEntries) {
this.securityRequirementEntries = securityRequirementEntries;
return this;
}

/**
* Build security requirement.
*
Expand All @@ -106,6 +124,11 @@ public String name() {
public String[] scopes() {
return scopes;
}

@Override
public SecurityRequirementEntry[] combine() {
return securityRequirementEntries;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Com
if (schema == null && parameterDoc.array() != null) {
schema = AnnotationsUtils.getSchema(parameterDoc.schema(), parameterDoc.array(), true, parameterDoc.array().schema().implementation(), components, jsonView, propertyResolverUtils.isOpenapi31()).orElse(null);
// default value not set by swagger-core for array !
if (schema != null) {
if (schema != null && SpringDocAnnotationsUtils.hasADefaultValue(parameterDoc.array().arraySchema())) {
Object defaultValue = SpringDocAnnotationsUtils.resolveDefaultValue(parameterDoc.array().arraySchema().defaultValue(), objectMapperProvider.jsonMapper());
schema.setDefault(defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.jackson.TypeNameResolver;
import io.swagger.v3.core.util.AnnotationsUtils;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Json31;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Webhook;
import io.swagger.v3.oas.annotations.Webhooks;
import io.swagger.v3.oas.annotations.security.SecuritySchemes;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.*;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
Expand All @@ -76,6 +75,7 @@
import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
import org.springdoc.core.properties.SpringDocConfigProperties;
import org.springdoc.core.providers.JavadocProvider;
import org.springdoc.core.providers.ObjectMapperProvider;
import org.springdoc.core.utils.PropertyResolverUtils;

import org.springframework.beans.BeansException;
Expand Down Expand Up @@ -247,7 +247,7 @@ public OpenAPI build(Locale locale) {
calculatedOpenAPI.setPaths(new Paths());
}
else {
calculatedOpenAPI = cloneViaJson(openAPI, OpenAPI.class, new ObjectMapper());
calculatedOpenAPI = cloneViaJson(openAPI, OpenAPI.class, ObjectMapperProvider.createJson(springDocConfigProperties));
}

if (apiDef.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ private static boolean isArray(io.swagger.v3.oas.annotations.media.Content annot
return isArray;
}

/**
* Whether the schema has defined a default value.
*
* @param schema The schema annotation
* @return Whether the schema annotation has defined a default value
*/
public static boolean hasADefaultValue(io.swagger.v3.oas.annotations.media.Schema schema) {
return schema != null && !schema.defaultValue().equals(io.swagger.v3.oas.annotations.media.Schema.DEFAULT_SENTINEL);
}

/**
* Attempt to cast the default value so that it matches the {@link Schema} type.
* If the value cannot be cast then the provided default value is returned as-is.
Expand Down Expand Up @@ -546,7 +556,7 @@ public static Optional<Map<String, Header>> getHeaders(io.swagger.v3.oas.annotat
public static void clearCache(JavadocProvider javadocProvider) {
if (javadocProvider != null)
javadocProvider.clearCache();
MODEL_CONVERTER_CONTEXT_MAP.remove();;
MODEL_CONVERTER_CONTEXT_MAP.remove();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"in": "query",
"required": false,
"schema": {
"type": "string"
"type": "string",
"nullable": true
}
},
{
Expand Down Expand Up @@ -86,7 +87,8 @@
"in": "query",
"required": false,
"schema": {
"type": "string"
"type": "string",
"nullable": true
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"in": "query",
"required": false,
"schema": {
"type": "string"
"type" : [ "string", "null" ]
}
},
{
Expand Down Expand Up @@ -86,7 +86,7 @@
"in": "query",
"required": false,
"schema": {
"type": "string"
"type" : [ "string", "null" ]
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ static class SpringDocTestApp {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info().extensions(Map.of("TEST", "HELLO")))
.extensions(Map.of("TEST", "HELLO"));
.info(new Info().extensions(Map.of("x-TEST", "HELLO")))
.extensions(Map.of("x-TEST", "HELLO"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ static class SpringDocTestApp {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info().extensions(Map.of("TEST", "HELLO")))
.extensions(Map.of("TEST", "HELLO"));
.info(new Info().extensions(Map.of("x-TEST", "HELLO")))
.extensions(Map.of("x-TEST", "HELLO"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2026 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/
package test.org.springdoc.api.v31.app245;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.info.Info;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.fasterxml.jackson.annotation.JsonView;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@OpenAPIDefinition(
info = @Info(
title = "My App",
version = "${springdoc.version}",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "x-build-time", value = "${git.build.time}")
})
}
)
)
import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
public class HelloController {

@GetMapping("/hello")
public String hello() {
return "hello";
}
@JsonView(Views.Hello.class)
@GetMapping(value = "/hello-paged", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<Page<HelloWorld>> getHelloWorldPaged(@ParameterObject Pageable pageable) {
return ResponseEntity.ok(new PageImpl<>(List.of(new HelloWorld("hello", "world")), pageable, 1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2026 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/
package test.org.springdoc.api.v31.app245;

import com.fasterxml.jackson.annotation.JsonView;

public class HelloWorld {

@JsonView(Views.Hello.class)
private String hello;

@JsonView(Views.World.class)
private String world;

public HelloWorld(String hello, String world) {
this.hello = hello;
this.world = world;
}

public String getHello() {
return hello;
}

public String getWorld() {
return world;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
package test.org.springdoc.api.v31.app245;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest(properties = {
"springdoc.version=v1",
"git.build.time=2025-07-08T12:00:00Z"
})
@AutoConfigureMockMvc
class SpringDocApp245Test {

@Autowired
private MockMvc mockMvc;

@Test
void SpringDocTestApp() throws Exception {
mockMvc.perform(get("/v3/api-docs"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.info.version", is("v1")))
.andExpect(jsonPath("$.info.x-build-time", is("2025-07-08T12:00:00Z")));
public class SpringDocApp245Test extends AbstractSpringDocV30Test {
@SpringBootApplication
static class SpringDocTestApp {
}
}

Loading
Loading