OpenAPITools / OpenAPITools/openapi-generator

Unrecognized token openapi

Open
#9,520 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I have problem with 3.1.x but 3.0.x works fine.

swagger.yaml

openapi: 3.1.0
info:
  description: test API
  title: test
  version: 1.0
servers:
  - url: /
tags:
  - name: examples-rest
    description: API examples
paths:
  /examples:
    get:
      tags:
        - examples-rest
      responses:
        '200':
          description: examples
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/example'
components:
  schemas:
    example:
      type: object
      properties:
        reference:
          type: string
          maxLength: 18
        designation:
          type: string
          maxLength: 69

build.gradle

...
plugins {
    id 'org.springframework.boot' version '2.3.7.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'org.openapi.generator' version '5.1.1'
............
}

openApiGenerate {
    generatorName = "java"
    inputSpec = new File("$rootDir/swagger.yaml").toString()
    outputDir = new File("$buildDir/generated/openapi").toString()
    apiPackage = "com.example.controller"
    invokerPackage = "com.example"
    modelPackage = "com.example.model"
    modelNamePrefix = "Api"
    generateApiTests = false
    configOptions = [
            library            : "resttemplate",
            dateLibrary        : "java8-localdatetime",
            booleanGetterPrefix: "is",
            interfaceOnly      : "true"
    ]
}

sourceSets.main.java.srcDirs += "$buildDir/generated/openapi/src/main/java"

compileJava.dependsOn tasks.openApiGenerate

....
wrapper {
    gradleVersion = '6.4.1'
}

I have this error when I run gradlew.bat openApiGenerate

failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"openapi: 3.1.0
info:
  description: test API
  title: test
  version: 1.0
servers:
  - url: /
tags:
  - name: examples-rest
    description: API examples
paths:
  /example:
    get:
      tags:
        - example-rest
      responses:
 "[truncated 4489 chars]; line: 1, column: 8]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1851)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:717)
There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
   | Error count: 2, Warning count: 0
  Errors:
        -attribute openapi is unexpected
        -attribute paths.'/example'(get).responses.200.content is unexpected

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied swagger.yaml and the openApiGenerate Gradle task, comparing the reported OpenAPI 3.1 behavior with the working 3.0.x case. Trace where the specification is parsed and validated, then verify that the 3.1 document is accepted and generation completes without the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.