Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.springframework.restdocs.headers.HeaderDescriptor
import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName
import org.springframework.restdocs.headers.RequestHeadersSnippet
import org.springframework.restdocs.headers.ResponseHeadersSnippet
import org.springframework.restdocs.hypermedia.HypermediaDocumentation
import org.springframework.restdocs.hypermedia.LinkDescriptor
import org.springframework.restdocs.hypermedia.LinkExtractor
import org.springframework.restdocs.hypermedia.LinksSnippet
import org.springframework.restdocs.operation.Operation
import org.springframework.restdocs.payload.FieldDescriptor
Expand All @@ -29,7 +29,7 @@ internal object DescriptorValidator {
validateIfDescriptorsPresent(
links,
operation
) { LinksSnippetWrapper(links) }
) { LinksSnippetWrapper(links, linkExtractor) }

validateIfDescriptorsPresent(
responseFieldsWithLinks,
Expand Down Expand Up @@ -174,7 +174,7 @@ internal object DescriptorValidator {
}
}

private class LinksSnippetWrapper(descriptors: List<LinkDescriptor>) : LinksSnippet(HypermediaDocumentation.halLinks(), descriptors),
private class LinksSnippetWrapper(descriptors: List<LinkDescriptor>, linkExtractor: LinkExtractor) : LinksSnippet(linkExtractor, descriptors),
ValidateableSnippet {
override fun validate(operation: Operation) {
this.createModel(operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.epages.restdocs.apispec

import com.epages.restdocs.apispec.SimpleType.STRING
import org.springframework.restdocs.headers.HeaderDescriptor
import org.springframework.restdocs.hypermedia.HypermediaDocumentation
import org.springframework.restdocs.hypermedia.LinkDescriptor
import org.springframework.restdocs.hypermedia.LinkExtractor
import org.springframework.restdocs.payload.FieldDescriptor
import org.springframework.restdocs.payload.JsonFieldType
import org.springframework.restdocs.payload.PayloadDocumentation
Expand All @@ -28,7 +30,8 @@ data class ResourceSnippetParameters @JvmOverloads constructor(
val requestParameters: List<ParameterDescriptorWithType> = emptyList(),
val requestHeaders: List<HeaderDescriptorWithType> = emptyList(),
val responseHeaders: List<HeaderDescriptorWithType> = emptyList(),
val tags: Set<String> = emptySet()
val tags: Set<String> = emptySet(),
val linkExtractor: LinkExtractor = HypermediaDocumentation.halLinks()
) {
val responseFieldsWithLinks by lazy { responseFields + links.map(Companion::toFieldDescriptor) }

Expand Down Expand Up @@ -190,6 +193,8 @@ class ResourceSnippetParametersBuilder : ResourceSnippetDetails() {
private set
var responseHeaders: List<HeaderDescriptorWithType> = emptyList()
private set
var linkExtractor: LinkExtractor = HypermediaDocumentation.halLinks()
private set

override fun summary(summary: String?) = apply { this.summary = summary }
override fun description(description: String?) = apply { this.description = description }
Expand Down Expand Up @@ -236,6 +241,8 @@ class ResourceSnippetParametersBuilder : ResourceSnippetDetails() {
override fun tag(tag: String) = tags(tag)
override fun tags(vararg tags: String) = apply { this.tags += tags }

fun linkExtractor(linkExtractor: LinkExtractor) = apply { this.linkExtractor = linkExtractor }

fun build() = ResourceSnippetParameters(
summary,
description,
Expand All @@ -250,6 +257,7 @@ class ResourceSnippetParametersBuilder : ResourceSnippetDetails() {
requestParameters,
requestHeaders,
responseHeaders,
tags
tags,
linkExtractor
)
}