OpenAPITools / OpenAPITools/openapi-generator

[BUG] testLoggersAreNotPublicFinalAndNotStatic is failed when init new generator with new.sh

Open
#14,557 0 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 tried to generate new server generator by using new.sh, but generated file in src/main/java/org/openapitools/codegen/languages/TypescriptNestjsServerCodegen.java trigger this error

Screenshot 2023-01-29 at 17 10 33

testLoggersAreNotPublicFinalAndNotStatic
java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'fields that have raw type org.slf4j.Logger should not be public and should not be static and should be final, because Code generators are most often used once per program lifetime, so making them all static will cause higher memory consumption. See PR #8799' was violated (1 times):
Field <org.openapitools.codegen.languages.TypescriptNestjsServerCodegen.LOGGER> has modifier STATIC in (TypescriptNestjsServerCodegen.java:0)
	at com.tngtech.archunit.lang.ArchRule$Assertions.assertNoViolation(ArchRule.java:107)
	at com.tngtech.archunit.lang.ArchRule$Assertions.check(ArchRule.java:95)
	at com.tngtech.archunit.lang.ArchRule$Factory$SimpleArchRule.check(ArchRule.java:215)
	at org.openapitools.codegen.ArchUnitRulesTest.testLoggersAreNotPublicFinalAndNotStatic(ArchUnitRulesTest.java:19)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at java.util.ArrayList.forEach(ArrayList.java:1259)
... Removed 28 stack frames
openapi-generator version

v6.2.1

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
 ./new.sh -n typescript-nestjs -s -t
mvn clean install 
Related issues/PRs
Suggest a fix/enhancement

Fix in new.sh file

    // BEFORE
    static final Logger LOGGER = LoggerFactory.getLogger(${lang_classname}.class);

    // AFTER
    private final Logger LOGGER = LoggerFactory.getLogger(${lang_classname}.class);

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 new.sh and inspect the logger template used by ./new.sh -n typescript-nestjs -s -t. Reproduce the failure with mvn clean install, then verify the generated TypescriptNestjsServerCodegen.java satisfies ArchUnitRulesTest.testLoggersAreNotPublicFinalAndNotStatic. Done means the generation command completes without that architecture violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, shell
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.