swagger-api / swagger-api/swagger-codegen

swagger codegen cli for openspec 3 - java language generation fails

Open
#8,218 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When I try to generate java stubs from a simple yml api definition I am getting the following error.

I am able to generate using other language types - but were hoping that the "java" language option will yield a set of stubs that are framework agnostic. I would like the generated stubs to be simply the model and an interface for the service.

Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'AppConfig'
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:409)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:728)
at io.swagger.codegen.cmd.Generate.run(Generate.java:331)
at java.lang.Thread.run(Unknown Source)
Caused by: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 3
v2\Java
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.escape(Unknown Source)
at java.util.regex.Pattern.atom(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.lang.String.replaceFirst(Unknown Source)
at io.swagger.codegen.DefaultGenerator.getHandlebars(DefaultGenerator.java:1014)
at io.swagger.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:744)
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:396)
... 3 more

Swagger-codegen version

swagger-codegen-cli-3.0.0-20180515.103456-67.jar

Swagger declaration file content or url
openapi: 3.0.0
servers:
# Added by API Auto Mocking Plugin
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/test/1.0.0  
info:
  description: Sample API
  version: "1.0.0"
  title: Sample API
  contact:
    email: test@email.com
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: admins
    description: Secured Admin-only calls
  - name: developers
    description: Operations available to regular developers
paths:
  /health:
    get:
      tags:
        - developers
      summary: Health endpoint
      operationId: health
      responses:
        '200':
          description: Health metrics for this endpoint
          content:
            application/json:
              schema:
                type: object                
                $ref: '#/components/schemas/HealthMetric'   
components:
  schemas:
    HealthMetric:
      type: object
      required:
        - reportGenerationEnabled
        - applicationVersion
        - configuration
        - hostname
      properties:
        reportGenerationEnabled:
          type: boolean
        applicationVersion:
          type: string
          example: "<artifact group>:<artifact name>:<artifact version>"
        hostname:
          type: string
        appConfig:
          $ref: '#/components/schemas/AppConfig'
    AppConfig:
      type: object
      required:
         - name
      properties:
        name:
          type: string
          description: A string       
Command line used for generation

java -jar swagger-codegen-cli-3.0.0-20180515.103456-67.jar generate -l java -i sample.yml -o ./dest

Steps to reproduce

Just run the command above.

Related issues/PRs
Suggest a fix/enhancement

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

Reproduce the failure with the provided sample.yml and the java -jar ... generate -l java command. Start at io.swagger.codegen.DefaultGenerator.getHandlebars and processTemplateToFile, using the stack trace in DefaultGenerator.java as the entry point. Done means Java generation completes without the PatternSyntaxException and produces the requested stubs.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.