mrabetr
(Rafik)
August 10, 2022, 2:48pm
1
I have an OpenAPI Schema and I used to generate collections for testing or documentation from it. However, i am now getting [object Object] in request bodies, when i used to get JSON request bodies following the schema definition.
What might be causing this [object Object] instead of the correct JSON?
An example request body used to be auto-generated such as in this screenshot from the API Schema
However, I am now getting request body with [object Object] as follows
I haven’t used the generate collection action for some time so i am guessing some update to Postman may be resulting into the generation no longer working
I have tried generating a previous version of the schema where the generation worked fine to make sure this issue is not due to recent changes made to the OpenAPI schema
w4dd325
(w4dd325)
August 11, 2022, 10:02am
2
Hi @mrabetr
This might sound weird, but I think there is formatting that is being passed too.
Try stripping out these dots and replace with spaces or tabs:
And see if it sends once they are removed…
mrabetr
(Rafik)
August 11, 2022, 1:41pm
3
hi @w4dd325 , thanks for your response
However, my screenshots are showing body requests generated from the OpenAPI Schema, when generating a collection from it.
The first screenshot is the correct JSON that was auto-generated from the API Schema and it works perfectly fine when sending a POST request with that body.
The second screenshot is basically Postman app failing to auto-generate the request body.
Therefore, what used to work during the collection generation from the API Schema is no longer working. I don’t usually maintain my collections manually. i have been updating my API Schema (definition in the Postman API tab) and from it i generate the collection for testing or documentation purposes.
The fact that the auto-generation of the request bodies is failing is now causing concerns because i can no longer create new collections on the fly and use them immediately. without the request bodies generated i will then have to copy past them manually
w4dd325
(w4dd325)
August 11, 2022, 2:20pm
4
Ahh sorry my mistake, I understand now.
It’s not something I have a lot of knowledge on to be honest, I’ll have a poke around and see if i can recreate a similar scenario.
I have been experiencing this issue as well. I have a workaround and info to help track the bug down. @mrabetr @w4dd325
After testing a bunch of prior version of Postman, I can say it was introduced in either v9.26.x or v9.27.0. I was not able to download any v9.26, but 9.25.2 works as expected, and 9.27.0 displays [object Object]
for imported request/response bodies.
I’ve been downloading these by fiddling with the direct download links, eg. https://dl.pstmn.io/download/version/9.25.2/osx64 for the last version without the issue.
I’m on Mac but my colleague on windows has the same issues.
Here is some yaml that you can use as a bug repro:
openapi: 3.0.0
info:
title: bug-repro
version: '1.0'
description: API specification.
servers:
- url: 'http://localhost:5001'
paths:
'/api/{tenancy}/name':
parameters:
- schema:
type: string
name: tenancy
in: path
required: true
description: The tenancy id
put:
summary: Check name
operationId: put-api-tenancy-name
responses:
'200':
description: 'OK'
requestBody:
content:
application/vnd.company.product.name-check-v1+json:
schema:
$ref: '#/components/schemas/Name-Check'
components:
schemas:
Name-Check:
title: Name-Check
description: |
Model to check name uniqueness
type: object
properties:
name:
type: string
type:
type: integer
required:
- name
- type
mrabetr
(Rafik)
September 27, 2022, 4:53pm
6
thanks @patrick-rsk for sharing your example.
After looking into your example i noticed that in the requestBody
you’re using application/vnd.company.product.name-check-v1+json
for the content type.
This has triggered me to try with application/json
which doesn’t not result into [object Object]
, but instead it correctly generates the JSON:
{
"name": "amet in",
"type": -3872749
}
The reason that caught my attention is because i use application/vnd.api+json
in my API
@w4dd325 can you flag this bug please. basically, if the content type of the requestBody
is application/json in the OpenAPI, the collection generated from it does produce a valid JSON
object. However, if the content type is application/vnd.api+json
then this results into the [object Object]
bug
w4dd325
(w4dd325)
September 27, 2022, 4:56pm
7
I don’t work for Postman, but you can search for / open issues here:
mrabetr
(Rafik)
September 27, 2022, 7:54pm
8
sorry about that @w4dd325
thanks for sharing the link, i created a new issue:
opened 07:48PM - 27 Sep 22 UTC
### Is there an existing issue for this?
- [X] I have searched the tracker for … existing similar issues and I know that duplicates will be closed
### Describe the Issue
When generating a collection from an OpenAPI definition, if the request body is of content type application/vnd.api+json then the generated request body fails and returns [object Object]
However, if the content type application/json then the request body is created correctly
### Steps To Reproduce
the bug is reproduced using the below definition. however the issue doesn't happen if the the content type of the post request's body is application/json instead of application/vnd.api+json
```
openapi: '3.0.0'
info:
version: '2022-07'
title: 'Shopify REST Admin'
description: The Admin API lets you build apps and integrations that extend and enhance the Shopify admin.
servers:
- url: https://{mystore}.myshopify.com/admin/api/{version}
description: Production server
variables:
mystore:
description: My store's name
default: '{{mystore}}'
version:
description: API version
default: '{{version}}'
paths:
/products:
post:
summary: Create a new product
description: Create a new product
operationId: createProduct
tags:
- products
requestBody:
required: true
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/productCreate'
responses:
'201':
$ref: '#/components/responses/product'
'422':
$ref: '#/components/responses/unprocessableEntityError'
'500':
$ref: '#/components/responses/internalServerError'
components:
schemas:
id:
description: An unsigned 64-bit integer that's used as a unique identifier for the resource.
type: integer
example: 1071559583
ids:
description: A comma-separated list of product IDs.
type: string
example: 632910392,921728736
date:
description: Time at which the resource was created or updated.
type: string
format: date-time
nullable: true
example: 2022-07-31T19:20:04-04:00
product:
type: object
properties:
id:
description: An unsigned 64-bit integer that's used as a unique identifier for the product. Each id is unique across the Shopify system. No two products will have the same id, even if they're from different shops.
type: integer
example: 1071559583
title:
description: The name of the product.
type: string
example: Burton Custom Freestyle 151
body_html:
description: A description of the product. Supports HTML formatting.
type: string
nullable: true
example: <strong>Good snowboard!</strong>
vendor:
description: The name of the product's vendor.
type: string
example: Burton
product_type:
description: A categorization for the product used for filtering and searching products.
type: string
example: Snowboard
created_at:
description: The date and time (ISO 8601 format) when the product was created.
$ref: '#/components/schemas/date'
handle:
description: A unique human-friendly string for the product. Automatically generated from the product's title. Used by the Liquid templating language to refer to objects.
type: string
example: burton-custom-freestyle-151
updated_at:
description: The date and time (ISO 8601 format) when the product was last modified. A product's updated_at value can change for different reasons. For example, if an order is placed for a product that has inventory tracking set up, then the inventory adjustment is counted as an update.
$ref: '#/components/schemas/date'
published_at:
description: The date and time (ISO 8601 format) when the product was published. Can be set to null to unpublish the product from the Online Store channel.
$ref: '#/components/schemas/date'
template_suffix:
description: The suffix of the Liquid template used for the product page. If this property is specified, then the product page uses a template called "product.suffix.liquid", where "suffix" is the value of this property. If this property is "" or null, then the product page uses the default template "product.liquid".
type: string
nullable: true
default: null
status:
description: The status of the product.
type: string
enum:
- active
- archived
- draft
default: active
published_scope:
description: Whether the product is published to the Point of Sale channel.
type: string
enum:
- web
- global
default: web
tags:
description: A string of comma-separated tags that are used for filtering and search. A product can have up to 250 tags. Each tag can have up to 255 characters.
type: string
example: Barnes & Noble, Big Air, John's Fav
admin_graphql_api_id:
type: string
example: gid://shopify/Product/1071559583
productCreate:
type: object
required:
- product
properties:
product:
type: object
required:
- title
properties:
title:
description: The name of the product.
type: string
example: Burton Custom Freestyle 151
body_html:
description: A description of the product. Supports HTML formatting.
type: string
example: <strong>Good snowboard!</strong>
vendor:
description: The name of the product's vendor.
type: string
example: Burton
product_type:
description: A categorization for the product used for filtering and searching products.
type: string
example: Snowboard
published:
type: boolean
default: false
published_scope:
description: Whether the product is published to the Point of Sale channel.
type: string
enum:
- web
- global
default: web
status:
description: The status of the product.
type: string
enum:
- active
- archived
- draft
default: active
tags:
description: An array of string tags that are used for filtering and search. A product can have up to 250 tags. Each tag can have up to 255 characters.
type: array
items:
type: string
example: ["Barnes & Noble","Big Air","John's Fav"]
template_suffix:
description: The suffix of the Liquid template used for the product page. If this property is specified, then the product page uses a template called "product.suffix.liquid", where "suffix" is the value of this property. If this property is "" or null, then the product page uses the default template "product.liquid".
type: string
nullable: true
default: null
productResponse:
type: object
properties:
product:
$ref: '#/components/schemas/product'
unprocessableEntityError:
description: Unprocessable Entity (422) error object
type: object
properties:
errors:
type: object
additionalProperties: true
example:
"title": ["can't be blank"]
notFoundError:
description: Not Found (404) error object
type: object
properties:
errors:
type: string
default: Not Found
internalServerError:
description: Internal Server (500) error object
type: object
properties:
errors:
type: string
default: Internal Server Error
responses:
product:
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/productResponse'
products:
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/productsResponse'
unprocessableEntityError:
description: Unprocessable Entity (422) error
content:
application/json:
schema:
$ref: '#/components/schemas/unprocessableEntityError'
notFoundError:
description: Not Found (404) error
content:
application/json:
schema:
$ref: '#/components/schemas/notFoundError'
internalServerError:
description: Internal Server (500) error
content:
application/json:
schema:
$ref: '#/components/schemas/internalServerError'
securitySchemes:
apiKey:
type: apiKey
in: header
name: X-Shopify-Access-Token
security:
- apiKey: []
tags:
- name: products
description: Products are the individual items and services for sale in the store.
```
### Screenshots or Videos
_No response_
### Operating System
macOS
### Postman Version
9.31
### Postman Platform
Both
### Additional Context?
_No response_
1 Like