All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hltech.pact.gen.domain.client.model.ResponseRepresentation Maven / Gradle / Ivy

The newest version!
package com.hltech.pact.gen.domain.client.model;

import com.hltech.pact.gen.domain.client.util.RawHeadersParser;
import com.hltech.pact.gen.domain.client.util.TypeExtractor;
import lombok.Builder;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.lang.reflect.Method;
import java.util.List;

@Data
@Builder
public class ResponseRepresentation {

    private final HttpStatus status;
    private final List headers;
    private final Body body;
    private final String description;
    private final boolean emptyBodyExpected;

    public static ResponseRepresentation getDefaultForMethod(Method method, String[] responseHeaders) {
        return ResponseRepresentation.from(
            HttpStatus.OK,
            RawHeadersParser.parseAll(responseHeaders),
            method,
            "",
            false);
    }

    public static ResponseRepresentation from(HttpStatus status,
                                                          List headers,
                                                          Method method,
                                                          String description,
                                                          boolean isEmptyBodyExpected) {

        return ResponseRepresentation.builder()
            .status(status)
            .headers(headers)
            .body(Body.builder()
                .type(method.getReturnType())
                .genericArgumentTypes(
                    TypeExtractor.extractParameterTypesFromType(method.getGenericReturnType()))
                .build())
            .description(description)
            .emptyBodyExpected(isEmptyBodyExpected)
            .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy