Describe the bug
I need to convert an OpenAPI 3 .yaml file to .json.
Running yq r --prettyPrint -j openapi.yaml > newfile.json in CLI have worked so far!
But for the file I am currently working with, I get this error Error: json: unsupported type: map[interface {}]interface {}
version of yq: 3.3.2
operating system: Mac Catalina
Command
yq r --prettyPrint -j openapi.yaml > newfile.json
Any idea what I can do? Or what I am doing wrong?
Thanks,
Can't help you unless you provide a short snippet that demonstrates the bug
I have the same issue for example with this yaml
openapi: 3.0.1
info:
title: Alert Service
description: Momentfeed Alert Service API
termsOfService: ""
version: 1.0.2-SNAPSHOT
security: []
paths:
/alerts:
get:
summary: Get all alerts for accountIds or userIds
description: Get all alerts for accountIds or userIds
operationId: getAlertsRoute
parameters:
- name: accountIds
in: query
description: accountIds
schema:
type: string
responses:
"200":
description: Responses containing a list of alert object
content:
'*/*':
schema:
$ref: '#/components/schemas/AlertsResponse'
"400":
description: Invalid Request, e.g. invalid params
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
"500":
description: Internal Server Error
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
post:
summary: Upsert an alert
description: Upsert an alert
operationId: createAlertRoute
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AlertRequest'
responses:
"200":
description: Responses containing an alert object
content:
'*/*':
schema:
$ref: '#/components/schemas/AlertsResponse'
"400":
description: Invalid Request, e.g. invalid params
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
"500":
description: Internal Server Error
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
/alerts/{alertId}:
delete:
summary: Delete an alert
description: Delete an alert by id.
operationId: deleteAlertRoute
parameters:
- name: alertId
in: path
description: alert Id
required: true
schema:
type: string
responses:
"200":
description: Responses return true
content:
'*/*':
schema:
type: string
"400":
description: Invalid Request, e.g. invalid params
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
"500":
description: Internal Server Error
content:
'*/*':
schema:
$ref: '#/components/schemas/Message'
components:
schemas:
AlertRecord:
required:
- delivery
- id
- status
- type
type: object
properties:
id:
type: integer
format: int64
accountId:
type: string
delivery:
$ref: '#/components/schemas/DeliveryType'
recipient:
type: string
deliveryAttr:
$ref: '#/components/schemas/Json'
source:
$ref: '#/components/schemas/Json'
type:
$ref: '#/components/schemas/AlertType'
scheduledTime:
type: integer
format: int64
realtime:
type: boolean
status:
$ref: '#/components/schemas/AlertStatus'
body:
type: string
createdTime:
type: integer
format: int64
updatedTime:
type: integer
format: int64
AlertStatus:
type: object
properties:
value:
type: string
AlertType:
required:
- value
type: object
properties:
value:
type: string
AlertsResponse:
required:
- alerts
type: object
properties:
alerts:
type: array
properties:
traversableAgain:
type: boolean
empty:
type: boolean
items:
$ref: '#/components/schemas/AlertRecord'
DeliveryType:
type: object
properties:
value:
type: string
Json:
required:
- number
type: object
properties:
number:
type: boolean
boolean:
type: boolean
string:
type: boolean
object:
type: boolean
array:
type: boolean
null:
type: boolean
SeqAlertRecord:
type: array
properties:
traversableAgain:
type: boolean
empty:
type: boolean
items:
$ref: '#/components/schemas/AlertRecord'
Message:
required:
- message
type: object
properties:
message:
type: string
Function1RequestContextFutureRouteResult:
type: object
AlertRequest:
required:
- destinations
- source
- type
type: object
properties:
accountId:
type: string
type:
$ref: '#/components/schemas/AlertType'
scheduledTime:
type: object
source:
required:
- traversableAgain
type: object
properties:
traversableAgain:
type: boolean
empty:
type: boolean
additionalProperties:
type: string
destinations:
type: array
properties:
traversableAgain:
type: boolean
empty:
type: boolean
items:
$ref: '#/components/schemas/Destination'
body:
type: string
Destination:
required:
- type
type: object
properties:
type:
$ref: '#/components/schemas/DeliveryType'
recipient:
type: string
attr:
$ref: '#/components/schemas/MapStringString'
MapStringString:
required:
- traversableAgain
type: object
properties:
traversableAgain:
type: boolean
empty:
type: boolean
additionalProperties:
type: string
SeqDestination:
type: array
properties:
traversableAgain:
type: boolean
empty:
type: boolean
items:
$ref: '#/components/schemas/Destination'
Thanks - though I would have appreciated a short snippet.
Anway, the problem seems to be the null key, this gets parsed by the yaml parser as null (not the string "null") and then it fails to encode that into json.
Hitting the same error with another yaml file - and google brought me here. Here is a very small sample that demonstrates the problem:
---
meta:
data_version: 0.9
created: '2020-02-03'
info:
competition: Big Bash League
dates:
- '2020-01-25'
outcome:
winner: Brisbane Heat
by:
runs: 71
overs: 20
teams:
- Melbourne Stars
- Brisbane Heat
toss:
decision: bat
winner: Brisbane Heat
innings:
- 1st innings:
team: Brisbane Heat
deliveries:
- 0.1:
non_striker: BCJ Cutting
bowler: Dilbar Hussain
runs:
extras: 0
total: 4
batsman: 4
batsman: SD Heazlett
- 0.2:
non_striker: BCJ Cutting
bowler: Dilbar Hussain
runs:
extras: 1
total: 1
batsman: 0
extras:
wides: 1
batsman: SD Heazlett
Hope this helps. Not sure if the reason is same though.
PS: Looking carefully, and researching a bit more, looks like the reason is the non-string keys (0.1, 0.2 etc) for maps towards the end. Not the same problem I guess then. But, how is it that the validation (yq v
Cool - this helps, it looks like the same sort of problem. Should be able to fix this by forcing keys to strings before converting to JSON.
Yes - I suppose that would be an effective solution.
Another example:
openapi: 3.0.3
info:
title: test
version: test
paths:
/:
get:
responses:
200:
description: OK
Equivalent json (using https://editor.swagger.io/ to convert):
{
"openapi": "3.0.3",
"info": {
"title": "test",
"version": "test"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
yq command: yq r test.yaml -j
yq error: unsupported type: map[interface {}]interface {}
@mikefarah Is this fixed now?
Yup, checkout the latest 3.4.0 release
Get Outlook for Androidhttps://aka.ms/ghei36
From: Samik R notifications@github.com
Sent: Friday, September 18, 2020 6:45:59 PM
To: mikefarah/yq yq@noreply.github.com
Cc: Mike Farah mikefarah@gmail.com; Mention mention@noreply.github.com
Subject: Re: [mikefarah/yq] What to do when Error: json: unsupported type: map[interface {}]interface {} ? (#519)
@mikefarahhttps://github.com/mikefarah Is this fixed now?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/mikefarah/yq/issues/519#issuecomment-694741105, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIZHNKPCFYR6PBJEWTXZ5DSGMM4PANCNFSM4QFEZBNA.