Skip to content

failling test case 199 for issue 1962 #1975

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

Merged
merged 1 commit into from
Dec 5, 2022
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: 4 additions & 0 deletions springdoc-openapi-webmvc-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<parent>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package test.org.springdoc.api.v30.app199;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;

@ControllerAdvice
public class CustomExceptionHandler {

static public class MyInternalException extends Exception {}

@ResponseStatus( value = INTERNAL_SERVER_ERROR )
@ExceptionHandler( MyInternalException.class )
@ResponseBody
public ErrorDto handleMyInternalException( final MyInternalException ex ) {
return new ErrorDto( ex.getMessage() );
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test.org.springdoc.api.v30.app199;

public class ErrorDto {
private String message;

public ErrorDto( final String message ) {
this.message = message;
}

public String getMessage() { return message; }
public void setMessage( final String message ) { this.message = message; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
*
* *
* * *
* * * * Copyright 2019-2022 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.app199;


import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.examples.Example;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;

import java.util.LinkedHashMap;
import java.util.Map;

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

@RestController
public class HelloController {

@Autowired
ObjectMapper defaultObjectMapper;

@GetMapping(
value = "/first",
produces = APPLICATION_JSON_VALUE
)
public void first() {}

@GetMapping(
value = "/second",
produces = APPLICATION_JSON_VALUE
)
public void second() {}

@Bean
public OperationCustomizer operationCustomizer()
{
return ( Operation operation, HandlerMethod handlerMethod ) ->
{
final io.swagger.v3.oas.models.media.MediaType mediaType = operation
.getResponses()
.get( "500" )
.getContent()
.get( ALL_VALUE );

mediaType.setExamples( mediaType.getExamples() != null
? mediaType.getExamples()
: new LinkedHashMap<>() );

final Map<String, Example> examples = mediaType.getExamples();

switch ( handlerMethod.getMethod().getName() ) {

case "first" :
examples.put(
"First case example",
new Example().value(
defaultObjectMapper.valueToTree(
new ErrorDto( "An ErrorDto sample specific to /first endpoint" )
)
)
);
break;

case "second" :
examples.put(
"Second case example",
new Example().value(
defaultObjectMapper.valueToTree(
new ErrorDto( "An ErrorDto sample specific to /second endpoint" )
)
)
);
break;
}

return operation;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* *
* * *
* * * * Copyright 2019-2022 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.app199;

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

public class SpringDocApp199Test extends AbstractSpringDocV30Test {

@SpringBootApplication
static class SpringDocTestApp {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost","description":"Generated server url"}],"paths":{"/second":{"get":{"tags":["hello-controller"],"operationId":"second","responses":{"500":{"description":"Internal Server Error","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ErrorDto"},"examples":{"Second case example":{"value":{"message":"An ErrorDto sample specific to /second endpoint"}}}}}},"200":{"description":"OK"}}}},"/first":{"get":{"tags":["hello-controller"],"operationId":"first","responses":{"500":{"description":"Internal Server Error","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ErrorDto"},"examples":{"First case example":{"value":{"message":"An ErrorDto sample specific to /first endpoint"}}}}}},"200":{"description":"OK"}}}}},"components":{"schemas":{"ErrorDto":{"type":"object","properties":{"message":{"type":"string"}}}}}}