ResponseExampleExtractor

class ResponseExampleExtractor(responseBodyGenerator: ResponseBodyGenerator)

Extracts expected response examples from OpenAPI operations.

This class handles the extraction of response examples from OpenAPI specifications, using a defined selection order:

  • Response: exact status -> range (e.g. 2XX) -> default

  • Media types: JSON/JWT-like -> XML -> other (alphabetical)

  • Example selection: explicit examples are chosen by media type priority; schema-derived fallback is JSON/JWT-like only

The schema-derived fallback slot is pluggable: pass a ResponseBodyGenerator to combine the extractor's explicit-example precedence with a custom body generator.

Constructors

Link copied to clipboard
constructor(responseBodyGenerator: ResponseBodyGenerator)
constructor(schemaExampleValueGenerator: SchemaExampleValueGenerator)

Creates an extractor whose fallback bodies are derived by schemaExampleValueGenerator.

Functions

Link copied to clipboard
fun extractExpectedResponseExample(operation: Operation, openAPI: OpenAPI, statusCode: Int): Any?

Extracts expected response example from an operation for the given status code.

fun extractExpectedResponseExample(operation: Operation, openAPI: OpenAPI, statusCode: Int, exampleName: String?): Any?

Extracts expected response example from an operation for the given status code and example name.

fun extractExpectedResponseExampleWithMediaType(operation: Operation, openAPI: OpenAPI, statusCode: Int): ExtractedResponseExample

Extracts expected response example and media type from an operation for the given status code.

fun extractExpectedResponseExampleWithMediaType(operation: Operation, openAPI: OpenAPI, statusCode: Int, exampleName: String?): ExtractedResponseExample

Extracts expected response example and media type from an operation for the given status code and example name.