Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [JAVA] [JavaScript] Getting started example code with parameter examples produces invalid syntax #6324

Closed
5 of 6 tasks
boting opened this issue May 15, 2020 · 1 comment

Comments

@boting
Copy link

boting commented May 15, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Running the generator against a sample OpenApi 3.0 spec produces invalid example code in the getting started guide. I've tried this using both the Java and JavaScript generators and the same issue exists.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io
  - url: http://petstore-sandbox.swagger.io
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: x-api-key
          in: header
          description: API Key
          schema:
            type: string
            example: 5bb608a0-7711-4f0e-8b51-00cfa968e042
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Command line used for generation

java -jar openapi-generator-cli.jar generate
--generator-name java
--output java
--library google-api-client
--input-spec ./petstore.yaml
--group-id io.swagger.petstore.client
--artifact-id io.swagger.petstore.client
--api-package io.swagger.petstore.client.api
--model-package io.swagger.petstore.client.model
--invoker-package io.swagger.petstore.client

Steps to reproduce
  1. Run the code generator using command line above
  2. Open the README.md in the generated java directory
  3. Look for LOC that looks like this:
String xApiKey = 5bb608a0-7711-4f0e-8b51-00cfa968e042; // String | API Key
  1. Was expecting the value to be in quotes because the example parameter is a string type.
Related issues/PRs
Suggest a fix

It seems like the Mustache templates aren't considering the dataType of the parameter before rendering its value. Perhaps something that could be solved by adding some additional flags and inverted sections into the Mustache template or maybe using a lambda?

@valpackett
Copy link
Contributor

valpackett commented Apr 10, 2024

Just hit this. Looks like this was fixed for Python specifically in #2669. Seems also fixed in AbstractJavaCodegen at least in the master branch.

I wonder why the base class doesn't work like those generators expect… would there be any unwanted side effects if it did? (EDIT: apparently yes…)

valpackett added a commit to valpackett/openapi-generator that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants