You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I have an API that has application/pdf as return type for one of the endpoints. Currently, if i generate a stub from an interaction, i have no way to load bytes in the response (using externalValue). I can only type an inline string.
This has two effects:
first i cannot correctly mock this interaction, because the calling app will need valid bytes to be sent back.
second, the mime type sent back is incorrect, Specmatic looks at the pattern from the response example to generate the response. This means if Specmatic parses the example body as a StringValue, it will set the return MimeType to text/plain, which isn't compatible with the contract.
There are multiple behaviors that adds up to create the mimetype behaviour:
Specmatic creates the example patterns from the example body, and doesn't look at the contract at all. This is why what is a "String format Binary" in the contract turns in a simple String in the example, generating the incorrect mimeType
Specmatic doesn't use the contract at all for responses MimeTypes, just the Value class of the body
Steps to reproduce
1. Here's what you need, there is a contract, an interraction & 1 pdf files:
Contract:
openapi: 3.0.3info:
contact:
url: http://balbalatitle: GigaUpload Servicedescription: Service to upload things and break Specmatic :( sorry guyzversion: 1.0.0servers:
- url: "http://{hostname}:{port}/{basePath}/"variables:
hostname:
default: localhostport:
default: "8080"basePath:
default: rest
- url: "http://localhost:9000"tags:
- name: UploadStuffpaths:
"/uploadstuff":
post:
tags:
- UploadStuffoperationId: UploadStuffToServerrequestBody:
content:
multipart/form-data:
schema:
type: objectproperties:
uploadRequest:
$ref: "#/components/schemas/UploadRequest"pdfFiles:
type: arrayitems:
type: stringformat: binaryrequired:
- uploadRequest
- pdfFilesencoding:
UploadRequest:
contentType: application/jsonpdfFiles:
contentType: application/pdfresponses:
"200":
description: "The document has been sent successfully send and...we're sending it back, because reasons. You're not my dad."content:
application/pdf:
schema:
type: stringformat: binarycomponents:
schemas:
UploadRequest:
type: objecttitle: UploadRequestproperties:
name:
type: stringminLength: 1maxLength: 255coolNameYourFriendsGiveYou:
type: stringminLength: 1maxLength: 255required:
- name
- coolNameYourFriendsGiveYou
Expected behavior
I Expect the response to be of mimetype application/pdf like it's written in the contract.
I Expect valid pdf bytes to be the body of the response
Screenshots
Response mimetype is text/plain:
System Information:
OS & version: Windows 11
Browser & version: Insomnia 2023
Specmatic version: 0.77
JDK version: OpenJDK 17
Additional context
There are multiple ways we could solve these problems:
Add support for externalValue in the responses
At the OpenAPI parsing time (in OpenAPISpecification.kt) set the mimetype to the HttpResponsePattern from the contract and drop using the body value as MimeType source
The text was updated successfully, but these errors were encountered:
This was hard to convey, let me know if something is not clear !
I will investigate the possible fixes that i talk about in the additional context. Please tell me what you think about them, how would you go about fixing this / adding this feature?
Description
I have an API that has application/pdf as return type for one of the endpoints. Currently, if i generate a stub from an interaction, i have no way to load bytes in the response (using externalValue). I can only type an inline string.
This has two effects:
There are multiple behaviors that adds up to create the mimetype behaviour:
Steps to reproduce
1. Here's what you need, there is a contract, an interraction & 1 pdf files:
Contract:
Interraction:
PdfFile:
test.pdf
Don't forget to update the file path in the interaction
2. Run specmatic in stub mode with the interaction loaded
3. Make a POST request to localhost:9000/uploadstuff of type multipart/form-data
The parts are:
Expected behavior
I Expect the response to be of mimetype application/pdf like it's written in the contract.
I Expect valid pdf bytes to be the body of the response
Screenshots
Response mimetype is text/plain:
System Information:
Additional context
There are multiple ways we could solve these problems:
The text was updated successfully, but these errors were encountered: