Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow parametrization by the media type of contentExamples #3283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -136,16 +136,18 @@ object OpenAPIGen {
)

def contentExamples: Map[String, OpenAPI.ReferenceOr.Or[OpenAPI.Example]] =
contentExamples(genExamples = false)
contentExamples(mediaType = MediaType.application.json, genExamples = false)

def contentExamples(genExamples: Boolean): Map[String, OpenAPI.ReferenceOr.Or[OpenAPI.Example]] =
def contentExamples(
mediaType: MediaType,
genExamples: Boolean,
): Map[String, OpenAPI.ReferenceOr.Or[OpenAPI.Example]] =
content.flatMap {
case mc @ MetaCodec(HttpCodec.Content(codec, _, _), _) if codec.lookup(MediaType.application.json).isDefined =>
mc.examples(codec.lookup(MediaType.application.json).get._2.schema, genExamples)
case mc @ MetaCodec(HttpCodec.ContentStream(codec, _, _), _)
if codec.lookup(MediaType.application.json).isDefined =>
mc.examples(codec.lookup(MediaType.application.json).get._2.schema, genExamples)
case _ =>
case mc @ MetaCodec(HttpCodec.Content(codec, _, _), _) if codec.lookup(mediaType).isDefined =>
mc.examples(codec.lookup(mediaType).get._2.schema, genExamples)
case mc @ MetaCodec(HttpCodec.ContentStream(codec, _, _), _) if codec.lookup(mediaType).isDefined =>
mc.examples(codec.lookup(mediaType).get._2.schema, genExamples)
case _ =>
Map.empty[String, OpenAPI.ReferenceOr.Or[OpenAPI.Example]]
}.toMap

Expand Down Expand Up @@ -728,7 +730,7 @@ object OpenAPIGen {
val mediaTypeResponses = mediaTypes.map { case (mediaType, (schema, atomized)) =>
mediaType.fullType -> OpenAPI.MediaType(
schema = OpenAPI.ReferenceOr.Or(schema),
examples = atomized.contentExamples(genExamples),
examples = atomized.contentExamples(mediaType, genExamples),
encoding = Map.empty,
)
}
Expand Down Expand Up @@ -1117,7 +1119,7 @@ object OpenAPIGen {
val mediaTypeResponses = mediaTypes.map { case (mediaType, (schema, atomized)) =>
mediaType.fullType -> OpenAPI.MediaType(
schema = OpenAPI.ReferenceOr.Or(schema),
examples = atomized.contentExamples(genExamples),
examples = atomized.contentExamples(mediaType, genExamples),
encoding = Map.empty,
)
}
Expand Down
Loading