|
| 1 | +/* |
| 2 | + * |
| 3 | + * * |
| 4 | + * * * |
| 5 | + * * * * Copyright 2019-2022 the original author or authors. |
| 6 | + * * * * |
| 7 | + * * * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * * * * you may not use this file except in compliance with the License. |
| 9 | + * * * * You may obtain a copy of the License at |
| 10 | + * * * * |
| 11 | + * * * * https://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * * * * |
| 13 | + * * * * Unless required by applicable law or agreed to in writing, software |
| 14 | + * * * * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * * * * See the License for the specific language governing permissions and |
| 17 | + * * * * limitations under the License. |
| 18 | + * * * |
| 19 | + * * |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +package org.springdoc.core.configuration; |
| 24 | + |
| 25 | +import com.fasterxml.jackson.databind.introspect.AnnotatedMember; |
| 26 | +import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector; |
| 27 | +import com.fasterxml.jackson.databind.module.SimpleModule; |
| 28 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 29 | + |
| 30 | +/** |
| 31 | + * The type Spring doc required module. |
| 32 | + * |
| 33 | + * @author bnasslahsen |
| 34 | + */ |
| 35 | +public class SpringDocRequiredModule extends SimpleModule { |
| 36 | + |
| 37 | + @Override |
| 38 | + public void setupModule(SetupContext context) { |
| 39 | + context.insertAnnotationIntrospector(new RespectSchemaRequiredAnnotationIntrospector()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * The type Respect schema required annotation introspector. |
| 44 | + */ |
| 45 | + private static class RespectSchemaRequiredAnnotationIntrospector extends NopAnnotationIntrospector { |
| 46 | + @Override |
| 47 | + public Boolean hasRequiredMarker(AnnotatedMember m) { |
| 48 | + Schema schemaAnnotation = m.getAnnotation(Schema.class); |
| 49 | + return schemaAnnotation != null ? schemaAnnotation.required() : null; |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments