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

NPE occurs when outputting an OpenAPI document since 2.5.0 #2561

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* * *
* * * *
* * * * * Copyright 2019-2022 the original author or authors.
* * * * * Copyright 2019-2024 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.
Expand Down Expand Up @@ -412,7 +412,7 @@ private Optional<ApiResponses> getApiResponses(

buildResponseContent(methodAttributes, components, classProduces, methodProduces, apiResponsesOp, response, apiResponseObject);

AnnotationsUtils.getHeaders(response.headers(), null, propertyResolverUtils.isOpenapi31()).ifPresent(apiResponseObject::headers);
AnnotationsUtils.getHeaders(response.headers(), components, null, propertyResolverUtils.isOpenapi31()).ifPresent(apiResponseObject::headers);
// Make schema as string if empty
calculateHeader(apiResponseObject);
if (isResponseObject(apiResponseObject)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
*
* *
* * *
* * * * Copyright 2019-2024 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.v30.app218;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;


@RestController
@RequestMapping("/")
public class HelloController {

@Operation(
summary = "Summary",
description = "This is description.",
tags = {"Sample"},
responses = {
@ApiResponse(
responseCode = "201",
description = "201 (Created)",
headers =
@Header(
name = HttpHeaders.LOCATION,
description = "Sample endpoint",
schema = @Schema(implementation = URI.class)
)
)
}
)
@GetMapping
public String get() {
return "Hello World!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* * Copyright 2019-2024 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.v30.app218;

import org.springdoc.core.customizers.SpecPropertiesCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;

/**
* <p>
* A test for {@link SpecPropertiesCustomizer}
*/
@SpringBootTest
public class SpringDocApp218Test extends AbstractSpringDocV30Test {

@SpringBootApplication
static class SpringDocTestApp {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"paths": {
"/": {
"get": {
"tags": [
"Sample"
],
"summary": "Summary",
"description": "This is description.",
"operationId": "get",
"responses": {
"201": {
"description": "201 (Created)",
"headers": {
"Location": {
"description": "Sample endpoint",
"style": "simple",
"schema": {
"type": "string",
"format": "uri"
}
}
},
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}