Search in sources :

Example 61 with Header

use of io.swagger.v3.oas.models.headers.Header in project swagger-core by swagger-api.

the class AnnotationsUtils method getHeader.

public static Optional<Header> getHeader(io.swagger.v3.oas.annotations.headers.Header header, JsonView jsonViewAnnotation) {
    if (header == null) {
        return Optional.empty();
    }
    Header headerObject = new Header();
    boolean isEmpty = !StringUtils.isNotBlank(header.name());
    if (StringUtils.isNotBlank(header.description())) {
        headerObject.setDescription(header.description());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(header.ref())) {
        headerObject.set$ref(header.ref());
        isEmpty = false;
    }
    if (header.deprecated()) {
        headerObject.setDeprecated(header.deprecated());
    }
    if (header.required()) {
        headerObject.setRequired(header.required());
        isEmpty = false;
    }
    headerObject.setStyle(Header.StyleEnum.SIMPLE);
    if (header.schema() != null) {
        if (header.schema().implementation().equals(Void.class)) {
            AnnotationsUtils.getSchemaFromAnnotation(header.schema(), jsonViewAnnotation).ifPresent(headerObject::setSchema);
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    return Optional.of(headerObject);
}
Also used : Header(io.swagger.v3.oas.models.headers.Header)

Example 62 with Header

use of io.swagger.v3.oas.models.headers.Header in project swagger-core by swagger-api.

the class SpecFilter method addPathItemSchemaRef.

private void addPathItemSchemaRef(PathItem pathItem, Set<String> referencedDefinitions) {
    if (pathItem.getParameters() != null) {
        for (Parameter parameter : pathItem.getParameters()) {
            addSchemaRef(parameter.getSchema(), referencedDefinitions);
            addContentSchemaRef(parameter.getContent(), referencedDefinitions);
        }
    }
    Map<PathItem.HttpMethod, Operation> ops = pathItem.readOperationsMap();
    for (Operation op : ops.values()) {
        if (op.getRequestBody() != null) {
            addContentSchemaRef(op.getRequestBody().getContent(), referencedDefinitions);
        }
        if (op.getResponses() != null) {
            for (String keyResponses : op.getResponses().keySet()) {
                ApiResponse response = op.getResponses().get(keyResponses);
                if (response.getHeaders() != null) {
                    for (String keyHeaders : response.getHeaders().keySet()) {
                        Header header = response.getHeaders().get(keyHeaders);
                        addSchemaRef(header.getSchema(), referencedDefinitions);
                        addContentSchemaRef(header.getContent(), referencedDefinitions);
                    }
                }
                addContentSchemaRef(response.getContent(), referencedDefinitions);
            }
        }
        if (op.getParameters() != null) {
            for (Parameter parameter : op.getParameters()) {
                addSchemaRef(parameter.getSchema(), referencedDefinitions);
                addContentSchemaRef(parameter.getContent(), referencedDefinitions);
            }
        }
        if (op.getCallbacks() != null) {
            for (String keyCallback : op.getCallbacks().keySet()) {
                Callback callback = op.getCallbacks().get(keyCallback);
                for (PathItem callbackPathItem : callback.values()) {
                    addPathItemSchemaRef(callbackPathItem, referencedDefinitions);
                }
            }
        }
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Header(io.swagger.v3.oas.models.headers.Header) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Aggregations

Test (org.testng.annotations.Test)32 OpenAPI (io.swagger.v3.oas.models.OpenAPI)26 Header (io.swagger.v3.oas.models.headers.Header)25 Parameter (io.swagger.v3.oas.models.parameters.Parameter)16 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)13 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)11 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)11 Schema (io.swagger.v3.oas.models.media.Schema)10 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)10 MediaType (io.swagger.v3.oas.models.media.MediaType)8 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)8 Components (io.swagger.v3.oas.models.Components)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 StringSchema (io.swagger.v3.oas.models.media.StringSchema)6 AuthorizationValue (io.swagger.v3.parser.core.models.AuthorizationValue)6 PathItem (io.swagger.v3.oas.models.PathItem)5 Example (io.swagger.v3.oas.models.examples.Example)5 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)5 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)5 RefFormat (io.swagger.v3.parser.models.RefFormat)5