OpenAPITools / OpenAPITools/openapi-generator

[BUG] [spring] Version 4.2.3 introduced bug in spring gen hashCode method - cannot find symbol

Open
#5,587 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

spring-boot code generator fails in 4.2.3 with Error:(80,29) java: cannot find symbol
Here is the hashcode method generated. namesuper cannot be found.
Seems to be an issue with the template used to generate the hashcode method

  @Override
  public int hashCode() {
    return Objects.hash(id, namesuper.hashCode());
  }

I think what it is supposed to generate is:

  @Override
  public int hashCode() {
    return Objects.hash(id, name) + super.hashCode();
  }
openapi-generator version

4.2.3

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: test
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths:
  /test/:
    post:
      summary: ''
      operationId: post-test
      responses:
        '200':
          description: OK
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Test'
        description: ''
components:
  schemas:
    Test:
      allOf:
        - $ref: '#/components/schemas/Parent'
      title: Test
      type: object
      properties:
        id:
          type: string
        name:
          type: string
      required:
        - id
      description: ''
    Parent:
      title: Parent
      type: object
      properties:
        foo:
          type: string
<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>4.2.3</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
				<output>${project.build.directory}/generated-sources/openapi</output>
				<generatorName>spring</generatorName>
				<generateSupportingFiles>true</generateSupportingFiles>
				<configOptions>
					<library>spring-boot</library>
					<interfaceOnly>true</interfaceOnly>
				</configOptions>
			</configuration>
		</execution>
	</executions>
</plugin>
Steps to reproduce

mvn clean compile

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 supplied OpenAPI declaration and the openapi-generator-maven-plugin configuration using mvn clean compile. Then inspect the Spring generator template responsible for the generated hashCode method; done means the generated Java code no longer references the undefined namesuper symbol and compiles successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.