openApiGenerate treating .yaml as .json
Answered
My openapi.yaml is:
openapi: "3.0.3"
info:
title: Miit API
version: "1.0"
servers:
- url: https://staging1.miit.co:8443/apiv2
description: staging (test) server
paths:
/profile:
get:
description: The requested user's profile, if it exist
parameters:
- name: id
in: query
description: user id.
required: true
schema:
type: integer
format: int32
minimum: 1
responses:
'200':
description: profile body
content:
application/json:
schema:
$ref: 'schemae/profileGet.yaml'
'404':
description: No such profile OR access denied
content:
application/json:
schema:
type: object
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
security:
- basicAuth: []
and my schemae/profileGet.yaml starts:
type: object
properties:
username:
type: string
description:
type: string
but when I run ./gradlew openApiGenerate it fails with:
> Task :openApiGenerate
failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'type': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"type: object
properties:
[...]
What could possibly be causing the generator to treat profileGet.yaml as JSON ???
Please sign in to leave a comment.
Could you please check if you maybe have spaces (blank characters) in the project path or
.yaml
file path?You can see the `.yaml` file path – no spaces there – `$ref: 'schemae/profileGet.yaml'`
There are no spaces in the project path.
Thank you for the information.
It usually happens when there is an error in the execution, it is assumed that the file is not YAML, so it tries with JSON parser which then fails. Is the issue happening only when it is run from the IDE or it also happens when running the command from the command line (outside of IDE)? Could you please share your IDE logs for further investigation (Help > Collect Logs and Diagnostic Data)? You can upload the zip file here: https://uploads.jetbrains.com, just provide the uploaded file ID. Thanks!
I uploaded the project. It's not open source so it's for this support question only.
Upload id: 2024_03_29_jSTtH77iCK2AbPuZuN8W1w (file: Miit2.tar.gz)
./gradlew openApiGenerate
Hello,
Have you tried to run generation using “play” button on editor gutter? It seems to run fine.
That confirms that the fault is in the Gradle plug-in. What now?
I suppose it should be reported to plugin author: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc
Fat chance. A search in the issues on is:issue is:open json yaml gives over 1000 results.
I think the only option realistically is to merge the separate specification files into one.